Orchestrating several agents
One agent can hand parts of a job to others. Learn the orchestrator-worker pattern and handoffs, and when more agents help or just add cost and confusion.
In 60 seconds
Orchestrating several agents
One agent can hand parts of a job to others. Learn the orchestrator-worker pattern and handoffs, and when more agents help or just add cost and confusion.
Two common patterns
| Pattern | How it works | Good for |
|---|---|---|
| Orchestrator-worker | A lead agent splits the task, sends parts to worker agents (often in parallel), then combines their results. | Research across many sources, reviewing many files, work that splits into independent parts. |
| Handoff (routing) | One agent passes the whole conversation to a more suitable agent, like a phone call transferred to the right department. | Customer support with separate billing, delivery and technical agents. |
Orchestrator-worker in code
from concurrent.futures import ThreadPoolExecutor
def call_model(prompt: str) -> str:
# Placeholder. Plug in your provider here.
return "[model answer to: " + prompt[:50] + "...]"
def worker(sub_task: str) -> str:
# Each worker could run its own agent loop with its own narrow tools.
return call_model("You are a research worker. Do only this, and reply "
"in at most 5 bullet points with sources: " + sub_task)
def orchestrate(goal: str) -> str:
sub_tasks = [ # in real code, ask the model for this list as JSON
"Price and validity of plan A",
"Price and validity of plan B",
"Price and validity of plan C",
]
with ThreadPoolExecutor(max_workers=3) as pool:
results = list(pool.map(worker, sub_tasks))
notes = "\n".join(t + ": " + r for t, r in zip(sub_tasks, results))
return call_model("Goal: " + goal + "\nWorker notes:\n" + notes +
"\nCombine into one short comparison. Say if anything is missing.")
print(orchestrate("Compare three mobile plans for a student"))Handoffs
transfer_to_billing(reason). When the model calls it, your code switches to the billing agent's instructions and tools, and passes a short summary of the case. Decide carefully what travels with the handoff: the full conversation, a summary, or only the facts the next agent needs.When more agents help, and when they hurt
- The task is short or strictly step-by-step
- Every step depends on the one before
- Agents must share lots of detailed context
- You cannot yet make one agent work reliably
- The work splits into independent parts
- Parts can run in parallel to save time
- Different parts need different tools or permissions
- One context would be too full for a single agent
Design rules
- Give each worker a clear sub-task, a done-test and an output format.
- Give each worker only the tools its sub-task needs. A research worker does not need the email tool.
- Limit the number of workers and the depth: workers should not spawn workers without limits.
- Trace every agent's calls under one run id, so you can follow a problem across agents.
- Have the orchestrator check results, for example for missing parts or contradictions, before combining.
Watch and read more
Lab
A written design for a two-level agent system, with a clear argument for why it needs more than one agent.
The problem
A newspaper wants a system that, every morning, reads 10 regional news websites and produces a one-page summary of farm-related news in simple language.
- Decide: one agent, or orchestrator plus workers? Write three sentences explaining why.
- If you choose workers: list each worker's sub-task, tools and output format. If not, write the single agent's steps.
- Write the rule for what the orchestrator does when a worker fails or returns nothing.
- Mark which agent, if any, may publish, and what approval it needs.
You are done when
Hard questions
Try to answer before you reveal. If you can answer these, you understood the lesson.
Q1Two workers return facts that contradict each other. What should the orchestrator do?Reveal
It should not quietly pick one. It can check the sources each worker gave, ask a worker to re-check, or report both versions with their sources and mark the conflict for a human editor. Hiding conflicts makes a summary look confident while being wrong.
Q2Why can adding a "reviewer" agent that checks another agent's work still miss errors?Reveal
The reviewer often uses a similar model with similar blind spots, sees only what it is shown, and may be too easily convinced by a confident answer. It helps most when it has a different view: access to the sources, a checklist of concrete tests, or tools that verify facts. Code-based checks and human review are still needed for important outputs.
Questions people ask
Is a multi-agent system smarter than a single agent?
Not automatically. It can cover more ground in parallel and keep each context focused, which can improve results on broad tasks. But it also adds cost, delay in combining results, and more places for errors. Measure on your own tasks.
Should all agents use the same model?
They do not have to. Some teams use a stronger model for the orchestrator and cheaper ones for simple workers. Test whether the cheaper workers are still good enough.
How do agents share information?
Through your code: arguments passed to a worker, results returned, or a shared store such as a notes file. Keep the shared data structured and small, and record which agent wrote each item.
What about agent-to-agent protocols?
There are protocols for agents from different systems to talk to each other. They bring their own trust questions: who is the other agent, and what can it ask for? See Agent-to-agent protocols and trust.
Lesson test
5 questions. Get 3 right (60%) to pass and complete this lesson.