Skip to main content

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:
On each wake, the Lead receives the full team status (agents, tasks, budget) and chooses one or more actions.

Lifecycle Overview

  1. Initial Planning — The Lead receives the user query and creates an initial set of tasks with optional dependency chains
  2. Agent Spawning — The Lead spawns agents and assigns tasks, respecting dependency order
  3. Event-Driven Coordination — As agents complete work, report idle, or hit checkpoints, the Lead dynamically reassigns tasks, revises the plan, or spawns new agents
  4. Synthesis — When all tasks are complete, the Lead can spawn a dedicated synthesis agent or declare done to produce the final response

Task Dependencies (DAG)

Tasks can declare dependencies on other tasks, forming a directed acyclic graph (DAG):
The system enforces dependency order — 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 include request, 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:
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.
URL metadata (title, summary, key facts) is shared across all agents in the team. When Agent B tries to fetch a URL that Agent A already processed, it receives the cached metadata instead of re-fetching — saving both time and tokens.
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:
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.
If 3 consecutive permanent tool errors occur (not transient errors like rate limits), the agent aborts and reports the failure.
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.
Transient errors (rate limits, timeouts, 503s) trigger automatic retry with escalating backoff (5s increments, max 30s) and do not count toward the abort threshold.

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 via config/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