Multi-Agent Swarms
Multiple specialized agents collaborate on complex tasks.
Overview
Multi-agent swarms enable multiple AI agents with different specializations to collaborate on solving complex problems.
Key benefits:
- Better quality on complex tasks
- Multiple perspectives on problems
- Consensus-based decisions
- Dynamic role assignment
How It Works
- Role assignment: System assigns roles (researcher, engineer, critic, synthesizer)
- Parallel execution: Each agent works on the problem from their perspective
- Contribution collection: All agent outputs are gathered
- Synthesis: Final agent combines insights into unified answer
Default roles:
- Researcher: Gathers facts, constraints, edge cases
- Engineer: Proposes implementation plans
- Critic: Identifies flaws and missing requirements
- Synthesizer: Combines inputs into final answer
Configuration
{
swarm: {
enabled: true,
size: 4, // Number of agents
dynamic_roles: true, // Auto-assign roles based on task
max_concurrent: 4,
agent_timeout_ms: 30000,
consensus_candidates: 3 // For high-stakes decisions
}
}
Usage
Enable swarm mode:
curl -X POST http://localhost:8080/v1/chat/completions \
-d '{
"model": "phi3",
"mode": "swarm",
"messages": [{"role": "user", "content": "Design a REST API for a blog"}]
}'
Response Structure
{
"choices": [{
"message": {
"content": "Final synthesized answer..."
}
}],
"swarm_metadata": {
"agents_used": 4,
"roles": ["researcher", "engineer", "critic", "synthesizer"],
"contributions": [
{"role": "researcher", "summary": "Identified key entities..."},
{"role": "engineer", "summary": "Proposed REST endpoints..."},
{"role": "critic", "summary": "Noted missing auth..."},
{"role": "synthesizer", "summary": "Combined insights..."}
]
}
}
Dynamic Role Assignment
When dynamic_roles: true, the system analyzes the task and assigns appropriate roles:
Example: Code review task
- Code analyzer
- Security auditor
- Performance reviewer
- Documentation checker
Example: Research task
- Data gatherer
- Fact checker
- Summarizer
- Citation manager
Consensus Mode
For critical decisions, use consensus voting:
{
swarm: {
consensus_candidates: 3 // Generate 3 candidate answers
}
}
Multiple synthesizers vote on the best answer.
Use Cases
- System design: Multiple architectural perspectives
- Code review: Security, performance, style, documentation
- Research: Comprehensive information gathering
- Decision making: Consensus on important choices
Performance
- Latency: 3-5x single agent (parallel execution)
- Quality: 20-40% improvement on complex tasks
- Token usage: N x base usage (N = number of agents)