This skill should be used when the user asks to "design multi-agent system", "implement supervisor pattern", "create swarm architecture", "coordinate multiple agents", or mentions multi-agent patterns, context isolation, agent handoffs, sub-agents, or parallel agent execution.
Add this skill
npx mdskills install muratcankoylan/multi-agent-patternsComprehensive guide to multi-agent patterns with clear actionable strategies and real-world trade-offs
1---2name: multi-agent-patterns3description: This skill should be used when the user asks to "design multi-agent system", "implement supervisor pattern", "create swarm architecture", "coordinate multiple agents", or mentions multi-agent patterns, context isolation, agent handoffs, sub-agents, or parallel agent execution.4---56# Multi-Agent Architecture Patterns78Multi-agent architectures distribute work across multiple language model instances, each with its own context window. When designed well, this distribution enables capabilities beyond single-agent limits. When designed poorly, it introduces coordination overhead that negates benefits. The critical insight is that sub-agents exist primarily to isolate context, not to anthropomorphize role division.910## When to Activate1112Activate this skill when:13- Single-agent context limits constrain task complexity14- Tasks decompose naturally into parallel subtasks15- Different subtasks require different tool sets or system prompts16- Building systems that must handle multiple domains simultaneously17- Scaling agent capabilities beyond single-context limits18- Designing production agent systems with multiple specialized components1920## Core Concepts2122Multi-agent systems address single-agent context limitations through distribution. Three dominant patterns exist: supervisor/orchestrator for centralized control, peer-to-peer/swarm for flexible handoffs, and hierarchical for layered abstraction. The critical design principle is context isolation—sub-agents exist primarily to partition context rather than to simulate organizational roles.2324Effective multi-agent systems require explicit coordination protocols, consensus mechanisms that avoid sycophancy, and careful attention to failure modes including bottlenecks, divergence, and error propagation.2526## Detailed Topics2728### Why Multi-Agent Architectures2930**The Context Bottleneck**31Single agents face inherent ceilings in reasoning capability, context management, and tool coordination. As tasks grow more complex, context windows fill with accumulated history, retrieved documents, and tool outputs. Performance degrades according to predictable patterns: the lost-in-middle effect, attention scarcity, and context poisoning.3233Multi-agent architectures address these limitations by partitioning work across multiple context windows. Each agent operates in a clean context focused on its subtask. Results aggregate at a coordination layer without any single context bearing the full burden.3435**The Token Economics Reality**36Multi-agent systems consume significantly more tokens than single-agent approaches. Production data shows:3738| Architecture | Token Multiplier | Use Case |39|--------------|------------------|----------|40| Single agent chat | 1× baseline | Simple queries |41| Single agent with tools | ~4× baseline | Tool-using tasks |42| Multi-agent system | ~15× baseline | Complex research/coordination |4344Research on the BrowseComp evaluation found that three factors explain 95% of performance variance: token usage (80% of variance), number of tool calls, and model choice. This validates the multi-agent approach of distributing work across agents with separate context windows to add capacity for parallel reasoning.4546Critically, upgrading to better models often provides larger performance gains than doubling token budgets. Claude Sonnet 4.5 showed larger gains than doubling tokens on earlier Sonnet versions. GPT-5.2's thinking mode similarly outperforms raw token increases. This suggests model selection and multi-agent architecture are complementary strategies.4748**The Parallelization Argument**49Many tasks contain parallelizable subtasks that a single agent must execute sequentially. A research task might require searching multiple independent sources, analyzing different documents, or comparing competing approaches. A single agent processes these sequentially, accumulating context with each step.5051Multi-agent architectures assign each subtask to a dedicated agent with a fresh context. All agents work simultaneously, then return results to a coordinator. The total real-world time approaches the duration of the longest subtask rather than the sum of all subtasks.5253**The Specialization Argument**54Different tasks benefit from different agent configurations: different system prompts, different tool sets, different context structures. A general-purpose agent must carry all possible configurations in context. Specialized agents carry only what they need.5556Multi-agent architectures enable specialization without combinatorial explosion. The coordinator routes to specialized agents; each agent operates with lean context optimized for its domain.5758### Architectural Patterns5960**Pattern 1: Supervisor/Orchestrator**61The supervisor pattern places a central agent in control, delegating to specialists and synthesizing results. The supervisor maintains global state and trajectory, decomposes user objectives into subtasks, and routes to appropriate workers.6263```64User Query -> Supervisor -> [Specialist, Specialist, Specialist] -> Aggregation -> Final Output65```6667When to use: Complex tasks with clear decomposition, tasks requiring coordination across domains, tasks where human oversight is important.6869Advantages: Strict control over workflow, easier to implement human-in-the-loop interventions, ensures adherence to predefined plans.7071Disadvantages: Supervisor context becomes bottleneck, supervisor failures cascade to all workers, "telephone game" problem where supervisors paraphrase sub-agent responses incorrectly.7273**The Telephone Game Problem and Solution**74LangGraph benchmarks found supervisor architectures initially performed 50% worse than optimized versions due to the "telephone game" problem where supervisors paraphrase sub-agent responses incorrectly, losing fidelity.7576The fix: implement a `forward_message` tool allowing sub-agents to pass responses directly to users:7778```python79def forward_message(message: str, to_user: bool = True):80 """81 Forward sub-agent response directly to user without supervisor synthesis.8283 Use when:84 - Sub-agent response is final and complete85 - Supervisor synthesis would lose important details86 - Response format must be preserved exactly87 """88 if to_user:89 return {"type": "direct_response", "content": message}90 return {"type": "supervisor_input", "content": message}91```9293With this pattern, swarm architectures slightly outperform supervisors because sub-agents respond directly to users, eliminating translation errors.9495Implementation note: Implement direct pass-through mechanisms allowing sub-agents to pass responses directly to users rather than through supervisor synthesis when appropriate.9697**Pattern 2: Peer-to-Peer/Swarm**98The peer-to-peer pattern removes central control, allowing agents to communicate directly based on predefined protocols. Any agent can transfer control to any other through explicit handoff mechanisms.99100```python101def transfer_to_agent_b():102 return agent_b # Handoff via function return103104agent_a = Agent(105 name="Agent A",106 functions=[transfer_to_agent_b]107)108```109110When to use: Tasks requiring flexible exploration, tasks where rigid planning is counterproductive, tasks with emergent requirements that defy upfront decomposition.111112Advantages: No single point of failure, scales effectively for breadth-first exploration, enables emergent problem-solving behaviors.113114Disadvantages: Coordination complexity increases with agent count, risk of divergence without central state keeper, requires robust convergence constraints.115116Implementation note: Define explicit handoff protocols with state passing. Ensure agents can communicate their context needs to receiving agents.117118**Pattern 3: Hierarchical**119Hierarchical structures organize agents into layers of abstraction: strategic, planning, and execution layers. Strategy layer agents define goals and constraints; planning layer agents break goals into actionable plans; execution layer agents perform atomic tasks.120121```122Strategy Layer (Goal Definition) -> Planning Layer (Task Decomposition) -> Execution Layer (Atomic Tasks)123```124125When to use: Large-scale projects with clear hierarchical structure, enterprise workflows with management layers, tasks requiring both high-level planning and detailed execution.126127Advantages: Mirrors organizational structures, clear separation of concerns, enables different context structures at different levels.128129Disadvantages: Coordination overhead between layers, potential for misalignment between strategy and execution, complex error propagation.130131### Context Isolation as Design Principle132133The primary purpose of multi-agent architectures is context isolation. Each sub-agent operates in a clean context window focused on its subtask without carrying accumulated context from other subtasks.134135**Isolation Mechanisms**136Full context delegation: For complex tasks where the sub-agent needs complete understanding, the planner shares its entire context. The sub-agent has its own tools and instructions but receives full context for its decisions.137138Instruction passing: For simple, well-defined subtasks, the planner creates instructions via function call. The sub-agent receives only the instructions needed for its specific task.139140File system memory: For complex tasks requiring shared state, agents read and write to persistent storage. The file system serves as the coordination mechanism, avoiding context bloat from shared state passing.141142**Isolation Trade-offs**143Full context delegation provides maximum capability but defeats the purpose of sub-agents. Instruction passing maintains isolation but limits sub-agent flexibility. File system memory enables shared state without context passing but introduces latency and consistency challenges.144145The right choice depends on task complexity, coordination needs, and acceptable latency.146147### Consensus and Coordination148149**The Voting Problem**150Simple majority voting treats hallucinations from weak models as equal to reasoning from strong models. Without intervention, multi-agent discussions devolve into consensus on false premises due to inherent bias toward agreement.151152**Weighted Voting**153Weight agent votes by confidence or expertise. Agents with higher confidence or domain expertise carry more weight in final decisions.154155**Debate Protocols**156Debate protocols require agents to critique each other's outputs over multiple rounds. Adversarial critique often yields higher accuracy on complex reasoning than collaborative consensus.157158**Trigger-Based Intervention**159Monitor multi-agent interactions for specific behavioral markers. Stall triggers activate when discussions make no progress. Sycophancy triggers detect when agents mimic each other's answers without unique reasoning.160161### Framework Considerations162163Different frameworks implement these patterns with different philosophies. LangGraph uses graph-based state machines with explicit nodes and edges. AutoGen uses conversational/event-driven patterns with GroupChat. CrewAI uses role-based process flows with hierarchical crew structures.164165## Practical Guidance166167### Failure Modes and Mitigations168169**Failure: Supervisor Bottleneck**170The supervisor accumulates context from all workers, becoming susceptible to saturation and degradation.171172Mitigation: Implement output schema constraints so workers return only distilled summaries. Use checkpointing to persist supervisor state without carrying full history.173174**Failure: Coordination Overhead**175Agent communication consumes tokens and introduces latency. Complex coordination can negate parallelization benefits.176177Mitigation: Minimize communication through clear handoff protocols. Batch results where possible. Use asynchronous communication patterns.178179**Failure: Divergence**180Agents pursuing different goals without central coordination can drift from intended objectives.181182Mitigation: Define clear objective boundaries for each agent. Implement convergence checks that verify progress toward shared goals. Use time-to-live limits on agent execution.183184**Failure: Error Propagation**185Errors in one agent's output propagate to downstream agents that consume that output.186187Mitigation: Validate agent outputs before passing to consumers. Implement retry logic with circuit breakers. Use idempotent operations where possible.188189## Examples190191**Example 1: Research Team Architecture**192```text193Supervisor194├── Researcher (web search, document retrieval)195├── Analyzer (data analysis, statistics)196├── Fact-checker (verification, validation)197└── Writer (report generation, formatting)198```199200**Example 2: Handoff Protocol**201```python202def handle_customer_request(request):203 if request.type == "billing":204 return transfer_to(billing_agent)205 elif request.type == "technical":206 return transfer_to(technical_agent)207 elif request.type == "sales":208 return transfer_to(sales_agent)209 else:210 return handle_general(request)211```212213## Guidelines2142151. Design for context isolation as the primary benefit of multi-agent systems2162. Choose architecture pattern based on coordination needs, not organizational metaphor2173. Implement explicit handoff protocols with state passing2184. Use weighted voting or debate protocols for consensus2195. Monitor for supervisor bottlenecks and implement checkpointing2206. Validate outputs before passing between agents2217. Set time-to-live limits to prevent infinite loops2228. Test failure scenarios explicitly223224## Integration225226This skill builds on context-fundamentals and context-degradation. It connects to:227228- memory-systems - Shared state management across agents229- tool-design - Tool specialization per agent230- context-optimization - Context partitioning strategies231232## References233234Internal reference:235- [Frameworks Reference](./references/frameworks.md) - Detailed framework implementation patterns236237Related skills in this collection:238- context-fundamentals - Context basics239- memory-systems - Cross-agent memory240- context-optimization - Partitioning strategies241242External resources:243- [LangGraph Documentation](https://langchain-ai.github.io/langgraph/) - Multi-agent patterns and state management244- [AutoGen Framework](https://microsoft.github.io/autogen/) - GroupChat and conversational patterns245- [CrewAI Documentation](https://docs.crewai.com/) - Hierarchical agent processes246- [Research on Multi-Agent Coordination](https://arxiv.org/abs/2308.00352) - Survey of multi-agent systems247248---249250## Skill Metadata251252**Created**: 2025-12-20253**Last Updated**: 2025-12-20254**Author**: Agent Skills for Context Engineering Contributors255**Version**: 1.0.0256
Full transparency — inspect the skill content before installing.