Feature flag
Sub-agents require thesub-agents feature flag, which is enabled by default in both the CLI and the facade crate.
AgentFactory has enable_subagents (default: false). Per-request builds can override via AgentBuildConfig::override_subagents.
Available tools
| Tool | Description |
|---|---|
agent_spawn | Create a sub-agent with clean context (just the prompt) |
agent_fork | Create a sub-agent that inherits the full conversation history |
agent_status | Get the status and output of a sub-agent by ID |
agent_cancel | Cancel a running sub-agent |
agent_list | List all sub-agents with their current states |
Spawn vs fork
- agent_spawn
- agent_fork
Creates a new sub-agent with a clean context. The sub-agent starts fresh with only the provided prompt — it does not inherit conversation history.Use for: Independent tasks that do not need the parent’s context.
Response:
Parameters
Parameters
Initial prompt/task for the sub-agent.
LLM provider:
anthropic, openai, gemini.Model name. Must be in the allowlist for the provider.
Tool access policy (see below).
Budget limits:
{ max_tokens, max_turns, max_tool_calls }.Override the system prompt for this sub-agent.
Keep agent alive processing comms messages after initial prompt. Requires
comms feature.Tool access policies
Bothagent_spawn and agent_fork accept a tool_access parameter:
| Policy | Description |
|---|---|
{"policy": "inherit"} | Inherit all tools from the parent (default). |
{"policy": "allow_list", "tools": ["shell", "task_list"]} | Only allow the specified tools. |
{"policy": "deny_list", "tools": ["shell"]} | Block the specified tools, allow everything else. |
tool_access value can be provided as either a JSON object or a JSON-encoded string (for LLMs that stringify nested objects).
Monitoring sub-agents
agent_status
agent_status
Query a single sub-agent by its UUID.Parameters: States:
{ "agent_id": "<UUID>" }running, completed, failed, cancelled.When is_final: true, the sub-agent is done. The output field contains the result text (or error field for failures).agent_list
agent_list
List all sub-agents with summary counts.Parameters: None (empty object).
agent_cancel
agent_cancel
Cancel a running sub-agent. Only agents in the
running state can be cancelled.Parameters: { "agent_id": "<UUID>" }Response: { "success": true, "previous_state": "running", "message": "Sub-agent cancelled successfully" }Concurrency limits
Concurrency limits:| Field | Type | Default | Description |
|---|---|---|---|
max_depth | u32 | 3 | Maximum nesting depth for sub-agents |
max_concurrent_ops | usize | 32 | Maximum concurrent operations (across all types) |
max_concurrent_agents | usize | 8 | Maximum concurrently running sub-agents |
max_children_per_agent | usize | 5 | Maximum children a single agent can spawn |
SubAgentManager enforces these limits. Attempting to spawn beyond the limits returns an error.
SubAgentConfig
SubAgentConfig
| Field | Type | Default | Description |
|---|---|---|---|
default_provider | String | "anthropic" | Default provider when not specified |
default_model | Option<String> | None | Default model (uses first in allowlist if None) |
concurrency_limits | ConcurrencyLimits | See above | Limits for this agent’s sub-agents |
allow_nested_spawn | bool | true | Whether sub-agents can spawn further sub-agents |
max_budget_per_agent | Option<u64> | None | Cap on tokens for any single sub-agent |
default_budget | Option<u64> | Some(50_000) | Default token budget when not specified |
inherit_system_prompt | bool | true | Whether spawned agents inherit the parent’s tool usage instructions |
enable_comms | bool | false | Whether to enable parent-child communication |
Budget allocation
- Spawn budget
- Fork budget policies
For
agent_spawn, the budget is resolved as:- If
budget.max_tokensis specified, use it (capped bymax_budget_per_agentif set). - Otherwise, use
default_budget(50,000 tokens by default).
Model allowlists
Sub-agents validate requested models against a per-provider allowlist. The allowlist comes from either:- Resolved policy from the global
SubAgentsConfigin the configuration file (highest precedence). - Default allowlist from
SubAgentsConfig::default()(hardcoded fallback).
agent_spawn tool definition dynamically includes the allowed models in the model parameter description, so the LLM can see which models are available.
Sub-agent execution lifecycle
Validation
The tool validates the prompt (non-empty), provider, model (against allowlist), and concurrency limits.
Session setup
agent_spawn: Creates a new session with optional system prompt + user prompt.agent_fork: Clones the parent session and appends the fork prompt.
Background execution
A tokio task runs the agent loop (
agent.run_pending() or agent.run_host_mode() for host mode).Completion
On success,
manager.complete() stores the result. On failure, manager.fail() stores the error. Both notify listeners via a watch channel.Comms integration
When thecomms feature is enabled and the parent has comms configured:
- Sub-agents get a comms context injected into their prompt explaining how to communicate with the parent.
- The sub-agent’s tools are wrapped with comms tools via
wrap_with_comms. - The sub-agent is added to the parent’s trusted peers so bidirectional communication works.
- The parent receives
commsinstructions in the spawn response explaining how to message the child. - Communication uses in-process (
CommsBootstrap::for_child_inproc) rather than network listeners.
See the comms guide for details on the inter-agent communication system.
How sub-agents get wired
Whenenable_subagents is true, the agent factory adds the five sub-agent tools (agent_spawn, agent_fork, agent_status, agent_cancel, agent_list) to the parent’s tool set. Child agents receive a copy of the parent’s tools but with sub-agent and comms tools removed to prevent recursive spawning.
Best practices
When to use sub-agents
- Parallel independent tasks (e.g., analyze multiple files simultaneously).
- Tasks requiring different model strengths (e.g., GPT for coding, Gemini for analysis).
- Long-running work you want to delegate while doing other things.
- Breaking complex problems into specialized subtasks.
When NOT to use sub-agents
- Simple tasks you can do directly.
- Tasks requiring tight coordination (use sequential steps instead).
- When you need immediate results (sub-agents add latency).
See also
- Built-in tools reference - tool parameter details
- Configuration: sub-agents - config file settings
- Architecture - how sub-agents fit into the agent loop
