When you move beyond a single AI agent, you need orchestration β deciding which agent does what, when, and how they communicate. Three patterns cover 90% of use cases.
Pattern 1: Sequential pipeline
Agent A β Agent B β Agent C β Output
Each agent processes the output of the previous one. The simplest pattern.
When to use
- Content generation: research β draft β edit β publish
- Data processing: extract β transform β validate β load
- Code workflows: plan β implement β test β review
Implementation
async def sequential_pipeline(task):
# Step 1: Research (cheap model)
research = await call_agent("deepseek-chat", f"Research: {task}")
# Step 2: Draft (medium model)
draft = await call_agent("claude-sonnet-4.6", f"Write based on: {research}")
# Step 3: Review (best model)
final = await call_agent("claude-opus-4.6", f"Review and improve: {draft}")
return final
Cost optimization: Use cheap models for early stages, expensive models only for the final step. See our model routing guide.
Pros and cons
β Simple to implement and debug β Each step is independently testable β Easy to add/remove steps β Slow (each step waits for the previous) β Errors cascade forward β No parallelism
Pattern 2: Parallel fan-out
β Agent B1 ββ
Task β Agent A β Agent B2 ββ€β Agent C (merge)
β Agent B3 ββ
A coordinator splits work across parallel agents, then merges results.
When to use
- Batch operations: refactor 50 files simultaneously
- Multi-source research: search 5 databases in parallel
- Testing: run tests across multiple environments
- Kimiβs Agent Swarm uses this pattern
Implementation
import asyncio
async def parallel_fanout(files, instruction):
# Fan out: process files in parallel
tasks = [
call_agent("claude-sonnet-4.6", f"{instruction}\n\nFile: {f}")
for f in files
]
results = await asyncio.gather(*tasks)
# Merge: combine results
merged = await call_agent("claude-opus-4.6",
f"Merge these changes, resolve conflicts:\n{results}")
return merged
Pros and cons
β Fast (N agents work simultaneously) β Scales linearly with parallelizable work β Merge step can be complex β Higher cost (N parallel API calls) β Conflict resolution between agents
Pattern 3: Hierarchical delegation
Manager Agent
βββ Specialist A (research tools)
βββ Specialist B (coding tools)
βββ Specialist C (communication tools)
A manager agent decides which specialist to delegate to based on the task. Each specialist has its own MCP tools.
When to use
- Complex workflows with different tool requirements
- Customer support: route to billing, technical, or sales specialist
- Development: route to frontend, backend, or DevOps agent
Implementation
async def hierarchical(task):
# Manager decides who handles it
routing = await call_agent("claude-sonnet-4.6",
f"Classify this task: {task}\nOptions: research, coding, communication")
if "research" in routing:
return await research_agent(task) # Has web search MCP
elif "coding" in routing:
return await coding_agent(task) # Has filesystem MCP
else:
return await comms_agent(task) # Has email/Slack MCP
Pros and cons
β Each specialist is optimized for its domain β Manager can use a cheap model, specialists use appropriate models β Maps well to MCP (each specialist has its own tools) β Manager can misroute tasks β More complex to set up β Manager is a single point of failure
Connecting to protocols
| Pattern | MCP | A2A |
|---|---|---|
| Sequential | Each agent has its own MCP tools | Not needed (internal pipeline) |
| Parallel | Shared MCP tools with conflict resolution | Not needed (same system) |
| Hierarchical | Each specialist has dedicated MCP tools | Useful for cross-vendor specialists |
Which pattern to start with
Start with sequential. Itβs the simplest, easiest to debug, and handles most use cases. Only move to parallel when you have genuinely parallelizable work, and hierarchical when you need specialized tool access.
See our multi-agent guide for the full implementation guide and our tool calling patterns for how individual agents use tools.
Related: How to Build Multi-Agent Systems Β· Tool Calling Patterns Β· Kimi Agent Swarm Β· MCP Complete Guide