Skip to main content

Overview

swarms.structs is the library’s multi-agent orchestration layer. Where the single-agent primitive (Agent) decides what one model does on one turn, the structures in this catalog decide how a population of agents combines into a system that produces a single useful answer. Each structure encodes a different opinion about how that combination should work — who talks to whom, in what order, how disagreement is resolved, and how results are merged. The catalog roughly clusters into a handful of recurring patterns:
  • Pipelines and DAGsSequentialWorkflow, ConcurrentWorkflow, AgentRearrange, SwarmRearrange, GraphWorkflow, BatchedGridWorkflow, SpreadSheetSwarm. These let you describe the topology of execution explicitly, from a flat A→B→C line to a full directed acyclic graph with fan-out/fan-in, callbacks, and streaming. Use these when you already know the shape of the workflow.
  • Routers and selectorsSwarmRouter, MultiAgentRouter, AgentRouter, ModelRouter, SkillOrchestra. These don’t run a fixed plan; they look at the incoming task and pick which agent(s) (or which model) should handle it. The selector itself is either an LLM (“boss”), an embedding match, or a skill-graph lookup. Use these when the input space is broader than any single agent’s competence.
  • Hierarchies and delegationHierarchicalSwarm, HierarchicalStructuredCommunicationFramework, HybridHierarchicalClusterSwarm, PlannerWorkerSwarm. A director or supervisor decomposes the task and delegates pieces to workers, then synthesizes. The variants differ in how strictly the communication protocol is defined and whether the workers themselves can cluster and talk peer-to-peer.
  • Ensembles and consensusMixtureOfAgents, SelfMoASeq, HeavySwarm, MajorityVoting, CouncilAsAJudge, LLMCouncil, DebateWithJudge. The shared assumption is that one model’s first answer is rarely the best answer. These structures sample multiple opinions and combine them — by aggregator synthesis, by vote, by judge ruling, or by structured adversarial debate.
  • Dialogue and discussionGroupChat, ForestSwarm, AdvisorSwarm, plus the named-ritual templates in multi_agent_debates.py (OneOnOneDebate, RoundTableDiscussion, PeerReviewProcess, TrialSimulation, and friends). These run scripted conversational patterns end-to-end so you don’t have to reimplement “moderated panel” or “academic peer review” by hand.
  • Topology experiments — the *Swarm family in various_alt_swarms.py (CircularSwarm, MeshSwarm, FibonacciSwarm, SigmoidSwarm, etc.) and the matching functional helpers in swarming_architectures.py. These exist for research and exploration: what happens if you only activate agents at prime indices? Sinusoidal positions? They’re cheap to try because they share a tiny common interface.
  • Self-improvement and auto-constructionPlannerGeneratorEvaluator, AutoSwarmBuilder, SocialAlgorithms. These build or refine swarms dynamically: a planner negotiates contracts with a generator and evaluator; a builder reads a high-level description and spits out a configured swarm; SocialAlgorithms lets you upload an entirely custom communication protocol over a fixed agent set.
A few practical notes that apply across the whole catalog:
  1. Most structures take a List[Agent]. Mix providers freely — a GPT agent and a Claude agent and a local Llama agent can sit side by side in MixtureOfAgents or GroupChat. The structure doesn’t care; LiteLLM normalizes the calls.
  2. SwarmRouter is the meta-entry point. If you’re not sure which structure to commit to, instantiate one and change swarm_type= later — you don’t have to rewrite the orchestration code.
  3. Topology choice is a lever, not a guess. Sequential is cheapest and most deterministic. Concurrent is fastest end-to-end but loses ordering. Hierarchical pays an extra LLM call to the director in exchange for cleaner delegation. Ensembles pay N× tokens for variance reduction. Pick the trade-off, not the buzzword.
The table below lists every multi-agent structure currently shipped, with a one-line description and a direct link to its source file on GitHub.

Catalog

