You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/context-engineering.mdx
+22-12Lines changed: 22 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -201,11 +201,13 @@ The practical framing: **AGENTS.md** holds what the agent should always know —
201
201
202
202
## Sub-Agents
203
203
204
-
Sub-agents run in completely separate context windows. A sub-agent might consume 50K–150K tokens researching a codebase, but return only a 2K–5K synthesis to the orchestrator.
204
+
Sub-agents are **delegated agents** — independent instances that run in separate context windows under the direction of an orchestrator. Each sub-agent operates on its own task slice, and the orchestrator consumes only the returned synthesis rather than inheriting the full working trace.
205
205
206
-
**Context effect:** the prompt forks work into a separate window; only the returned synthesis enters the parent near the active turn. The parent pays for that synthesis, not the raw search trail, file reads, and partial interpretations. This keeps the orchestrator clean while making the return boundary intentionally lossy.
206
+
**Context effect:** the prompt forks work into separate windows; each sub-agent carries its own context lifecycle, and only its synthesis returns to the orchestrator. The parent pays for that synthesis, not the raw search trail, file reads, and partial interpretations. This isolation keeps the orchestrator clean while making the return boundary intentionally lossy.
207
207
208
-
Think of a sub-agent like a function call for agents. The prompt is the parameter: "Find all JWT authentication code and explain the current implementation." The synthesis is the return value: "JWT implementation found at src/auth/jwt.ts using Passport.js..." You pay for work in both contexts, but the parent receives the compact result instead of inheriting the whole research journey.
208
+
Sub-agents are the agentic analogue of a function call: the dispatch prompt is the parameter ("Find all JWT authentication code and explain the current implementation") and the synthesis is the return value ("JWT implementation found at src/auth/jwt.ts using Passport.js..."). You pay to process tokens in all participating contexts, but the orchestrator receives compact results instead of inheriting every delegate's full journey.
209
+
210
+
What makes sub-agents a first-class orchestration primitive — beyond context isolation — is **per-agent optimization**. With the right harness, each delegate can run on the LLM best suited to its sub-task: [pi](https://pi.dev) + [pi-agenticoding](https://github.com/agenticoding/pi-agenticoding) lets you route each sub-agent to the model that matches its cost-accuracy profile. Similarly, Claude Code, Codex, and OpenCode let you customize the system prompt per sub-agent, so each delegate carries only the instructions it needs for its slice of work. Regardless of the mechanism, the payoff is the same: **orchestrating a single task via multiple specialized agents** instead of overloading one context.
209
211
210
212
<DiagramFrame
211
213
kicker="Context management"
@@ -218,17 +220,25 @@ Think of a sub-agent like a function call for agents. The prompt is the paramete
218
220
<SubAgentFanoutDiagram />
219
221
</DiagramFrame>
220
222
221
-
The tradeoffs:
223
+
### Benefits and Costs
224
+
225
+
**Benefits:**
226
+
-**Proper delegation** — the orchestrator assigns each sub-task to an independent agent rather than doing all work in one overloaded context
227
+
-**LLM optimization per task** — pi + pi-agenticoding routes each delegate to the model best suited to its slice (e.g. high-throughput for research, precision-tuned for review)
228
+
-**System prompt customization per agent** — Claude Code, Codex, and OpenCode let you tailor the system prompt to each delegate's role
229
+
-**Parallel execution** — independent sub-tasks run concurrently instead of serially
230
+
-**Cleaner orchestrator** — only syntheses cross back, keeping the parent window focused on coordination
222
231
223
-
-**No shared state** — each sub-agent starts fresh, so you pay the context-file loading cost again
224
-
-**Synthesis can lose nuance** — the 2K summary omits details the parent might have needed
225
-
-**Cost multiplied** — every sub-agent is a separate API call with its own token consumption
232
+
**Costs:**
233
+
-**No shared state** — each sub-agent starts fresh, so context-file loading cost is paid again per delegate
234
+
-**Synthesis can lose nuance** — the compact return omits details the orchestrator might have needed
235
+
-**Token cost multiplied** — every sub-agent is a separate API call with its own consumption
226
236
-**No nesting** — sub-agents cannot spawn sub-agents; the orchestrator is always the root
227
-
-**10 parallel cap** — Claude Code limits concurrent sub-agents to 10
237
+
-**Concurrency cap** — Claude Code limits concurrent sub-agents to 10
228
238
229
-
The trade-off is tokencost, not accuracy. You pay to process tokens in both contexts, but the orchestrator stays clean. That often improves first-iteration accuracy enough to save tokens compared with multiple correction cycles from a polluted parent context.
239
+
These are token-cost tradeoffs in exchange for delegation and specialization — the right tradeoff when per-agent optimization improves outcome quality faster than the added token spend costs.
230
240
231
-
Sub-agents are ideal for heavy research, multi-file analysis, and exploratory tasks where the journey matters less than the destination. They can also generate independent plans or implementations when you want to compare options before applying one result.
241
+
Sub-agents are ideal for delegating independent research, multi-file analysis, and exploratory tasks to the agent best suited for each slice, and for generating independent plans or implementations across specialized models when you want to compare options before applying one result.
232
242
233
243
## Context Compaction
234
244
@@ -309,8 +319,8 @@ Eager loading is simple but charges the full catalog to every request. Deferred
309
319
**Skills: procedure content arrives only when activated**
310
320
A lightweight catalog supports discovery; the selected workflow enters near the active turn. Manual activation favors reliability, while model activation favors convenience.
311
321
312
-
**Sub-agents: raw exploration stays outside the parent**
313
-
A sub-agent can consume 150K tokens internally while returning only a small synthesis. Use separate windows for research trails and multi-file exploration when the parent needs conclusions rather than the full journey.
322
+
**Sub-Agents: delegation via isolated windows with per-agent optimization**
323
+
A sub-agent can consume 150K tokens internally while returning only a small synthesis. Use delegation to assign sub-tasks to agents optimized per slice — the right LLM and system prompt for each work item — while the orchestrator stays focused on coordination.
314
324
315
325
**Compaction: working room is recovered by losing detail**
316
326
A summary replaces accumulated history, so facts needed later may disappear. External checkpoint files provide exact recall; a fresh context restores inference quality.
Copy file name to clipboardExpand all lines: website/docs/reliability-levers.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -114,7 +114,7 @@ unnecessary dependent transformations and handoffs.
114
114
<OrchestrationLeverDiagram />
115
115
</DiagramFrame>
116
116
117
-
Orchestration also removes dependencies. Run independent research in parallel sub-agents rather than one long serial thread. Separate implementation from review when they need different judgment. Stop before code turns a human decision into structure. [Sub-agents](./context-engineering.mdx#sub-agents)are useful because they isolate noisy work and return compact results.
117
+
Orchestration also removes dependencies. Run independent research in parallel sub-agents rather than one long serial thread. Separate implementation from review when they need different judgment. Stop before code turns a human decision into structure. [Sub-agents](./context-engineering.mdx#sub-agents)change orchestration by letting a single task be decomposed across multiple specialized agents — each running on the LLM and system prompt optimized for its slice — rather than overloading one context, isolating noisy work and reducing dependency length in the parent chain.
118
118
119
119
This lever does not fix missing facts or an unclear success condition. Better shape only helps when each unit is grounded and judgeable.
0 commit comments