Agent Harnesses Explained
← /learn · 06

Sub-agents

A parent hands a sub-task to a child with a fresh context and gets a short report back: a smaller context for the parent, paid for in the child's tokens and in time.

Check yourself ↓ three questions and what to remember, at the end

Loading the animation…

Concept

Everything an agent reads stays in its context, and the whole context is sent again on every later turn (chapter 1). Reading four long notes to extract five sentences leaves the four notes in the conversation for the rest of the task. A sub-agent is the harness's answer: the parent calls a task tool with a short prompt; the harness starts a second loop with a fresh context (its own system prompt, the tools, the prompt, nothing else); the sub-agent does the reading; and only its final answer comes back to the parent, as that tool call's result.

The animation draws both contexts to one scale. Inline, the parent's context grows with every note it reads and peaks at 2,785 tokens. With a sub-agent, the notes fill the sub-agent's context instead (it peaks at 2,507 tokens), the report it hands back is 77 tokens, and the parent never holds more than 926 tokens: about a third of the inline peak. Over the whole run the two agents together send 11,557 tokens to the model, against 16,179 tokens inline.

The saving is not free, and here it is not even a saving in money. The sub-agent is another loop, run while the parent waits: the task takes 12.5 s instead of 9.59 s. And because the inline run re-reads its history from the prompt cache (chapter 4) at a fraction ρ\rho of the input price, while the sub-agent's fresh context has to be written to the cache first, the run with a sub-agent costs $0.0165 against $0.014 inline at Sonnet 5.5's prices. Fewer tokens, more money: the cache changes which tokens are expensive.

How much more depends on the model, which the Prices switch shows. On the earlier Sonnet 4.6 the gap is larger, $0.0354 against $0.0256, $0.00983 more rather than $0.0025: with its 1,024-token minimum the parent's short prompts in the sub-agent run are never cached, while Sonnet 5.5's 512-token minimum lets them be read from the cache. With no cache the sign flips, and the sub-agent is the cheaper run, because it sends fewer tokens: on Haiku 4.5, whose 4,096-token minimum this task never reaches, it costs $0.0143 against $0.0182 inline (chapter 10 has both runs). "A sub-agent costs more" is a statement about one cache, not about sub-agents.

What a sub-agent really buys is room. Switch the window to 3,000 tokens: inline, the parent has to summarise its own history twice to keep going; with a sub-agent, the parent's context never comes near the limit, and only the sub-agent compacts. A parent that keeps a small, clean context makes better decisions for longer; that is why the public harnesses use sub-agents for exploration and side questions, where most of what is read is thrown away.

Maths

Let NN be the tokens sent to the model over a run (every call's whole prompt). Inline, a note of RR tokens read on turn jj is re-sent on every later turn, so it costs about R (n−j)R\,(n - j) tokens over an nn-turn run. With a sub-agent, the parent instead carries the report of S≪RS \ll R tokens, and the sub-agent pays for its own loop, NchildN_{\text{child}}. The saving

ΔN=Ninline−(Nparent+Nchild)\Delta N = N_{\text{inline}} - (N_{\text{parent}} + N_{\text{child}})

is positive when the notes would have stayed in the parent's context for many turns: here 4,622 tokens, with the parent's peak context down by 1,859 tokens. The extra time is the sub-agent's loop, which runs while the parent waits, less the turns the parent no longer takes: here 2.88 s.

Money follows the price of each token, not their count. Cached tokens cost ρ\rho times fresh ones and cache writes ww times (chapter 4 derives both); a run that re-reads a long, stable history is mostly cache reads, while a new context is mostly writes. With the cache on, the sub-agent here costs $0.0025 more for the same answer at Sonnet 5.5's prices (ρ=0.05\rho = 0.05, Lmin⁡=512L_{\min} = 512) and $0.00983 more at Sonnet 4.6's (ρ=0.1\rho = 0.1, Lmin⁡=1,024L_{\min} = 1{,}024).

Code

The task tool, cut from the vendored engine (harness.ts): a second loop with its own system prompt and the parent's tools minus task, so a sub-agent cannot spawn another one here.

const child = `sub${this.spawned}`;
this.emit("handoff", parent, this.t, { direction: "spawn", child, prompt_tokens: this.tok.count(prompt) });
const tools = (this.scenario.tools as string[]).filter((n) => n !== "task");
const sub = this.policy.subagents as Obj;
const [status, answer, used] = this.loop(child, sub.system, prompt, tools, new ScriptedModel(script), sub.max_turns);

Sub-agents in the public harnesses

HarnessSub-agents (from their docs, accessed 2026-10-07)
Claude Code"Each subagent starts with a fresh, isolated context window"; it "does that work in its own context and returns only the summary"; by default a sub-agent can spawn its own, "up to three layers below the main conversation" (subagents)
Codex CLIsub-agents are on by default, and the parent receives "summaries from subagents instead of raw intermediate output" (subagents)
OpenHandsa task tool delegates to a sub-agent with its own conversation, which returns its response to the parent (task tool set)

All three draw the same line the animation draws: the child's context is its own, and only a summary crosses back. How deep the tree may grow, and whether children run in parallel, differ; chapter 9 compares the rest.

Check yourself

Commit to an answer before you reveal it: a wrong guess you can explain teaches more than a right one you skimmed. Every number in the answers comes from the same tested model as the chapter’s.

Q1With a sub-agent doing the reading, the parent's peak context is what share of the inline run's peak?
Reveal the answer

Answer: 33% (counted right within ± 5%)

The parent never holds more than 926 tokens, against 2,785 tokens inline: the notes fill the sub-agent's context, and only its short report comes back.

Two contexts, one scale →

Commit to a number, then reveal.

Q2With the cache on, at Sonnet 5.5's prices, which run is cheaper?
Reveal the answer

Answer: The inline run

Inline: $0.014 against $0.0165. The inline run re-reads its history from the cache at a fraction of the price, while the sub-agent's fresh context has to be written first. Fewer tokens, more money.

What the sub-agent costs →

Pick one, then reveal.

Q3Now on Haiku 4.5, whose cache minimum this task never reaches. Which run is cheaper?
Reveal the answer

Answer: The sub-agent run

The sub-agent run, $0.0143 against $0.0182. With no cache, cost follows the token count, and the sub-agent sends fewer tokens.

It depends on the cache →

Pick one, then reveal.