What is Swarm Mode?
Swarm mode deploys multiple persistent, autonomous agents that work in parallel to solve complex tasks. An LLM-powered Lead Agent dynamically coordinates the team — planning tasks, spawning agents, reassigning work, and making decisions based on real-time events. Unlike static orchestration where tasks are pre-decomposed and never change, the Lead Agent continuously monitors progress and adapts: creating new tasks, canceling redundant work, and reassigning idle agents as the situation evolves.How It Works
Shannon’s swarm workflow is driven by an event-driven Lead Agent loop:Lead Agent Event Loop
The Lead Agent wakes on specific events and decides what to do next:Lifecycle Overview
- Initial Planning — The Lead receives the user query and creates an initial set of tasks with optional dependency chains
- Agent Spawning — The Lead spawns agents and assigns tasks, respecting dependency order
- Event-Driven Coordination — As agents complete work, report idle, or hit checkpoints, the Lead dynamically reassigns tasks, revises the plan, or spawns new agents
- Synthesis — When all tasks are complete, the Lead can spawn a dedicated synthesis agent or declare
doneto produce the final response
Task Dependencies (DAG)
Tasks can declare dependencies on other tasks, forming a directed acyclic graph (DAG):task-4 cannot be assigned until all three research tasks are complete. The Lead can dynamically create new dependency chains via revise_plan.
Lead Agent Actions
Each time the Lead wakes, it selects one or more actions:Agent Actions
Each iteration, an agent chooses exactly one action:Agents cannot self-exit. When an agent returns
done, it automatically converts to idle status. Only the Lead Agent can terminate agents via shutdown_agent. This ensures the Lead maintains full control over team composition.Inter-Agent Communication
Swarm agents collaborate through two mechanisms:P2P Messaging
Agents send direct messages to specific teammates through Redis-backed mailboxes. Message types includerequest, offer, accept, delegation, and info.
Before each LLM call, the agent’s mailbox is checked for new messages. Incoming messages appear in the agent’s prompt context.
Shared Workspace
Agents publish findings to topic-based workspace lists. Before each iteration, every agent fetches recent workspace entries from all topics, so the entire team stays aware of collective progress.Knowledge Deduplication
Shannon prevents redundant work across agents with three layers of deduplication:L1: Per-Agent URL Fetch Cache
L1: Per-Agent URL Fetch Cache
Each agent caches URLs it has already fetched. If the same URL is requested again within the same agent loop, the cached content is returned without a network call.
L3: Search Overlap Detection
L3: Search Overlap Detection
URLs discovered by search results are tracked across all agents. When a new search returns URLs where 70% or more have already been discovered by other agents, the system injects a warning to find new angles. Additionally, a search saturation detector compares recent queries using Jaccard word-level similarity (threshold 0.7, window of 3 queries) to flag repetitive searches.
Convergence Detection
Three mechanisms prevent agents from running indefinitely:No-Progress Detection
No-Progress Detection
If an agent takes 3 consecutive iterations with no meaningful action (empty or unrecognized actions), it is considered converged and transitions to idle status. Note that
tool_call, send_message, and publish_data all reset this counter.Consecutive Error Abort
Consecutive Error Abort
If 3 consecutive permanent tool errors occur (not transient errors like rate limits), the agent aborts and reports the failure.
Max Iterations Force-Done
Max Iterations Force-Done
On the last iteration, if the agent has not called
done or idle, the workflow forces completion and builds a summary from the most recent iterations.Global Budget Control
Swarm execution is bounded by three budget layers that prevent runaway costs:
The Lead Agent receives budget information (remaining calls, tokens, time) in its context, enabling it to make cost-aware decisions — such as shutting down low-priority agents or skipping optional tasks when budget is tight.
When to Use Swarm vs Other Workflows
Swarm mode uses more tokens than standard workflows because each agent runs multiple LLM iterations and the Lead Agent consumes tokens for coordination decisions. Use it for tasks that genuinely benefit from persistent, collaborative multi-agent execution.
Configuration
Swarm behavior is controlled viaconfig/features.yaml:
Streaming Events
Swarm workflows emit SSE events for real-time monitoring:Next Steps
Swarm Tutorial
Step-by-step guide to running swarm workflows
Workflows & Patterns
Other workflow types and cognitive patterns
Streaming
Real-time event streaming
Cost Control
Budget management for multi-agent tasks