NameDescriptionSource
SequentialWorkflowRuns agents one after another; each step receives the previous output as context.sequential_workflow.py
ConcurrentWorkflowFires every agent in parallel on the same task; returns a per-agent result map.concurrent_workflow.py
AgentRearrangeDSL-driven flow ("A -> B, C -> D") mixing sequential and concurrent steps with optional human-in-the-loop.agent_rearrange.py
SwarmRearrangeSame DSL as AgentRearrange but the nodes are whole swarms instead of single agents.swarm_rearrange.py
GraphWorkflowFull DAG executor with topological sort, per-node callbacks, and token streaming.graph_workflow.py
BatchedGridWorkflowRuns an agent×task grid of batched executions.batched_grid_workflow.py
SpreadSheetSwarmTreats a spreadsheet as the task table; each row becomes a concurrent agent run.spreadsheet_swarm.py
SwarmRouterSingle entry point that dispatches to any supported swarm type by name.swarm_router.py
MultiAgentRouterLLM-driven “boss” routes a task to one or many specialist agents by capability.multi_agent_router.py
AgentRouterEmbedding-based router: matches a task to the best agent via cosine similarity over descriptions.agent_router.py
ModelRouterRoutes a task to the best model (not agent) given task requirements.model_router.py
SkillOrchestraSkill-aware orchestration — picks agents by declared skills and cost.skill_orchestra.py
HierarchicalSwarmDirector agent decomposes the task and delegates to workers; synthesizes results.hiearchical_swarm.py
HierarchicalStructuredCommunicationFramework”Talk Structurally, Act Hierarchically” — structured messages between supervisor / generator / evaluator / refiner roles.hierarchical_structured_communication_framework.py
HybridHierarchicalClusterSwarmHierarchy routes to clusters; inside clusters agents communicate peer-to-peer.hybrid_hiearchical_peer_swarm.py
PlannerWorkerSwarmPlanner emits a task queue; a worker pool claims and executes tasks concurrently.planner_worker_swarm.py
MixtureOfAgentsN workers respond in parallel for L layers; aggregator synthesizes the final answer.mixture_of_agents.py
SelfMoASeqSequential self-MoA: many samples from one strong model, sliding-window aggregation.self_moa_seq.py
HeavySwarmDecomposes a problem into specialized questions, runs each through deep multi-loop agents.heavy_swarm.py
MajorityVotingAgents vote; consensus agent synthesizes / breaks ties across loops.majority_voting.py
CouncilAsAJudgeCouncil evaluates a response across multiple dimensions; ranks/scores outputs.council_as_judge.py
LLMCouncilIndependent expert agents respond, peer-review each other, then synthesize.llm_council.py
DebateWithJudgeAdversarial debate rounds followed by a judge ruling; supports self-refinement.debate_with_judge.py
GroupChatRound-table chat with pluggable speaker-selection (round-robin, expertise, random, priority, dynamic).groupchat.py
ForestSwarmA forest of Trees of TreeAgents; routes tasks to the best matching tree leaf.tree_swarm.py
AdvisorSwarmCheap executor + powerful advisor consulted on-demand between turns.advisor_swarm.py
PlannerGeneratorEvaluatorThree-agent harness: Planner emits step contracts, Generator produces, Evaluator scores.planner_generator_evaluator.py
RoundRobinSwarmTrue round-robin distribution with optional turn awareness between agents.round_robin.py
AutoSwarmBuilderTakes a high-level description and auto-generates agents, roles, and swarm structure.auto_swarm_builder.py
SocialAlgorithmsFramework for uploading user-defined communication algorithms over a fixed agent set.social_algorithms.py
CircularSwarmAgents pass tasks around a ring.various_alt_swarms.py
StarSwarmOne central agent processes; others orbit.various_alt_swarms.py
MeshSwarmAgents pull tasks from a shared queue at random.various_alt_swarms.py
PyramidSwarmAgents arranged in a pyramid; tasks flow top-down.various_alt_swarms.py
FibonacciSwarmTasks land on Fibonacci-indexed agents.various_alt_swarms.py
PrimeSwarmPrime-indexed agents handle the work.various_alt_swarms.py
PowerSwarmPower-of-two-indexed agents handle the work.various_alt_swarms.py
LogSwarmLogarithmic spacing of active agents.various_alt_swarms.py
ExponentialSwarmExponential spacing of active agents.various_alt_swarms.py
GeometricSwarmGeometric progression of active agents.various_alt_swarms.py
HarmonicSwarmHarmonically spaced active agents.various_alt_swarms.py
StaircaseSwarmStaircase-pattern indices process the task.various_alt_swarms.py
SigmoidSwarmSigmoid-distributed agent activations.various_alt_swarms.py
SinusoidalSwarmSinusoidal agent activations.various_alt_swarms.py
BroadcastOne sender broadcasts to many receivers.various_alt_swarms.py
OneToOnePair-wise direct communication between two agents.various_alt_swarms.py
OneToThreeOne sender hands off to exactly three receivers.various_alt_swarms.py
OneOnOneDebateTurn-based debate between two agents for N loops.multi_agent_debates.py
RoundTableDiscussionEach participant speaks in order; cycle repeats.multi_agent_debates.py
ExpertPanelDiscussionModerator-guided panel of expert agents.multi_agent_debates.py
InterviewSeriesStructured interview with follow-up questions.multi_agent_debates.py
PeerReviewProcessAcademic peer review with reviewers + author rebuttals.multi_agent_debates.py
MediationSessionMediator resolves conflict between two or more parties.multi_agent_debates.py
NegotiationSessionMulti-party negotiation toward agreement.multi_agent_debates.py
BrainstormingSessionParticipants build on each other’s ideas.multi_agent_debates.py
CouncilMeetingStructured council discussion + decision-making.multi_agent_debates.py
MentorshipSessionStructured mentor / mentee learning and feedback.multi_agent_debates.py
TrialSimulationLegal trial with structured phases and roles.multi_agent_debates.py
circular_swarmFunctional (agents, tasks) circular topology.swarming_architectures.py
grid_swarmFunctional agent×task grid execution.swarming_architectures.py
star_swarmFunctional star topology — central hub, peripheral workers.swarming_architectures.py
mesh_swarmFunctional mesh topology — random task pull.swarming_architectures.py
pyramid_swarmFunctional pyramid topology — top-down task flow.swarming_architectures.py
one_to_oneFunctional direct send/reply between two agents.swarming_architectures.py
broadcastFunctional one-sender-to-many-receivers.swarming_architectures.py

