Expert about 7 h
The picture
01
Router
pick specialists
02
Workers
parallel, scoped tools
03
Hand-off
bounded context
04
Synthesiser
grounded answer
05
Evaluator
check, retry
Why split into several agents
Genuine reasons: context isolation (a worker sees only what its job needs), specialisation (different tools, prompts or models per role), parallelism (independent subtasks run at once) and separation of duties (a checker that is not the author). If none of these applies, a single agent with several tools is simpler and usually better.
A supervisor with parallel workers
import asyncio, json
async def route(question: str, specialists: dict[str, str]) -> list[str]:
menu = "\n".join(f"- {k}: {v}" for k, v in specialists.items())
out = await allm(f"Which specialists are needed? Return a JSON list of names from:\n{menu}\n\nQuestion: {question}", 200)
return [n for n in json.loads(out) if n in specialists]
async def run_worker(name, question, workers, sem):
async with sem:
try:
res = await asyncio.wait_for(workers[name].arun(question), timeout=90)
return {"worker": name, "ok": True, "findings": res.answer[:3000], "evidence": res.evidence[:10]}
except Exception as e:
return {"worker": name, "ok": False, "error": f"{type(e).__name__}: {e}"}
async def answer(question, workers, specialists):
chosen = await route(question, specialists)
sem = asyncio.Semaphore(4)
results = await asyncio.gather(*(run_worker(n, question, workers, sem) for n in chosen))
good = [r for r in results if r["ok"]]
if not good:
return "I could not get a reliable answer from any specialist."
brief = json.dumps(good, ensure_ascii=False)
return await allm(
"Write the final answer using ONLY the findings below. Cite the worker names. "
"If findings conflict or are missing, say so.\n\n" + brief + f"\n\nQuestion: {question}", 900)
This is orchestrator-workers with a parallel fan-out. Notice what protects it: a timeout per worker, failure isolation (one worker failing does not sink the run), a cap on findings passed on, and a synthesiser told to use only what it was given.
Hand-offs are an interface
What one agent passes to the next is a contract. Make it:
- Structured (findings, evidence ids, confidence) rather than free prose.
- Bounded in size, with explicit caps on rows, characters and items. Unbounded hand-offs cause oversized requests, higher cost and distracted models.
- Minimal: pass what the next agent needs, not the whole transcript. This also limits leakage between roles.
- Grounded: carry evidence references so the final answer can cite them.
Other patterns
- Router only: classification chooses one specialist. Cheap and effective; start here.
- Debate or ensemble: several agents answer independently and a judge picks or merges. Costs multiples; helps on reasoning tasks with a clear criterion.
- Evaluator loop: a separate model checks the output against requirements and triggers a bounded retry.
- Hierarchical: a manager delegates to sub-managers. Seldom worth the added latency and failure surface.
What goes wrong
- Compounding errors and drift: each agent trusts the previous one's output.
- Context loss across hand-offs: the worker lacks a fact the supervisor knew, so it solves the wrong problem.
- Redundant work and cost: several agents search for the same thing.
- Conflicting actions: two agents edit the same resource. Prefer a single writer.
- Hard-to-debug runs: many interleaved traces. Give every run and every worker a correlation id.
- Role confusion: the "reviewer" rubber-stamps because it shares the author's blind spots. Use different prompts, models or objective checks.
Research on multi-agent LLM failures finds that many problems come from specification and coordination, not model capability, so invest in clear contracts and verification before adding agents.
Common mistakes
- Starting with five agents because the diagram looks impressive.
- Letting agents talk freely when a fixed hand-off schema would do.
- No budget per run across all agents combined.
Exercises
- Build the supervisor above with two workers that have different tools. Inject a failure into one and confirm the answer degrades gracefully.
- Compare the multi-agent version with a single agent holding all tools on 20 questions: accuracy, cost and latency.
You are done when you can…
- Implement a supervisor that fans work out to specialists in parallel and merges grounded results
- Design a hand-off format that keeps worker context small and prevents leakage
- Name the main multi-agent failure modes and one mitigation for each