AI Starter Package
Advanced

Building Agent Swarms

Multiple agents working in parallel can compress hours of work into minutes. This guide covers architecture patterns, communication, and real-world examples.

What Are Agent Swarms?

An agent swarm is a group of AI agents working on the same goal in parallel or in a coordinated sequence. Each agent has a defined role, its own context window, and produces structured output that other agents can consume.

The key benefit is parallelism. A code review that takes one agent 90 seconds can be done in 30 seconds by three agents reviewing in parallel — security, logic, and test coverage simultaneously.

Use a swarm when...

  • • The task has parallel-safe subtasks
  • • Different subtasks need different expertise
  • • Speed matters and tasks are independent
  • • You want multiple perspectives on the same input

Use a single agent when...

  • • Tasks are strictly sequential
  • • State must be shared and mutable
  • • Token cost is the primary constraint
  • • Simplicity and debuggability outweigh speed

Architecture Patterns

Hub and Spoke

One orchestrator agent delegates to specialist sub-agents and aggregates results. Best for sequential pipelines with clear ownership.

Pros: Simple to debug, clear accountability, easy to add new spokes
Cons: Orchestrator becomes a bottleneck; single point of failure

Peer-to-Peer

Agents communicate directly with each other via a shared message bus or shared file. No single coordinator.

Pros: Resilient, agents can start in any order, parallelism is natural
Cons: Harder to trace execution, requires conflict resolution for shared resources

Hierarchical

Agents form a tree. Top-level agents decompose goals and hand off to teams of sub-agents, each of which may delegate further.

Pros: Scales to large problems, mirrors how human teams work
Cons: Deep hierarchies add latency; co-ordination overhead grows with depth

Defining Agent Roles

Every agent in a swarm should have one clearly defined role. Overlap leads to conflicting outputs and wasted tokens.

RoleResponsibility
OrchestratorDecomposes the goal, assigns tasks, aggregates outputs
SpecialistDeep expertise in one domain; produces structured output
ValidatorChecks outputs from other agents for correctness or policy compliance
AggregatorMerges parallel outputs into a coherent result
MonitorWatches for failures, timeouts, or unexpected outputs; triggers retries

Inter-Agent Communication

Agents communicate through structured outputs written to shared files. The simplest and most debuggable pattern is a shared JSON or markdown file in the workspace:

# Shared coordination file: .claude/swarm/review-results.json
{
  "pr_number": 142,
  "status": "in_progress",
  "agents": {
    "typescript_reviewer": { "status": "done", "issues": 2 },
    "security_reviewer": { "status": "running", "issues": null },
    "test_coverage": { "status": "done", "coverage": 84 }
  },
  "aggregate_ready": false
}

The orchestrator polls this file. When all agents have written their results, it reads all outputs and synthesises the final review. No message queues, no network calls — just files.

Real-World Examples

Code Review Swarm

TypeScript ReviewerSecurity ReviewerTest Coverage CheckerDocs Updater

On every PR, four agents review in parallel. Results are merged by an orchestrator into a single review comment.

Research Swarm

Web SearcherPaper SummariserFact CheckerReport Writer

Searcher and Summariser run in parallel. Fact Checker validates claims. Report Writer synthesises the final output.

Deployment Swarm

Build VerifierE2E RunnerSecurity ScannerRelease Note Writer

All four run in parallel after a merge to main. Deployment only proceeds if all agents return green.

Get a Pre-Built Swarm Setup

The AI Starter Package includes a 12-agent configuration with orchestration, inter-agent communication, and parallel execution pre-wired.

View Pricing