Conclusion

The breadth of this catalog is deliberate: there is no single “right” way to compose agents. A linear pipeline beats a hierarchy when the work is well-decomposed. A hierarchy beats a pipeline when the decomposition itself is the hard part. An ensemble beats either when correctness matters more than latency. A debate beats an ensemble when the failure mode is one-sided reasoning rather than random noise. The structures here exist so you can pick the one whose assumptions match your task instead of bending one general-purpose pattern to fit every problem. A pragmatic way to use the catalog:
  1. Start with the simplest structure that could plausibly work. A SequentialWorkflow or ConcurrentWorkflow is usually enough for a first pass and forces you to confirm the underlying agents are doing their jobs before you add coordination overhead.
  2. Reach for SwarmRouter when prototyping. Swapping swarm_type= between "SequentialWorkflow", "MixtureOfAgents", "HierarchicalSwarm", and "MajorityVoting" is a one-line change and a fast way to see which topology actually helps on your task.
  3. Escalate to a heavier pattern only when you can name the failure it fixes. Adding CouncilAsAJudge because the single-agent answers are inconsistent across criteria is a good reason; adding it because “more agents is better” usually just buys variance and cost.
  4. Treat the topology swarms in various_alt_swarms.py and swarming_architectures.py as a research playground. They share a tiny interface, are cheap to try, and are useful when you want to ask empirical questions like “does this task benefit from non-uniform agent activation?”
  5. Reach for SocialAlgorithms or AutoSwarmBuilder only when nothing in the built-in set fits. Most production workloads land cleanly on one of the canonical patterns; reinventing the protocol or auto-generating the swarm is a last resort, not a default.
If you’re adding a new pattern of your own, the convention is straightforward: subclass nothing required, accept a List[Agent] and any structure-specific config, expose .run(task) and (ideally) .batch_run(tasks), and let find_agent_by_name, Conversation, and the helpers in multi_agent_exec handle the boring parts. Drop the new file in swarms/structs/, export it from swarms/structs/__init__.py, and add a row to this table.