AI Agents & LLMsHard
How do multi-agent systems work, and when should you use one?
Learning path, stage 4 of 5: Agents, tools and MCP · question 7 of 10A multi-agent system splits work across several LLM agents, typically an orchestrator (lead) that plans and hands sub-tasks to worker agents, each with its own context and tools, then combines their results. It helps when work can run in parallel or would overflow one context. It costs many times more tokens and adds coordination failures, so use it only when the task justifies it.
Common topologies
- Orchestrator–workers: the lead plans, starts sub-agents, merges the results. The most common setup.
- Pipeline: specialised agents in sequence (research → write → review).
- Debate / critic: one agent proposes, another critiques.
- Handoffs: a router passes the conversation to a specialist agent.
Why it can help
- Parallel exploration: research across many sources at once.
- Separate contexts: each worker reads a lot and returns only a summary, which keeps the lead's context clean.
- Specialisation: different prompts, tools or cheaper models per role.
Why it can hurt
- Token cost: Anthropic measured single agents at about 4× the tokens of a chat, and multi-agent systems at about 15×.
- Lost context between agents. Each delegated task needs a clear objective, output format and limits.
- It's harder to debug and evaluate. Add tracing.
- Poor fit when sub-tasks are tightly coupled, as in most coding tasks.
Sources
Code example
tsx
1// Orchestrator-workers: plan, fan out in parallel, synthesise.2import Anthropic from "@anthropic-ai/sdk";3import { z } from "zod";4import { zodOutputFormat } from "@anthropic-ai/sdk/helpers/zod";56const client = new Anthropic();7const Plan = z.object({ subtasks: z.array(z.object({ objective: z.string(), output_format: z.string() })) });89const text = (m: Anthropic.Message) => m.content.flatMap((b) => (b.type === "text" ? [b.text] : [])).join("");1011export async function research(question: string) {12 const plan = await client.messages.parse({13 model: "claude-opus-5-5",14 max_tokens: 4096,15 messages: [{ role: "user", content: `Split into 2-5 independent research subtasks:\n${question}` }],16 output_config: { format: zodOutputFormat(Plan) },17 });1819 const findings = await Promise.all(20 plan.parsed_output!.subtasks.map((t) =>21 client.messages.create({22 model: "claude-sonnet-5-5", // cheaper worker model23 max_tokens: 4096,24 messages: [{ role: "user", content: `Objective: ${t.objective}\nReturn: ${t.output_format}` }],25 }).then(text),26 ),27 );2829 const final = await client.messages.create({30 model: "claude-opus-5-5",31 max_tokens: 8000,32 messages: [{ role: "user", content: `Question: ${question}\n\nFindings:\n${findings.join("\n---\n")}\n\nWrite the answer.` }],33 });34 return text(final);35}
To run it: follow the one-time setup guide, add npm i @anthropic-ai/sdk zod @modelcontextprotocol/sdk, save the code as a .ts file and run npx tsx file.ts. Anything marked declare is a part you supply.
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the AI Agents & LLMs set.