Paso 11 de 13 - Unos 35 min
Lab 10 - Sub-agents
Time: about 35 minutes. You will: let Steward hand reading-heavy work to a helper with its own context, a cheaper model, read-only tools, and a budget.
Why
"Turn my notes folder into a checklist of what I still need to review" means reading ten files. If Steward does that itself, ten files of text land in the main conversation, and every later request pays for them until compaction (lab 07) eventually summarizes them away. Most of that text was needed once. A helper can read it in its own session and hand back one short report.
Concepts
Delegation as a tool
Código del diagrama
sequenceDiagram
participant S as Steward (main session)
participant H as Helper (steward:sub:<id>)
S->>H: spawn_agent {task: "Checklist from notes/"}
H->>H: list_files, search_files, read_file x 8
H-->>S: "Helper report ... 1. Compaction vs context editing (notes/context-management.md:12) ..."
S->>S: answer the owner from the reportThe helper's whole conversation - every file it read - stays in its own session log. The main conversation gets one tool result: the report. To the main model, delegation is just another tool call; it can ask for several helpers in one response, and they run in parallel like any parallel tool calls.
Narrower and cheaper on purpose
| Setting | Steward | Helper |
|---|---|---|
| Model | model.main (Opus 5.5) |
model.subagent (Haiku 5.5), effort low |
| Tools | everything | read-only: time, list, read, search |
| System prompt | persona + rules | config/subagent.md (research helper) |
| Approvals | asks the owner | "ask" means deny: nobody is there to ask |
| Limits | maxStepsPerTurn |
subagents.maxSteps, task budget, result cap |
Tools are withheld, not just denied: the helper's request does not even list write_file,
run_program, memory, or spawn_agent, so it cannot write, act, change memory, or spawn more
helpers. The policy and the audit log still apply to what it does use.
Why Haiku 5.5: reading and summarizing does not need the strongest model (choosing a model), and it is much cheaper: $0.10 input and $0.50 output per million tokens for prompts up to 100,000 tokens, against $4 and $20 for Opus 5.5 (pricing).
A task budget
A task budget tells the model how many tokens the whole task may use, so it plans instead of
being cut off (output_config.task_budget, beta task-budgets-2026-03-13). It is advisory - the
model paces itself - so Steward also keeps a hard step limit and cuts the report to
subagents.maxResultChars. The helper's spending counts toward the daily limit (lab 12).
When not to delegate
A helper costs a model call or more and loses the conversation's context. Delegate when the task
is self-contained and reading-heavy; do it directly when it needs the conversation, or when one
read_file would do.
Build
config/subagent.md- the helper's instructions: read-only, citefile:line, short report. (paths.subagentin the config points to it.)src/agents/subagent.ts-SUBAGENT_TOOLSandspawnAgentTool(): a secondAssistantwithaskMeansDeny, a session per task, and the report as the tool result.src/core/assistant.ts-askMeansDenyturns an "ask" decision into a deny with a reason.src/core/anthropic-model.ts-taskBudgetTokensadds the task budget and its beta.src/app.ts- the helper gets the read-only subset of the main tools and its own model.
The helper reuses Steward's own turn loop (lab 01), so the policy, the audit log, and the spending ledger apply to it unchanged. The SDK also has a tool runner that runs the tool loop for you; it would work for a helper too, but then those checks would have to be added again in its hooks.
Run
pnpm steward chatyou> Use a helper to go through all my notes and list every topic I marked as weak, with the file and line.The [tool] spawn_agent line runs while the helper works. Afterwards:
pnpm steward sessions # a steward:sub:... session per helper
pnpm steward audit # the helper's read_file calls, each with its steward:sub:... sessionBreak it
- No writes. Ask:
Have a helper write a summary to summary.md. The helper has nowrite_file; its report says it could not write, and Steward offers to write it itself (with your approval). - No approvals inside. In your local config, set
read_filetoask, then ask for a helper task. The helper's reads are denied with "nobody can approve it here", and the main turn does not hang waiting. Set it back.
Check
pnpm lab 10The checkpoint proves: the report (not the files) reaches the main conversation and the helper
runs in a steward:sub: session; the helper sees exactly the read-only tools and its own system
prompt; tools it was not given fail; "ask" becomes "deny" inside a helper; the helper's requests
carry a task budget.
Exercises
- Run two helpers in parallel on different folders and compare the cost with doing it in the main
session (
steward usage). - Give helpers a
memoryview-only tool. What would you have to change inmemory-tool.ts, and is it worth the risk? - Add a
--depthlimit so a future "helper of a helper" design cannot recurse forever.
Claude API docs
- How tool use works - delegation is one more tool call in the loop
- Parallel tool use - several helpers from one response
- Tool runner - the SDK's ready-made tool loop
- Choosing a model - matching the model to the job
- Pricing - what the helper's cheaper model saves
- Building effective agents - the orchestrator-workers pattern
Exam connection
CCA-F - Agentic Architecture & Orchestration: orchestrator and worker agents, isolating context, least privilege for sub-agents, and budgets. Practice on CertLabPro.
Related: NVIDIA-Certified Professional: Agentic AI (NCP-AAI) - Agent Architecture and Design covers multi-agent design and delegation.
Previous: Lab 09 - Next: Lab 11 - Testing and evals