Skip to main content
Glama

spawn_agent

Launch an AI agent in a new terminal window to execute tasks using specified models and CLI tools. Configure with repository, model selection, and task prompt for immediate deployment.

Instructions

Spawn an AI agent in a new terminal surface. Returns immediately — use wait_for to block until ready.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repoYesRepository name (e.g. 'brainlayer', 'golems')
modelYesModel name (e.g. 'sonnet', 'codex', 'opus')
cliYesCLI tool to launch
promptYesTask prompt to send after agent is ready
workspaceNoTarget workspace ref

Implementation Reference

  • The core implementation of the agent spawning logic.
    async spawnAgent(params: SpawnAgentParams): Promise<SpawnAgentResult> {
      const agentId = generateAgentId(params.model, params.repo);
    
      // Resolve parent hierarchy
      let spawnDepth = 0;
      let parentAgentId: string | null = null;
    
      if (params.parent_agent_id) {
        const parent = this.registry.get(params.parent_agent_id);
        if (!parent) {
          throw new Error(`Parent agent not found: ${params.parent_agent_id}`);
        }
        if (parent.spawn_depth >= MAX_SPAWN_DEPTH) {
          throw new Error(`Max spawn depth exceeded: ${MAX_SPAWN_DEPTH}`);
        }
        const children = this.registry.getChildren(params.parent_agent_id);
        if (children.length >= MAX_CHILDREN) {
          throw new Error(`Max children exceeded: ${MAX_CHILDREN}`);
        }
        spawnDepth = parent.spawn_depth + 1;
        parentAgentId = params.parent_agent_id;
      }
    
      // 1. Create cmux surface
  • src/server.ts:684-714 (registration)
    Registration of the 'spawn_agent' MCP tool and its invocation handler in server.ts.
    server.tool(
      "spawn_agent",
      "Spawn an AI agent in a new terminal surface. Returns immediately — use wait_for to block until ready.",
      {
        repo: z
          .string()
          .describe("Repository name (e.g. 'brainlayer', 'golems')"),
        model: z
          .string()
          .describe("Model name (e.g. 'sonnet', 'codex', 'opus')"),
        cli: z
          .enum(["claude", "codex", "gemini", "kiro", "cursor"])
          .describe("CLI tool to launch"),
        prompt: z.string().describe("Task prompt to send after agent is ready"),
        workspace: z.string().optional().describe("Target workspace ref"),
      },
      async (args) => {
        try {
          const result = await engine.spawnAgent({
            repo: args.repo,
            model: args.model,
            cli: args.cli,
            prompt: args.prompt,
            workspace: args.workspace,
          });
          return ok({ ...result });
        } catch (e) {
          return err(e);
        }
      },
    );
  • Parameter definition for the spawnAgent operation.
    export interface SpawnAgentParams {
      repo: string;
      model: string;
      cli: CliType;
      prompt: string;
      workspace?: string;
      parent_agent_id?: string;
      max_cost_per_agent?: number;
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It discloses key behavioral traits: it spawns an agent, returns immediately (non-blocking), and suggests using 'wait_for' for readiness. However, it doesn't cover aspects like error handling, resource consumption, or permissions needed, which are gaps for a tool with no annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is highly concise and front-loaded, with two sentences that directly state the purpose and a key behavioral note. Every sentence earns its place by providing essential information without waste.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is moderately complete: it covers the basic action and a critical behavioral trait (non-blocking return). However, for a tool that spawns agents, it lacks details on what the spawned agent does, potential side effects, or error conditions, leaving gaps in context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds no additional meaning beyond the schema, such as explaining interactions between parameters or usage examples. Baseline 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Spawn an AI agent') and the location ('in a new terminal surface'), which is specific. However, it doesn't explicitly differentiate from sibling tools like 'browser_surface' or 'new_split', which might also create surfaces, leaving some ambiguity about uniqueness.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage by mentioning 'Returns immediately — use wait_for to block until ready', suggesting when to use 'wait_for' as an alternative for blocking. But it lacks explicit guidance on when to choose this tool over other surface-related siblings like 'browser_surface' or 'new_split', leaving context somewhat implied.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/EtanHey/cmuxlayer'

If you have feedback or need assistance with the MCP directory API, please join our Discord server