Multi-Agent Swarms
AgentOS swarms enable multiple agents to work together on complex tasks through decentralized coordination. Unlike hierarchical systems, swarms use consensus-based decision making where agents observe, propose, vote, and converge on solutions.Overview
Swarms are implemented insrc/swarm.ts:1 and provide four key capabilities:
- Decentralized coordination with up to 20 agents per swarm
- Consensus-based decisions using configurable voting thresholds (default: 66%)
- Message-based communication with observations, proposals, and votes
- Automatic archival to agent memory when swarms dissolve
Creating a Swarm
Agents broadcast messages to the swarm
Each agent can share observations, make proposals, or cast votes:
Swarm Strategies
While the core swarm implementation focuses on consensus, you can implement different coordination strategies:Parallel
All agents work simultaneously on different aspects of the problem. Best for independent subtasks.
Sequential
Agents take turns, each building on the previous agent’s work. Best for dependent tasks.
Consensus
Agents vote on proposals until reaching agreement threshold. Built into the swarm system.
Hierarchical
One agent coordinates others. Combine with the hierarchy system for org-chart-based coordination.
Real-World Example: Code Review
Swarm Limits
Fromsrc/swarm.ts:32:
- MAX_AGENTS_PER_SWARM: 20 agents
- MAX_MESSAGES_PER_SWARM: 500 messages
- DEFAULT_MAX_DURATION_MS: 600,000ms (10 minutes)
- DEFAULT_CONSENSUS_THRESHOLD: 0.66 (66% agreement)
HTTP API Endpoints
Security & Auditing
All swarm operations are automatically audited (seesrc/swarm.ts:80-83):
- swarm_created: Logged with swarmId, goal, and agent count
- swarm_dissolved: Logged with final message count
- Agent membership: Validated before broadcasting messages
Memory Integration
When a swarm dissolves (src/swarm.ts:269-280), findings are automatically stored in each agent’s memory:
Best Practices
Choose the right consensus threshold
Choose the right consensus threshold
- 1.0 (100%): Use for critical decisions (deployments, security approvals)
- 0.66 (66%): Default, good for most collaborative tasks
- 0.5 (50%): Majority rule for faster iteration
Limit swarm size
Limit swarm size
Smaller swarms (3-5 agents) converge faster. Use hierarchical coordination for larger teams.
Set appropriate timeouts
Set appropriate timeouts
Match
maxDurationMs to task complexity. Long-running research might need 30+ minutes.Monitor message volume
Monitor message volume
Watch for chatty agents approaching the 500-message limit. Consider breaking into multiple swarms.
Related Features
- Knowledge Graph - Structure findings from swarm research
- Session Replay - Debug swarm coordination issues
- A2A Protocol - Connect swarms across different AgentOS instances