subagents array, a task tool is automatically generated that lets the parent agent spawn child agents by name.
Basic Setup
task tool with a description listing the available subagents and their descriptions. It can call task with an agent name and a prompt, and the subagent runs to completion autonomously.
Key Behaviors
- Fresh instance per task — each
taskcall creates a new agent with no shared conversation state - No approval — subagents run autonomously without prompting for permission
- Configurable nesting — by default subagents cannot themselves have subagents (
maxSubagentDepth: 1). Set a higher depth to enable nested delegation. - Abort propagation — the parent’s abort signal is forwarded to the child
- Concurrent execution — the model can call
taskmultiple times in one response to run subagents in parallel
Nested Subagents
By default, subagents cannot delegate further. SetmaxSubagentDepth to allow nesting:
explore gets depth 1 (can use search), and search gets depth 0 (no further delegation).
Live Subagent Events
To observe what subagents are doing in real time, pass anonSubagentEvent callback:
path parameter is a string[] representing the full ancestry from outermost to innermost agent. Events from nested subagents automatically bubble up through the chain. The callback receives the same AgentEvent types as the parent’s run() generator.
Background Subagents
By default, all subagent calls are synchronous — the parent blocks until the child finishes. EnablesubagentBackground to let the parent spawn agents in the background, do other work, and collect results later. This works like JavaScript’s Promise combinators.
- The
tasktool gains an optionalbackgroundparameter. Whentrue, the agent is spawned in the background and the tool returns immediately with an agent ID. - An
agent_awaittool is registered for waiting on background agents using different strategies. agent_statusandagent_canceltools are registered for checking on and cancelling background agents.
Await Modes
Theagent_await tool supports four modes, matching JavaScript’s Promise combinators:
| Mode | Behavior |
|---|---|
all | Wait for all agents to succeed. Fails fast if any agent fails. |
allSettled | Wait for all agents to finish. Returns results and errors. |
any | Wait for the first agent to succeed. Only fails if all agents fail. |
race | Wait for the first agent to settle (succeed or fail). |
Configuration
Passtrue for sensible defaults, or an object for fine-grained control:
| Option | Default | Description |
|---|---|---|
maxConcurrent | Infinity | Maximum number of background agents running simultaneously |
timeout | — | Auto-cancel background agents after this many milliseconds |
autoCancel | true | Cancel all running background agents when agent.close() is called |
tools.status | true | Register the agent_status tool |
tools.cancel | true | Register the agent_cancel tool |
tools.await | all four modes | Which await modes to expose (true = all, false = disable, or an array) |
Lifecycle Tools
WhensubagentBackground is enabled, these tools are auto-registered alongside the task tool:
| Tool | Description |
|---|---|
agent_status | Non-blocking status check. Returns the agent’s current status (running, done, failed, cancelled) and result if available. |
agent_cancel | Cancel a running background agent via its ID. |
agent_await | Block until background agents complete, using one of the four await modes. |
Cleanup
Background agents respect the parent’s abort signal — if the parent is aborted, all background children are cancelled. WhenautoCancel is true (the default), calling agent.close() cancels any still-running background agents.