Overview
Theagent tool spawns a sub-agent to handle a complex subtask independently. Sub-agents run in their own context with their own message history, making them ideal for delegating research, parallel exploration, or multi-step work.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
task | string | Yes | The task description for the sub-agent |
context | string | No | Additional context or constraints |
How Sub-Agents Work
- The parent agent invokes the
agenttool with a task description. - A new
Agentinstance is spawned in a separate Tokio task. - The sub-agent has its own message history and runs independently.
- The sub-agent has access to all tools except the
agenttool itself (prevents recursive spawning). - Sub-agents run with
BypassPermissionsmode, so they do not prompt for permission. - When the sub-agent completes, its final response is returned to the parent agent.
Use Cases
Research tasks: Delegate a research question that requires multiple steps of investigation.Constraints
- Sub-agents cannot spawn further sub-agents (no recursive nesting).
- Sub-agents bypass all permission prompts.
- Sub-agents share the same working directory and file sandbox as the parent.
- Sub-agent results are returned as a single text response; intermediate steps are not visible to the parent.