Skip to content
The AI Agent Factory

27.3 An orchestrator and its subagents

Approved by
Panaversity ·
17 min read

In everyday life. A family hires a head cook for a wedding dinner. Before the day, the family fixes three things: the money for food, how many helpers the cook may bring, and the hour the dinner is served. On the day, the cook decides the rest. She sees what the market had, and she chooses which dishes to hand to a helper and what to tell each one. She hands over a whole dish with its recipe, never "all the chopping", because a helper with a whole dish needs nothing from the others. In this section, the cook is the orchestrator, the helpers are subagents, and the family's three limits are your code.

What you will learn. You practice this in Lab 27, Task 1.

  • What does an orchestrator hand to the model?
  • Which limits stay in your code?
  • Where should a job be cut?
  • What does an orchestrator cost, and when is one loop the fair choice?

Why it matters. A workflow's model call could pick a branch and could never add a step (27.2). An orchestrator can add a whole agent. What still limits the run is only what you wrote before it started.

At work. It is still Wednesday, May 5, 2027. The workflow is built. Now you build Dave Kowalski's review the other way. The orchestrator gets three things. The first is his one sentence. The second is a short list of subagents it may use, with vendor-lookup from Lab 26 among them. The third is its limits, with a review's budget of $1.00. You do not tell it which work to hand over, or when. After the run, you read the trace to learn what it chose.

What does an orchestrator hand to the model?

Two more decisions: when to split the work, and what to tell each helper. In this design an agent may start subagents, and then it combines their answers. That agent is an orchestrator. It is the parent of 26.5, with one difference. In Lab 26 your instructions told the parent to ask vendor-lookup for every vendor. Here nothing tells it. The exam guide calls the design "the orchestrator and subagent decomposition". A decomposition is the way a job is cut into parts.

On the Claude Agent SDK, the documentation says who makes the cut: "Claude decides on its own when to spawn a subagent and how many to spawn."1 To spawn a subagent means to start one. The model chooses from "the task and each subagent's description",1 the line you wrote to say what that subagent is for.

So in docs/architecture.md, the orchestrator's column cannot be filled before the run. For the steps it hands over, "who decides" reads "the model", and you copy what it chose from the trace.

The model also decides whether to wait. "By default, a subagent your main agent spawns runs in the background", and "the report arrives in a later turn."1 To make the choice yourself, ask for it in the prompt: tell the orchestrator to wait for each report. When you read an orchestrator's trace, an answer can arrive several steps after the call that asked for it.

The same essay lists this design among its workflows, as "orchestrator-workers", and says the subtasks are "determined by the orchestrator".2 Whatever the label, the table shows the same thing: your code starts the orchestrator and limits it, and the model decides the split.

Which limits stay in your code?

Five: the list of subagents, how deep they may go, how many run at once, the turn limit and the budget. The model cannot change any of them during the run. On the Claude Agent SDK each is a setting, and each has a value if you set nothing:13

The limitIts settingIf you set nothing
The list of subagentsThe agents you defineA built-in general-purpose subagent is also there, which the model can start "without you defining anything". CLAUDE_AGENT_SDK_DISABLE_BUILTIN_AGENTS=1 removes it.
How deepCLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH"3 layers of subagents below your main agent"
How many at onceCLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS"20 subagents running at once"
The turn limitmaxTurns"No limit"
The budgetmaxBudgetUsd"No limit"

The model can also start a fork "with nothing configured".1 27.6 says what a fork is and how to stop one.

The documentation says what a run with no limits can become: "a subagent can spawn subagents of its own, so one prompt can grow into a tree of agents."1 Two of the five have no limit until you set one. 27.6 reads a trace from a run where nobody did.

The budget covers the helpers too: "their spend counts toward the total", and at the cap, starting one more subagent fails with Budget limit reached.3 A subagent can also have a turn limit of its own (27.4).

In this book's lab, the orchestrator turns the built-in subagent off and denies forks, so its list holds only the subagents you wrote.

These five are the stop and the boundary of 21.8. The third thing code holds is the check. The orchestrator's review goes through the same check by code as the workflow's.

Where should a job be cut?

By the context each part needs, not by the kind of work. Anthropic's advice is to "adopt a context-centric view rather than a problem-centric view when decomposing work."4

A cut by kind of work would give Brightline three helpers: one gathers the facts for every invoice, one judges them, and one writes the review. Each needs everything the one before it found. Anthropic says of such a design: "Each handoff loses context."4

A cut by context looks for a part that needs little going in and sends little back. vendor-lookup is one: a vendor id goes in, and one line of terms comes back. The rule is the one 12.6 gave for coding sessions. Anthropic states it for agents: "Work should only be split when context can be truly isolated."4

The model makes the cut, and you shape it through the list. Each subagent's description and tools describe one part that can be done alone.

What does an orchestrator cost, and when is one loop the fair choice?

It costs several times the tokens of one agent, and its path may differ on every run. One loop is the fair choice until something you measured says to split.

What you buy. An orchestrator can handle a case that no branch of a workflow covers.

What you pay. Anthropic reports that "multi-agent implementations typically use 3-10x more tokens than single-agent approaches for equivalent tasks."4 At Brightline all of it is paid from the same $1.00. Also, the path is not fixed (Why it matters), and nothing promises the same steps next month (27.1).

When several agents win. Anthropic names three cases: "when context pollution degrades performance, when tasks can run in parallel, and when specialization improves tool selection or task focus. Outside these situations, the coordination costs typically exceed the benefits."4 Context pollution is Chapter 26's bloat: a window so full of side work that answers get worse.

The other choice. One agent in one loop, with skills (16.1) for its special jobs. Anthropic reports, from several companies' deployments, that "a single agent with skills frequently outperformed both the one-prompt-for-everything design and the subagent design on quality", often at lower cost and in less time.5 That is the vendor's report, not a result this book measured. It agrees with 23.18 in detail, "Split for a measured reason", and with 31.10.

How to decide. Measure it. "Build a small end-to-end eval, fold in one subagent, and keep it as a subagent only if the folded version scores worse".5 To fold a subagent in means to give its work back to the main loop. An eval is a scored run over a set of cases, as in Chapter 24. In Lab 27, Task 2, you run both builds on the same invoices and record what each cost.

The operating rule: let the model decide the split only inside limits your code holds, and cut by context. Keep a subagent only when a measurement says it is worth its cost.

Do this now. Ask your coding agent to find the limits, without changing them. Copy this line:

List every subagent this project defines, with its description and its tools. For each one, say what it needs from its parent and what it sends back. Then name the five limits on a run that uses them: the list of subagents, the depth, the number at once, the turn limit and the budget. For each limit, show me the line that sets it, or say that nothing sets it. Change no file.

Check yourself

Question 1 / 8

0 answered

In the orchestrator build of Dave Kowalski's review, who decides which work goes to a subagent, and when?

  1. Subagents in the SDK, Claude Agent SDK, Anthropic.↑↑2↑3↑4↑5↑6
  2. Building effective agents, Anthropic.↑
  3. How the agent loop works, Claude Agent SDK, Anthropic.↑↑2
  4. Building multi-agent systems: when and how to use them, Anthropic.↑↑2↑3↑4↑5
  5. Building agents: When to fold subagents into your main agent loop, Anthropic.↑↑2
Owner
Panaversity