Agent Orchestration Explained
← /learn · 05

Multi-agent patterns

Single agent, supervisor, hierarchical, swarm, debate and map-reduce on the same task: every call on a timeline, each agent's context, and what each pattern costs in tokens, time and reliability.

Loading the animation…

Concept

A multi-agent system is a graph whose nodes are model calls with their own prompts, tools and contexts. The patterns differ in who talks to whom and therefore in who reads what: every agent pays, on every call, for every token in its own context. The animation lays one pattern's calls on a timeline, one lane per agent, with nothing queueing yet (that is chapter 8); the table under it runs all six on the same task: compare 4 vendors, each needing a search and a short sub-answer, then a recommendation.

  • Single agent. One context, one loop: search, read, search, read … answer. The fewest calls (5), the cheapest ($0.0309), and because each prompt extends the last, most of its input is a cached prefix (7,620 of 12,700 tokens). Its weakness is that context grows with every tool result.
  • Supervisor. A supervisor delegates each sub-question to a worker that starts from a fresh, short context and returns only its answer. 13 calls, one at a time, so it is slow (34.6 s).
  • Hierarchical. A supervisor of team leads, each a supervisor of workers: the top never sees a worker's messages, only a lead's summary. More calls again (17), in return for bounded contexts at every level.
  • Swarm. Specialists hand off to each other directly, with no supervisor: fewer calls (8), but the message history is shared, so each specialist reads everything said so far under its own system prompt.
  • Debate. One researcher gathers the evidence; three debaters answer, read each other's answers and answer again; a judge takes the majority (after Du et al., Improving Factuality and Reasoning in Language Models through Multiagent Debate). It buys reliability by voting: 90.2% against the supervisor's 81.7%, at $0.11.
  • Map-reduce. A planner sends every sub-question to a worker at once (LangGraph's Send, chapter 6) and a reducer writes the answer: the supervisor's isolation without its serial chain, 15.9 s instead of 34.6 s.

On this small task the single agent wins outright: 90.3% success for $0.0309. Every extra call is one more thing that can go wrong, and splitting work that fits in one context only adds calls. Grow the task and it turns: with 16 sub-questions and 1,500-token results, the single agent's prompts pass 229,500 tokens in total and its success falls to 11.2%, while map-reduce keeps every worker's context short and holds 50.6% in 25.6 s. The swarm, whose shared history grows fastest, collapses (0.7%, $1.16). Set the accuracy penalty to "none" and the reason shows: with accuracy independent of context length, the single agent's 70.9% is the best of the six again, because splitting only multiplies the number of calls. Which pattern wins depends on how fast accuracy falls with context, and that is a property of your model and task to measure, not to assume.

Maths

Call ii reads nin_i prompt tokens, of which cic_i are a cached prefix (the agent's previous prompt, when at least 1,024 tokens), and writes oio_i. Cost and success follow the equation. For a chain of kk sub-questions, the single agent's prompt before call jj holds about S+j (r+o)S + j\,(r + o) tokens (system prompt, then a result and a tool call per step), so its total input grows as k2k^2; a supervisor's workers each read about S+h+rS + h + r, constant in kk, while the supervisor itself grows only by the sub-answers. That is the trade: the single agent pays quadratically in tokens but makes k+1k + 1 calls; a supervisor pays linearly in tokens but makes 3k+13k + 1 calls, and P=∏piP = \prod p_i punishes every one of them. Debate replaces a product with a vote: for three independent debaters with accuracies q1,q2,q3q_1, q_2, q_3, the majority is right with probability q1q2+q1q3+q2q3−2 q1q2q3q_1 q_2 + q_1 q_3 + q_2 q_3 - 2\,q_1 q_2 q_3, which exceeds their common value qq when all three are equally accurate and q>12q > \tfrac12 (3q2−2q3>q3q^2 - 2q^3 > q), and exceeds their mean when all three are above one half. It need not beat the best debater: with q=(0.99,0.51,0.51)q = (0.99, 0.51, 0.51) the majority is right with probability about 0.7550.755, so a vote helps only when the voters are comparably accurate and their errors independent.

Latency is the longest path through the calls (each call's time to first token plus its output at the decode rate, tool calls included): sequential patterns take the sum of their calls, map-reduce the planner plus the slowest worker plus the reducer.

Code

The success rule and the cache rule, cut from the vendored engine (patterns.ts):

for (const c of p.calls as Obj[]) {
  if (c.role === "critical") out = out * c.p;
  else if (c.role === "vote") (groups[c.group] ??= []).push(c.p);
}
for (const g of Object.values(groups)) out = out * maj3(g[0]!, g[1]!, g[2]!);
return call.prefix >= price.min_tokens && call.prefix > 0 ? call.prefix : 0;