←Back to Docs
Recipe
Multi-Agent Swarm
Orchestrate a swarm of specialized agents that collaborate, debate, and converge on solutions — each with its own persona, tools, and memory.
Overview
A multi-agent swarm distributes reasoning across independent agents that communicate through a shared message bus. Each agent operates with bounded context, reducing hallucination and enabling parallel exploration of solution paths. The swarm converges via consensus or a designated arbiter agent.
Architecture
┌─────────────┐
│ Orchestrator│
└──────┬──────┘
│ spawns
┌──────┴──────────────────────┐
│ Agent A Agent B Agent C│
│ (research) (critic) (write)│
└─────────────────────────────┘
│ message bus
┌──────┴──────┐
│ Arbiter │
└─────────────┘Key Concepts
- Agent Personas — System prompts define each agent's role, tone, and constraints.
- Message Bus — Agents publish structured messages; the orchestrator routes them.
- Convergence — Majority vote, arbiter decision, or iterative refinement loop.
- Tool Access — Each agent gets a scoped toolset; no agent sees everything.
Quick Start
// Define agents
const swarm = new Swarm({
agents: [
{ name: "researcher", model: "gpt-4o", tools: [search] },
{ name: "critic", model: "gpt-4o", tools: [] },
{ name: "writer", model: "gpt-4o", tools: [draft] },
],
strategy: "consensus",
});
// Run
const result = await swarm.run("Analyze Q3 metrics");