AI engineering / Core / 02.21
Multi-agents
One lead agent splits a big job, hands the parts to helper agents that work at the same time, and checks what comes back.
10 min readFree
Several helpers, one job
The last lesson, Agent use cases, ended with a promise: next, multi-agent systems, several helpers working on one job. Here they are.
Think of planning a trip with friends. One friend looks at flights, one at hotels, one at the weather. They go off at the same time, then come back and tell the group. Someone puts it together. That someone is the organiser.
A multi-agent system works the same way. In this lesson you will learn the main layout, what you gain, what it costs, and how to tell when one agent is enough. Then you will run a small version yourself, free.
Key words
- Agent
- A program that uses a model to decide its next step, calls tools, and loops until the job is done. The Agents lessons cover this.
- Multi-agent system
- Several agents working on one job and talking to each other.
- Orchestrator
- The lead agent. It makes the plan, splits the job and hands out the parts. Some call it the lead agent.
- Worker
- A helper agent that does one part of the job. Some people say subagent.
- Reviewer
- A step that checks a worker's result against a rule and can send it back.
- Context
- Everything a model can see while it works. Each worker gets its own.
- Token
- A small piece of text a model counts. Models are billed by token. The Tokens lesson explains it.
What a multi-agent system is
The idea is older than chat models. Wikipedia describes a multi-agent system as "a computational system composed of multiple interacting intelligent agents". It adds that such systems "can solve problems that are difficult or impossible for an individual agent or a monolithic system to solve". A monolithic system is one big program doing everything alone.
Language models brought the idea to apps. The AutoGen paper's abstract describes a framework "that allows developers to build LLM applications via multiple agents that can converse with each other to accomplish tasks". The Frameworks lesson, next, looks at libraries like it.
Each worker is a full agent. It has its own instructions, its own tools and its own context. The last lesson, Multi-agent Context Sharing, covered what they should share with each other. This lesson is about how the whole team is laid out and what it costs.
The orchestrator-worker layout
The layout you will meet most is one lead and many workers. Anthropic's engineering team describes its Research feature this way: "Our Research system uses a multi-agent architecture with an orchestrator-worker pattern, where a lead agent coordinates the process while delegating to specialized subagents that operate in parallel."
Parallel means at the same time, not one after another. The same post says the lead agent "spins up 3-5 subagents in parallel rather than serially".
- 1
Plan
The orchestrator reads the request and decides which parts can be done on their own.
- 2
Hand out
It gives each part to a worker, with a clear task description.
- 3
Work
Each worker runs in its own context, using its own tools, at the same time as the others.
- 4
Check
A reviewer step tests each result against a rule. A weak one goes back for a redo.
- 5
Merge
The orchestrator puts the good results together into one answer.
A check step is worth having. The Anthropic post describes a last step of this kind in its own design: the system passes all findings to a CitationAgent, which processes the documents and the report to identify specific locations for citations.
Tip
Give every worker a detailed task. The Anthropic post warns: "Without detailed task descriptions, agents duplicate work, leave gaps, or fail to find necessary information." Short orders like "look into flights" are how two workers end up doing the same search.
Other layouts exist too. In AutoGen, for example, the agents converse with each other. This lesson sticks to the one lead and many workers layout, because that is the one the sources describe in detail.
What you gain
Parallel work
Three workers on three parts finish sooner than one agent doing all three in a row.
Focused context
Each worker only sees its own part, so its window holds less clutter. The Anthropic post says subagents work in parallel "with their own context windows" before "condensing the most important tokens for the lead research agent".
More room
A job too big for one context window can be split over several.
The post also reports a result from its own tests. It says a multi-agent system with Claude Opus 4 as the lead agent and Claude Sonnet 4 subagents "outperformed single-agent Claude Opus 4 by 90.2% on our internal research eval". That is one team's test on one kind of job, so treat it as an example, not a promise.
What it costs
Teams cost more than one person, and agents are the same. There are three costs to know.
Many more tokens
The Anthropic post says: "agents typically use about 4× more tokens than chat interactions, and multi-agent systems use about 15× more tokens than chats." Every token costs money.
Harder to debug
The same post says agents "make dynamic decisions and are non-deterministic between runs, even with identical prompts", and adds, "This makes debugging harder." With many agents there are many places for a mistake to hide.
Conflicting results
Two workers can come back with answers that disagree, or both do the same work. Someone has to notice and decide. The reviewer step is one way to do that.
The post is clear that it is not for everything: "some domains that require all agents to share the same context or involve many dependencies between agents are not a good fit for multi-agent systems today." If part B cannot start until part A is done, running them side by side gains nothing.
Tip
Start with one agent. Add workers only when the job splits into parts that really are independent, and the extra cost is worth the speed or room.
Build a tiny team, free
Now let us build one. The plan is a trip report with three parts: flights, hotels and weather. An orchestrator hands each part to a worker and runs them at the same time. A reviewer checks each result against one rule: it must contain at least one number. A result with no number goes back for a redo. Last, a tally adds up the tokens.
Python can run things at the same time with concurrent.futures. Its docs say "ThreadPoolExecutor is an Executor subclass that uses a pool of threads to execute calls asynchronously." A thread is one lane of work, and a pool is a small group of lanes.
from concurrent.futures import ThreadPoolExecutor
# Stand-in for a model: fixed answers and made-up token counts.
# The "market" helper gives a weak answer the first time and a better one on a redo.
ANSWERS = {
("flights", 1): ("Flights: 3 direct options, cheapest leaves at 07:10.", 120),
("hotels", 1): ("Hotels: 4 near the centre, best rated has 8.9 of 10.", 140),
("weather", 1): ("Weather: it looks fine.", 90),
("weather", 2): ("Weather: 22 degrees and dry on 5 of 7 days.", 110),
}
def fake_worker(topic, attempt):
text, tokens = ANSWERS[(topic, attempt)]
return {"topic": topic, "attempt": attempt, "text": text, "tokens": tokens}
def passes_rule(result):
# The rule: a useful answer must contain at least one number.
return any(ch.isdigit() for ch in result["text"])
topics = ["flights", "hotels", "weather"]
tally = {"orchestrator": 150, "workers": 0, "reviewer": 0}
with ThreadPoolExecutor(max_workers=3) as pool:
results = list(pool.map(lambda t: fake_worker(t, 1), topics))
for i, r in enumerate(results):
tally["workers"] += r["tokens"]
tally["reviewer"] += 30
if not passes_rule(r):
print("Reviewer: sent back", r["topic"], "->", r["text"])
redo = fake_worker(r["topic"], 2)
tally["workers"] += redo["tokens"]
tally["reviewer"] += 30
results[i] = redo
print("--- Trip report ---")
for r in sorted(results, key=lambda r: topics.index(r["topic"])):
print(f"- {r['text']} (try {r['attempt']})")
total = sum(tally.values())
print("Tokens:", tally)
print("Total:", total, "| one plain chat (made up):", 400)
print("About", round(total / 400, 1), "times as many")Output
Reviewer: sent back weather -> Weather: it looks fine.
--- Trip report ---
- Flights: 3 direct options, cheapest leaves at 07:10. (try 1)
- Hotels: 4 near the centre, best rated has 8.9 of 10. (try 1)
- Weather: 22 degrees and dry on 5 of 7 days. (try 2)
Tokens: {'orchestrator': 150, 'workers': 460, 'reviewer': 120}
Total: 730 | one plain chat (made up): 400
About 1.8 times as manyImportant: the workers here are stand-ins. fake_worker does not call a model. It looks up a fixed answer and a made-up token count, so the code runs free and gives the same output every time. A real model is slower, costs money for every token, can give a different answer each run, and can fail or refuse. The token numbers, and the 400 for a plain chat, are made up too.
Read the output. The reviewer found no digit in "Weather: it looks fine.", so it sent weather back. The second try returned "22 degrees and dry on 5 of 7 days", which passed. The orchestrator used 150 tokens, the workers 460 (the redo adds 110) and the reviewer 120, so the team used 730 in all. Against the made-up 400 for one chat, that is about 1.8 times as many. Real systems can be far higher, as the 15 times figure above shows.
Notice that the report is printed in a fixed order: flights, hotels, weather. The workers can finish in any order. To show it, here is a second small program. Helper A is slow, B is fast and C is in between.
import time
from concurrent.futures import ThreadPoolExecutor, as_completed
def slow_helper(name, seconds):
time.sleep(seconds)
return name
jobs = [("A", 0.3), ("B", 0.1), ("C", 0.2)]
with ThreadPoolExecutor(max_workers=3) as pool:
futures = [pool.submit(slow_helper, n, s) for n, s in jobs]
print("as they finish:", [f.result() for f in as_completed(futures)])
print("in the order asked:", [f.result() for f in futures])Output
as they finish: ['B', 'C', 'A'] in the order asked: ['A', 'B', 'C']
The Python docs describe as_completed as returning an iterator over the futures "that yields futures as they complete". So the first line follows the finish order, B then C then A. The second line goes through the list in the order the jobs were asked, A, B, C. A final report should use the second way, so the reader sees the same page every time.
Keeping a team under control
Back to the costs. Here is how to keep them from running away.
Count tokens
Keep a tally per agent, like the demo. When the bill jumps, you can see which worker caused it.
Write down every hand-off
Log what each worker was asked and what it sent back. The Context Evaluation lesson covers checking results.
Set a limit
Cap the number of workers and the number of redos. A reviewer that keeps sending work back can loop for ever.
The Anthropic post adds a point about fit. It says most coding tasks involve fewer truly parallelizable tasks than research, and that LLM agents are not yet great at coordinating and delegating to other agents in real time. So the parts of a job must really be independent before you split it.
Quick check
Which job suits a multi-agent system best?
Quick check
In the demo, why did the weather result go back?
Recap
The layout
An orchestrator splits the job, workers do the parts in their own contexts, a reviewer checks, the orchestrator merges.
The gain
Parallel work, focused context and more room for big jobs.
The cost
Far more tokens, harder debugging and results that may clash.
You also ran a free team with stand-in workers. Swapping them for real models would make it slower, costly per token, and different on each run, but the shape stays the same.
Next: frameworks, the libraries that bundle all of this.
Sources
Last updated on 16 November 2026
Learn with me
Every lesson is free. I add new ones as I learn. Have a question, or want help with your own work? Book a short call.