The multi-agent dream: a planner agent decomposes the task, a researcher gathers data, a coder writes the implementation, a reviewer catches bugs. Reality: the coder has no idea what the planner intended because context was lost at the handoff.
Pattern 1: context envelope
Wrap every handoff in a structured envelope that carries task context, constraints, and lineage. The receiving agent doesn’t just get “write code” — it gets the full decision tree that led to this moment.
envelope = HandoffEnvelope(
task="implement flight search API",
origin="planner",
context={
"constraints": ["must use MCP", "latency < 2s"],
"prior_research": researcher.summary(),
"decision_log": planner.decisions()
}
)
Pattern 2: shared scratchpad
All agents read and write to a shared memory space. No handoffs needed — agents observe what other agents have produced and build on it. Works best for collaborative tasks where agents work in parallel.
Pattern 3: supervisor with replay
A supervisor agent maintains the full execution trace and replays relevant context to each worker agent. Higher token cost, but zero context loss. The supervisor acts as an intelligent context window manager for the entire swarm.