Multi-Agent Systems: Orchestration Patterns
When splitting the work actually pays
A single agent with good tools is the correct default, and multi-agent systems are frequently an expensive way to rediscover that. The split earns its overhead under three conditions. Context isolation: each sub-task would otherwise flood one window with data the other tasks never need â a research step pulling fifty pages that the writing step has to scroll past. Role conflict: the standards of a strict reviewer and a fast drafter fight when collapsed into one prompt, because each turn overwrites the other's instruction. Parallelism: independent sub-tasks can run simultaneously, trading one long serial run for several short ones.
The cost side is real. Every hop adds a model call, a latency hop, and a lossy hand-off where the receiving agent sees only what the sender chose to write. Failures multiply too: if each agent succeeds 95 percent of the time, a four-step pipeline lands a correct result about 81 percent of the time before any coordination bugs appear. Measure against the single-agent baseline with the same tools before you commit to the topology.
Messages are the interface, not the shared brain
Whatever structure you choose, agents communicate through messages, and the message schema is the most consequential design decision in the system. A message that carries only free-form prose forces the receiver to re-infer intent, identifiers, and completeness on every hop.
from dataclasses import dataclass, field
from enum import Enum
from typing import Any
import time
class Kind(Enum):
TASK = "task"
RESULT = "result"
REQUEST = "request"
BROADCAST = "broadcast"
@dataclass
class Message:
sender: str
receiver: str
kind: Kind
payload: dict[str, Any]
conversation_id: str
in_reply_to: str = ""
expects_reply: bool = False
sent_at: float = field(default_factory=time.time)
class Bus:
def __init__(self):
self.agents: dict = {}
self.inbox: dict = {}
self.dead_letters: list = []
def register(self, name: str, agent):
self.agents[name] = agent
self.inbox[name] = []
def send(self, message: Message) -> None:
if message.receiver not in self.inbox:
self.dead_letters.append(message)
return
self.inbox[message.receiver].append(message)
def deliver_all(self) -> int:
moved = 0
for name, queue in self.inbox.items():
while queue:
message = queue.pop(0)
reply = self.agents[name].receive(message)
if reply is not None:
self.send(reply)
moved += 1
return moved
Note the fields that make debugging possible: a conversation id that threads every message of one task together, a reply reference, and an explicit statement of whether a reply is expected. Systems built on bare strings are undebuggable within a week, because you cannot tell whether an agent is silent because it finished or because it never understood the assignment.
The orchestrator pattern
A central coordinator decomposes the goal, assigns sub-tasks, and synthesises results. It is the simplest topology to reason about and the easiest to trace, which is why most production systems start here.
import json
class Orchestrator:
def __init__(self, planner, workers: dict, synthesizer, budget_steps=12):
self.planner = planner
self.workers = workers
self.synthesizer = synthesizer
self.budget_steps = budget_steps
def decompose(self, goal: str) -> list:
raw = self.planner.generate(
f"Split into at most 5 independent sub-tasks as a JSON array.\nGoal: {goal}"
)
try:
steps = json.loads(raw)
except json.JSONDecodeError:
steps = [goal]
return steps if isinstance(steps, list) else [goal]
def run(self, goal: str) -> str:
plan = self.decompose(goal)
results = []
for step in plan[:self.budget_steps]:
worker = self.pick_worker(step)
result = worker.execute(step, context={"prior": results[-2:]})
results.append({"step": step, "worker": worker.name, "output": result})
return self.synthesizer.generate(
f"Goal: {goal}\nFindings: {results}\nWrite the final deliverable."
)
def pick_worker(self, step: str):
return max(self.workers.values(), key=lambda w: w.matches(step))
The coordinator is a single point of failure in both senses: a bad decomposition propagates everywhere, and one slow worker stalls the whole run. Keep the plan visible in logs, pass only the last two prior results into each step to control context growth, and give the synthesiser explicit instructions about which findings it may override.
Pipeline, hand-off and peer patterns
When sub-tasks have a fixed order â research into outline into draft into review â a pipeline beats an orchestrator because no planning call is needed and each stage's output format is known in advance. Peer or debate patterns are the third option: several agents produce independent answers, then a critic or a vote reduces them. Debate buys accuracy on questions with a verifiable answer, at the cost of multiplying inference.
| Topology | Coordination cost | Best for | Main risk |
|---|---|---|---|
| Orchestrator | One planning call per run | Tasks with unpredictable structure | Planner errors cascade |
| Pipeline | None after design | Fixed, known stage orders | Brittle hand-offs |
| Parallel map-reduce | Fan-out and merge | Independent sub-tasks per item | Merge quality |
| Peer debate | One round per agent | Questions with checkable answers | Consensus on a wrong answer |
| Hierarchical teams | Compounds with depth | Very large, separable workstreams | Coordination overhead dominates |
Choose with the same discipline as any architecture decision: start at the cheapest row that satisfies the task, and move down only when a measured failure demands it.
Shared state and write conflicts
Shared memory makes collaboration possible and introduces the classic concurrency problem in a new disguise. Two agents summarising the same document into one scratchpad, an agent overwriting a field another agent just set, or three agents appending notes until the context window is gone are all versions of the same bug.
The workable rule is to make writes explicit and ownership clear. Give each agent a private working area, let them propose entries to the shared store, and have a designated writer â usually the orchestrator or the synthesiser â commit them. Version or timestamp every entry so a stale overwrite can be detected, and cap the store's size with an explicit compaction step rather than letting it grow until the platform truncates it silently.
Failures that only appear with multiple agents
Coordination introduces failure modes that a single agent cannot have. Redundant work: two agents research the same question because the plan did not partition cleanly, doubling cost and producing contradictory answers. Hallucinated hand-offs: an agent reports a result the next stage never receives, because the reply was routed to the wrong conversation. Echoing: agents agree not because they verified anything but because each one saw the previous confident answer in its context. And unrestrained delegation: an agent told to complete a task spawns sub-tasks of its own until a budget limit stops the recursion.
Defences are unglamorous. Unique conversation ids with reply references catch misrouting. Independent verification by an agent that has not seen the original answer catches echoing. Hard budgets on depth and total calls catch runaway delegation. Tracing every message in a single timeline catches the rest â and it is the tool you will wish you had the first time a run produces a confident answer that no participant can reconstruct.
Counting the cost of every extra voice
Every additional agent is another full context assembly plus another model call, and the arithmetic is unforgiving. A four-agent pipeline with a synthesiser easily costs five to eight times a single-agent run once you include retries, because each stage re-reads the shared history, and the synthesiser then reads everything again. Latency multiplies too: stages that run in parallel stay bounded by the slowest one, while sequential pipelines simply add up, which is why a well-built single agent often returns a first draft faster than a committee returns an outline.
The decision procedure that holds up under review is to measure both axes at once. Start from a single-agent baseline with the same tools and the same budget, then split only where the split demonstrably buys something: a capability the baseline could not reach, a quality gain on an evaluation set, or a wall-clock reduction from genuine parallelism. Track completed-task rate and total spend on the same dashboard, because coordination frequently improves the first while quietly worsening the second.
Two cost traps deserve their own watch. Retries: a failing stage that gets retried three times inside each of four agents turns one expensive run into twelve. And context hoarding: agents that keep the entire run history in every call make each successive call more expensive than the last, so pass forward only what the next stage needs and keep the full transcript in storage for tracing rather than in the prompt.
Common Mistakes
Splitting into agents before a single-agent baseline is measured
Fix: Build the one-agent version with the same tools first; multi-agent must beat it on quality, cost, or latency to justify itself.
Passing free-form prose between agents
Fix: Use a structured message with conversation id, reply reference, and explicit completion status.
Letting every agent write to shared memory
Fix: Agents propose, one designated writer commits, and entries carry timestamps so stale overwrites are visible.
Allowing agents to spawn sub-agents without a depth limit
Fix: Cap delegation depth and total model calls per run, and alert when the cap is reached.
Best Practices
- Trace all agents onto one timeline keyed by conversation id; scattered logs hide coordination bugs.
- Give each role a narrow system prompt and a narrow tool set instead of one general prompt with caveats.
- Pass only the context a stage needs rather than the entire run history.
- Evaluate the system on completed-task rate and total cost together, since coordination often wins quality while losing economics.
Key Takeaways
- Split agents for context isolation, conflicting roles, or genuine parallelism â not for the appearance of sophistication.
- Message schemas with conversation ids and reply references are the difference between a debuggable system and a mystery.
- Orchestrator, pipeline, debate and hierarchical topologies trade coordination cost against flexibility; pick the cheapest one that fits.
- Shared state needs single-writer commits, timestamps, and a size cap or it will corrupt the run.
- Echoing, redundant work, and runaway delegation are multi-agent-only failures that require explicit defences.