Multi-Agent Orchestration Patterns
Coordinate multiple AI agents (planner, coder, reviewer) for tasks too big for one context.
Why
MCP's reference server repo has ~90,000 GitHub stars, and the Agentic AI Foundation grew from 49 founding members (December 2025) to 247 by August 2026, signaling rapid multi-agent ecosystem growth. A single agent hits context limits and loses the plot on big tasks.
Splitting work across specialized agents (planner decomposes, coder implements, reviewer critiques) keeps each context focused, produces better-reasoned output, and lets the loop self-correct without a human in every cycle. This is how you scale AI beyond a single prompt.
When
Orchestrate multiple agents when a task needs decomposition (a feature touching DB, API, UI, and tests), when one context cannot hold all relevant files, or when you want a built-in reviewer to gate the coder. Avoid it for tasks a single agent handles in one shot; the orchestration overhead is not worth it.
How
Example
Common Problems
- ⚠Error: Agent loops infinitely on the same tool call → add a max-iterations guard and a distinctness check on the last N actions.
- ⚠Error: Cannot find module '@modelcontextprotocol/sdk' → `npm install @modelcontextprotocol/sdk`; agents need the SDK to call MCP tools.
- ⚠Error: "Tool timed out after 30000ms" → increase the timeout config or break the task into smaller sub-tasks the agent can complete incrementally.
- ⚠Error: Agent loops infinitely on the same tool call → add a max-iterations guard and a distinctness check on the last N actions.
Best Practices
- ✓Define each role's input and output schema; serialize handoffs as JSON files.
- ✓Give the reviewer explicit, checkable reject criteria, not vague 'is this good' judgments.
- ✓Cap every loop (3 iterations) and escalate to a human on exhaustion.
- ✓Scope each coder run to only the files for its step to keep context focused.
- ✓Log the full agent transcript per step so failures are debuggable post-hoc.
FAQ
When is multi-agent orchestration worth the overhead?
When a task needs decomposition (a feature touching DB, API, UI, and tests) or one context can't hold all relevant files. For a single-file edit or one-shot task, one agent is faster — orchestration adds latency and failure modes for no gain.
What topology should I use: pipeline, loop, or fan-out?
Pipeline (planner, coder, reviewer) is simplest and works for most tasks. Add a loop (coder and reviewer until approve) for self-correction. Use fan-out (N independent coders plus merge) for parallelizable independent steps. Start with pipeline.
How do agents share context without shared memory?
Serialize every handoff as a JSON file. The planner's step list becomes the coder's input; the coder's diff becomes the reviewer's input. Each agent starts with a clean context reading only its input file — no implicit shared state.
How do I stop the reviewer agent from rubber-stamping?
Give it concrete, checkable reject criteria ('reject if the diff adds unrequested files, uses banned patterns, or fails any acceptance criterion') and require an explicit APPROVE/REJECT with reasons. A vague 'is this good?' reviewer approves everything and defeats the gate.
What if the coder and reviewer loop forever?
Cap every loop at 3 iterations and escalate to a human on exhaustion. Log the full transcript per step so the disagreement is debuggable. Infinite loops usually mean the spec is ambiguous or the reviewer's criteria conflict with the coder's constraints.