Swarm Multi-Agent Workflow
This tutorial shows how to use Shannon’s SwarmWorkflow to deploy persistent, collaborating agents that work in parallel with inter-agent messaging and a shared workspace.What You’ll Learn
- How to submit a swarm task via API and Python SDK
- How agents decompose, execute, and synthesize results
- How to monitor agent progress with SSE streaming
- How to configure swarm parameters
- Real-world use cases and best practices
Prerequisites
- Shannon stack running (Docker Compose)
- Gateway reachable at
http://localhost:8080 - Swarm enabled in
config/features.yaml(enabled by default) - Auth defaults:
- Docker Compose: authentication is disabled by default (
GATEWAY_SKIP_AUTH=1). - Local builds: authentication is enabled by default. Set
GATEWAY_SKIP_AUTH=1to disable auth, or include an API key header-H "X-API-Key: $API_KEY".
- Docker Compose: authentication is disabled by default (
Quick Start
curl -X POST http://localhost:8080/api/v1/tasks \
-H "Content-Type: application/json" \
-d '{
"query": "Compare AI chip markets across US, Japan, and South Korea",
"session_id": "swarm-demo-001",
"context": {
"force_swarm": true
}
}'
{
"task_id": "task-abc123...",
"status": "STATUS_CODE_OK",
"message": "Task submitted successfully",
"created_at": "2025-11-10T10:00:00Z"
}
data: {"type":"WORKFLOW_STARTED","agent_id":"swarm-supervisor","message":"Assigning a team of agents"}
data: {"type":"PROGRESS","agent_id":"swarm-supervisor","message":"Planning approach"}
data: {"type":"PROGRESS","agent_id":"swarm-supervisor","message":"Assigning 3 agents"}
data: {"type":"AGENT_STARTED","agent_id":"takao","message":"Agent takao started"}
data: {"type":"AGENT_STARTED","agent_id":"mitaka","message":"Agent mitaka started"}
data: {"type":"AGENT_STARTED","agent_id":"kichijoji","message":"Agent kichijoji started"}
data: {"type":"PROGRESS","agent_id":"takao","message":"Agent takao progress: iteration 1/25, action: tool_call"}
data: {"type":"AGENT_COMPLETED","agent_id":"takao","message":"Agent takao completed"}
data: {"type":"AGENT_COMPLETED","agent_id":"mitaka","message":"Agent mitaka completed"}
data: {"type":"AGENT_COMPLETED","agent_id":"kichijoji","message":"Agent kichijoji completed"}
data: {"type":"PROGRESS","agent_id":"swarm-supervisor","message":"Combining findings from 3 agents"}
data: {"type":"WORKFLOW_COMPLETED","agent_id":"swarm-supervisor","message":"All done"}
{
"task_id": "task-abc123...",
"status": "TASK_STATUS_COMPLETED",
"result": "## AI Chip Market Comparison\n\n### United States\nThe US market is dominated by NVIDIA...\n\n### Japan\nJapan focuses on edge AI...\n\n### South Korea\nSouth Korea leverages Samsung...",
"metadata": {
"workflow_type": "swarm",
"total_agents": 3,
"agents": [
{"agent_id": "takao", "iterations": 8, "tokens": 12400, "success": true, "model": "gpt-5-mini-2025-08-07"},
{"agent_id": "mitaka", "iterations": 6, "tokens": 9800, "success": true, "model": "gpt-5-mini-2025-08-07"},
{"agent_id": "kichijoji", "iterations": 7, "tokens": 11200, "success": true, "model": "gpt-5-mini-2025-08-07"}
]
}
}
Submit + Stream in One Call
For frontend applications, use the combined submit-and-stream endpoint:Python SDK
Basic Usage
With Streaming
With Custom Context
How Agents Collaborate
Team Roster
Each agent receives a team roster showing all agents and their assignments. This enables agents to know who to contact for specific information:Publishing Findings
Agents share discoveries via the shared workspace. These appear in every agent’s prompt context:Sending Direct Messages
Agents can send direct messages to specific teammates:Requesting Help
When an agent needs additional support, it requests help from the supervisor:Configuration
features.yaml
Configuration Parameters
| Parameter | Default | Range | Description |
|---|---|---|---|
enabled | true | true/false | Enable or disable swarm workflows |
max_agents | 10 | 1-50 | Total agent cap including dynamically spawned helpers |
max_iterations_per_agent | 25 | 1-100 | Maximum reason-act cycles per agent |
agent_timeout_seconds | 600 | 60-3600 | Per-agent wall-clock timeout |
max_messages_per_agent | 20 | 1-100 | Cap on P2P messages an agent can send |
workspace_snippet_chars | 800 | 100-4000 | Truncation limit for workspace entries in agent prompt |
workspace_max_entries | 5 | 1-20 | Number of recent workspace entries shown per topic |
Real-World Use Cases
Market Research
Assign agents to research different markets or competitors in parallel, then synthesize into a unified report.
Technical Comparison
Each agent evaluates a different framework, library, or architecture, sharing findings as they discover them.
Multi-Region Analysis
Agents research different geographic regions simultaneously with cross-pollination of findings.
Literature Review
Agents explore different facets of a research topic, sharing sources and key findings via the workspace.
Example: Technical Framework Comparison
Example: Comprehensive Industry Analysis
Understanding the Response Metadata
The swarm workflow returns metadata with per-agent details:| Field | Description |
|---|---|
workflow_type | Always "swarm" for swarm workflows |
total_agents | Number of agents that participated |
agents[].agent_id | Unique agent name |
agents[].iterations | Number of reason-act cycles completed |
agents[].tokens | Total tokens consumed by this agent |
agents[].success | Whether the agent completed successfully |
agents[].model | LLM model used by this agent |
Tips and Best Practices
- Getting Started
- Performance
- When Not to Use Swarm
- Set
context.force_swarm: trueto route to SwarmWorkflow - Start with default configuration and adjust based on results
- Monitor SSE events to understand agent behavior
- Use sessions (
session_id) for multi-turn swarm conversations
Troubleshooting
Fallback Behavior
If the swarm workflow fails (decomposition error, all agents fail, etc.), Shannon automatically falls back to standard DAG/Supervisor workflow routing. Theforce_swarm flag is removed from context to prevent recursive failures.