Multi-Agent Patterns with Strands 🤝
Published: January 5, 2025
How to build powerful systems by combining multiple AI agents. From simple orchestration to swarms.
The Problem with Single Agents
Single agents hit limits:
- Context windows overflow on complex tasks
- Specialization conflicts (coding vs writing vs research)
- Throughput bottlenecks on parallel work
- Failure modes cascade without isolation
Solution: Multiple specialized agents working together.
Pattern 1: Orchestrator-Worker
graph TB
User[👤 User] --> Orch[🎯 Orchestrator Agent]
Orch --> W1[📝 Writer Agent]
Orch --> W2[💻 Coder Agent]
Orch --> W3[🔍 Researcher Agent]
W1 --> Orch
W2 --> Orch
W3 --> Orch
Orch --> User
style Orch fill:#f9f,stroke:#333,stroke-width:4px
When to use: Complex tasks with clear subtasks.
from strands import Agent
from strands_tools import use_agent
orchestrator = Agent(
system_prompt="""You orchestrate specialized agents:
- For writing: use_agent with writer prompt
- For coding: use_agent with coder prompt
- For research: use_agent with researcher prompt
Break complex tasks into subtasks and delegate.""",
tools=[use_agent]
)
orchestrator("Create a blog post about AI safety with code examples")
Implementation with use_agent
# The orchestrator delegates to specialized sub-agents
result = agent.tool.use_agent(
prompt="Write an introduction about AI safety",
system_prompt="You are an expert technical writer. Be concise and engaging.",
tools=["editor", "file_write"] # Limit tools per sub-agent
)
Pattern 2: Pipeline
graph LR
A[📥 Input] --> B[🔍 Research]
B --> C[📝 Draft]
C --> D[✏️ Edit]
D --> E[✅ Review]
E --> F[📤 Output]
style A fill:#bbf
style F fill:#bfb
When to use: Sequential workflows with clear stages.
# Each agent handles one stage
stages = [
("research", "Research the topic thoroughly"),
("draft", "Write a first draft from the research"),
("edit", "Improve clarity and fix errors"),
("review", "Final quality check and polish")
]
content = user_input
for stage_name, system_prompt in stages:
result = agent.tool.use_agent(
prompt=content,
system_prompt=system_prompt
)
content = str(result)
Pattern 3: Parallel Ensemble
graph TB
Input[📥 Query] --> A1[Agent 1<br/>Claude] & A2[Agent 2<br/>GPT-4] & A3[Agent 3<br/>Gemini]
A1 & A2 & A3 --> Merge[🔀 Merge/Vote]
Merge --> Output[📤 Best Answer]
style Merge fill:#ff9
When to use: Critical decisions, diverse perspectives.
from strands_tools import use_agent
# Query multiple models in parallel
results = []
# Claude perspective
results.append(agent.tool.use_agent(
prompt=query,
system_prompt="Analyze from a safety-first perspective",
model_provider="anthropic"
))
# GPT-4 perspective
results.append(agent.tool.use_agent(
prompt=query,
system_prompt="Analyze from an efficiency perspective",
model_provider="openai"
))
# Merge results
final = agent.tool.use_agent(
prompt=f"Synthesize these perspectives:\n{results}",
system_prompt="Combine the best insights from each analysis"
)
Pattern 4: Swarm (Zenoh)
graph TB
subgraph "Zenoh Mesh Network"
D1[🦆 DevDuck 1<br/>Research] <--> Z[Zenoh]
D2[🦆 DevDuck 2<br/>Coding] <--> Z
D3[🦆 DevDuck 3<br/>Testing] <--> Z
D4[🦆 DevDuck 4<br/>Deploy] <--> Z
end
Z -.-> |Auto-discover| D1 & D2 & D3 & D4
style Z fill:#f0e6ff
When to use: Distributed work across machines.
# Terminal 1: Research agent
ZENOH_LISTEN="tcp/0.0.0.0:7447" devduck
# Terminal 2: Coding agent (auto-discovers)
devduck
# Terminal 3: Testing agent
devduck
# Broadcast to all
🦆 zenoh_peer(action="broadcast", message="everyone run git pull")
See DevDuck Swarms for full details.
Pattern 5: Hierarchical
graph TB
CEO[🎯 CEO Agent] --> VP1[📊 VP Engineering]
CEO --> VP2[📈 VP Product]
VP1 --> Eng1[💻 Backend Dev]
VP1 --> Eng2[🎨 Frontend Dev]
VP1 --> Eng3[🔧 DevOps]
VP2 --> PM1[📝 PM Features]
VP2 --> PM2[🔍 PM Research]
style CEO fill:#f9f,stroke:#333,stroke-width:4px
When to use: Complex organizations, domain separation.
ceo = Agent(
system_prompt="""You're the CEO coordinating VPs.
- Engineering VP handles technical decisions
- Product VP handles feature priorities
Delegate appropriately and synthesize results.""",
tools=[use_agent]
)
# CEO delegates to VPs who delegate to specialists
ceo("Launch a new authentication feature with OAuth support")
Pattern 6: Critic-Actor
sequenceDiagram
participant U as User
participant A as Actor Agent
participant C as Critic Agent
U->>A: Task
loop Until Approved
A->>A: Generate solution
A->>C: Submit for review
C->>C: Evaluate quality
alt Approved
C->>A: ✅ Approved
else Needs Work
C->>A: ❌ Feedback
end
end
A->>U: Final solution
When to use: High-quality output, self-improvement.
max_iterations = 5
solution = None
for i in range(max_iterations):
# Actor generates
solution = agent.tool.use_agent(
prompt=f"Create solution for: {task}\nPrevious feedback: {feedback}",
system_prompt="You are an expert implementer. Create high-quality solutions."
)
# Critic evaluates
review = agent.tool.use_agent(
prompt=f"Review this solution:\n{solution}",
system_prompt="You are a strict code reviewer. Find issues, suggest improvements."
)
if "APPROVED" in str(review):
break
feedback = str(review)
Choosing the Right Pattern
| Pattern | Best For | Complexity |
|---|---|---|
| Orchestrator | General complex tasks | Medium |
| Pipeline | Sequential workflows | Low |
| Ensemble | Critical decisions | Medium |
| Swarm | Distributed work | High |
| Hierarchical | Large organizations | High |
| Critic-Actor | Quality-critical output | Medium |
Anti-Patterns to Avoid
Common Mistakes
- Over-orchestration: Don't add agents for simple tasks
- No isolation: Agents should have limited, focused tools
- Missing coordination: Swarms need clear communication
- Infinite loops: Always have termination conditions
Tools for Multi-Agent
| Tool | Purpose |
|---|---|
use_agent |
Spawn sub-agents |
zenoh_peer |
P2P coordination |
websocket |
Real-time communication |
ipc |
Local process coordination |
Example: Full Research Pipeline
from strands import Agent
from strands_tools import use_agent, shell, retrieve
research_agent = Agent(
system_prompt="""You coordinate a research pipeline:
1. Research: Gather information using web search
2. Analysis: Extract key insights
3. Synthesis: Create coherent summary
4. Review: Quality check final output
Use use_agent to delegate each stage to a specialist.""",
tools=[use_agent, shell, retrieve]
)
research_agent("Research the latest developments in quantum computing and create a report")
The future is multi-agent. Build systems, not just agents. 🤝