delegate_subagent tool lets the parent agent delegate a focused sub-task to a separate ReAct loop instance with its own context window. The subagent runs, burns its own tokens, and returns only the final summary — its tool calls, intermediate reasoning, and raw outputs stay isolated in the sub-session and never pollute the parent’s context.
This is the same pattern that projects like Claude Code call “Task” subagents, and it solves a classic problem: analyses over large payloads (Prometheus /metrics, verbose logs, exhaustive repo searches) that would otherwise consume tens of thousands of tokens just feeding raw data into the main agent’s history.
When to use
| Scenario | Use delegate_subagent? |
|---|---|
Summarise a 50K-char /metrics endpoint extracting only top-3 hotspots | Yes — raw payload stays in the subagent, only the summary returns |
| Find every call site of a function across the repo | Yes — broad scan, short answer |
| Analyse 200KB of logs and identify the relevant stack trace | Yes |
| Read 1 known file and patch it | No — delegation overhead isn’t worth it for tiny tasks |
| Run 3 independent actions in parallel | No — use <agent_call> multi-agent, which actually parallelises |
| Task that needs the conversation’s accumulated context | No — the subagent does not see the parent’s history |
Syntax
The tool is exposed asdelegate_subagent in native function calling, and as the delegate subcommand of @coder in the XML form:
- Native (preferred)
- XML (/coder mode)
Parameters
| Field | Type | Required | Description |
|---|---|---|---|
description | string | No | Short label shown in logs (e.g. "analyze metrics"). |
prompt | string | Yes | Full instructions for the subagent. Be explicit about the output format you expect — the subagent has no access to the parent’s history. |
tools | array of strings | No | Allowlist of engine subcommands the subagent may use. Default: read-only set (read, search, tree, git-*). |
read_only | boolean | No | If true (default), blocks write, patch, exec. Set false to grant the full toolset. |
max_turns | integer | No | Cap on the subagent’s internal ReAct iterations. Default: 15. |
What the parent receives
The output returned to the main agent is the subagent’s final string, prefixed with a header carrying telemetry metadata:Limits and protections
| Limit | Default | Override env var |
|---|---|---|
| Max nested delegation depth | 2 | CHATCLI_AGENT_SUBAGENT_MAX_DEPTH |
| ReAct iterations per subagent | 15 | CHATCLI_AGENT_SUBAGENT_MAX_TURNS |
| Max output size returned to parent | ~30 KB | MaxWorkerOutputBytes (internal const) |
delegate_subagent increments.
Tools allowlist
By default the subagent receives a safe read-only set:read_only: false and list which ones:
read_only: true + tools: [...] containing a write tool results in a runtime block — read_only takes precedence.
Differences from other delegation forms
| Aspect | delegate_subagent | <agent_call> | Inline tool call |
|---|---|---|---|
| Context | Own window, isolated from parent | Own window, isolated from parent | Same as parent |
| Parallelism | Sequential (one at a time) | Parallel (multiple tags in a single response) | Parallel via batch |
| Agent selection | Generic ReAct loop | Catalog of specialised agents | N/A |
| Per-model routing | No — uses parent’s client | Yes — per-agent Model hint | No |
| Best for | Focused analyses producing a summary | Parallel tasks with different types of expertise | Cheap, trivial operations |
Full example — metrics analysis
Scenario: the user asks for a memory-spike diagnosis. Withoutdelegate_subagent, the agent would web_fetch the /metrics, receive 50K chars in context, and burn tokens analysing the raw payload turn after turn.
With delegation:
webfetch (with the filter already applied), does a second pass if needed, and returns a ~500-char summary. The main agent hands that summary to the user without ever seeing the raw payload.
Next Steps
Multi-Agent
For parallel tasks instead of isolated delegation.
Session Workspace
The scratch dir shared between parent and subagent.
Tool Result Management
How the subagent’s output gets truncated if it’s too big.
Web Tools
@webfetch filters that pair well with delegation.