Pattern: orchestrator–workers
A central LLM reads the task, decides at runtime which subtasks it needs, delegates each to a worker LLM and synthesizes the results: parallelization where the model, not your code, writes the task list.
Analogy: A general contractor walks the house, decides which trades the job needs (two electricians or none), briefs each one, and signs off on the combined result.
How it works
- It fits unpredictable work: a code change touching 2 files or 20, research with unknown angles.
- Workers get context isolation: each sees only its brief, so it stays focused and can run in parallel.
- Each brief needs an objective, output format, tools and boundaries, or workers duplicate or miss work.
- Synthesis, merging partial, overlapping or conflicting results, is the hardest step.
- Tokens add up (~15× a chat in Anthropic's research system): cap fan-out and rounds.
Check yourself
Answer to mark it learned; your answers aren't scored.
Your research orchestrator spawns ~20 workers even for simple questions like "What's our refund window?". Answers are fine, but the token bill is exploding. Best fix?
Go deeper
Full explanation
In orchestrator–workers, one LLM (the orchestrator) reads the input and decides the subtasks at runtime: which files to edit, which questions to research, how many pieces there are. It sends each subtask to a worker (a separate LLM call with its own focused brief and a fresh context), then synthesizes their outputs into one result, possibly launching another round.
The topology looks like Pattern: parallelization, but the plan has a different author. In parallelization your code fixes the subtasks; here the orchestrator invents them per input. That fits work you can't predict: a code change touching 2 files or 20, a research question with an unknown number of angles.
Workers get context isolation: each sees only its brief, not the orchestrator's whole history, so it stays focused and can run in parallel. The price:
- Tokens: Anthropic reports its multi-agent research system uses ~15× the tokens of a chat.
- Delegation: vague briefs make workers duplicate or miss work; each brief needs an objective, an output format, tools and boundaries.
- Synthesis: merging partial, overlapping or conflicting results is the hardest step.
Cap fan-out and rounds, and make workers return structured output.
Code Plan, fan out to workers, synthesize
import asyncio, json
from anthropic import AsyncAnthropic
client = AsyncAnthropic()
LEAD = "claude-sonnet-4-5" # stronger model plans and synthesizes
WORKER = "claude-haiku-4-5" # cheaper model executes narrow briefs
async def llm(model: str, prompt: str) -> str:
msg = await client.messages.create(model=model, max_tokens=4096,
messages=[{"role": "user", "content": prompt}])
return msg.content[0].text
async def orchestrate(task: str, max_workers: int = 5) -> str:
plan = json.loads(await llm(LEAD,
f"Break this task into at most {max_workers} independent subtasks. "
'Reply with JSON only: [{"objective": str, "scope": str, "output_format": str}]\n\n'
+ task))
# The subtasks come from the model, not from code: that is the whole pattern
briefs = [f"Objective: {s['objective']}\nStay inside this scope: {s['scope']}\n"
f"Return: {s['output_format']}" for s in plan[:max_workers]] # hard cap on fan-out
results = await asyncio.gather(*[llm(WORKER, b) for b in briefs],
return_exceptions=True) # one failure must not sink all
findings = "\n\n".join(f"## Subtask {i + 1}\n{r}" for i, r in enumerate(results)
if not isinstance(r, Exception))
return await llm(LEAD, f"Task: {task}\n\nWorker results:\n{findings}\n\n"
"Synthesize one answer. Resolve conflicts explicitly and list gaps.")Real example
A research assistant gets "Compare the EU AI Act, the NIST AI RMF and ISO 42001 for a bank deploying a credit model." The orchestrator plans four subtasks (one per framework, plus one on banking-specific obligations) and sends each to a worker with a brief: objective, preferred sources, and return a table of obligations with citations. Workers run in parallel (~40 s instead of ~150 s serially). The orchestrator merges the tables, notices that two workers disagree on a high-risk classification, and launches one more worker to resolve it before writing the final comparison.
Trade-offs +4 · −4
+ You gain
- Handles tasks whose shape you can't predict: the plan adapts to each input.
- Context isolation: each worker spends its whole window on one focused subtask.
- Independent subtasks run in parallel, cutting wall-clock time on broad tasks.
- Mix models: a strong orchestrator with cheaper workers.
− You pay
- Token-hungry: Anthropic measured ~15× a chat's tokens for multi-agent research.
- Nondeterministic plans: cost, latency and behaviour vary run to run, so evals must judge outcomes.
- Workers can't see each other's decisions, which hurts tightly coupled tasks.
- Synthesis is a single point of failure: a weak merge wastes good worker output.
Use it when
Complex tasks where the subtasks can't be predicted up front (multi-file code changes, research across many sources) and the answer is valuable enough to justify several times the tokens.
Avoid it when
Subtasks are known in advance (use parallelization), are tightly coupled and need shared context, or the task fits a single call or a single agent loop.
Numbers to know 4
- Anthropic (2025): an Opus 4 lead with Sonnet 4 subagents beat single-agent Opus 4 by 90.2% on its internal research eval.
- Same post: agents use ~4× the tokens of chat; multi-agent systems ~15×.
- In Anthropic's BrowseComp analysis, token usage alone explained ~80% of the performance variance.
- Spinning up 3–5 subagents in parallel (plus parallel tool calls) cut research time by up to 90% on complex queries.
Common pitfalls 4
- Over-delegation: Anthropic's early research agents spawned 50 subagents for simple queries. Put effort-scaling rules in the orchestrator prompt.
- Vague briefs (research the chip shortage): workers duplicate each other or leave gaps. Specify objective, format, tools and boundaries.
- Parallel workers writing the same files or records: conflicting edits. Partition the work, or let workers propose and one step apply.
- Using it when the subtasks are actually fixed: you pay for a planning call and nondeterminism for nothing.
Interview questions 3
Answer out loud first, then reveal.
What's the difference between orchestrator–workers and parallelization, and why does it matter?Show answer
Same topology, different author of the plan. In parallelization my code defines the subtasks, so cost, latency and evals are predictable. In orchestrator–workers the model decides the subtasks per input, which I need when the work can't be enumerated, like a refactor touching an unknown set of files. That flexibility costs determinism: plans vary between runs and token use can reach ~15× a chat's, so I cap fan-out and rounds and evaluate the final outcome rather than a fixed list of steps.
How would you design a multi-file code-change system with this pattern?Show answer
The orchestrator reads the request and a repo map, then emits a plan: which files, the change in each, and the interface contracts between them. Each worker gets one file plus those contracts in a fresh context; no two workers write the same file. A deterministic gate (apply patches, compile, run tests) sits before synthesis, and failures go back to the orchestrator with the test output, capped at about three rounds. The main failure mode is inconsistent edits across files, so the contracts in each brief are non-negotiable.
Why would a multi-agent setup beat a single agent, and when doesn't it?Show answer
Mostly because it applies more context in parallel: each worker spends its own window on one subtask, so the total tokens and tool calls aimed at the problem grow. In Anthropic's analysis, token usage alone explained ~80% of performance variance on BrowseComp. It loses when subtasks are tightly coupled, as in most coding, because workers can't see each other's decisions, and when the task isn't worth ~15× the tokens of a chat. Breadth-first research is the sweet spot.