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 DAGs —
SequentialWorkflow,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 selectors —
SwarmRouter,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 delegation —
HierarchicalSwarm,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 consensus —
MixtureOfAgents,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 discussion —
GroupChat,ForestSwarm,AdvisorSwarm, plus the named-ritual templates inmulti_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
*Swarmfamily invarious_alt_swarms.py(CircularSwarm,MeshSwarm,FibonacciSwarm,SigmoidSwarm, etc.) and the matching functional helpers inswarming_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-construction —
PlannerGeneratorEvaluator,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;SocialAlgorithmslets you upload an entirely custom communication protocol over a fixed agent set.
- 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 inMixtureOfAgentsorGroupChat. The structure doesn’t care; LiteLLM normalizes the calls. SwarmRouteris the meta-entry point. If you’re not sure which structure to commit to, instantiate one and changeswarm_type=later — you don’t have to rewrite the orchestration code.- 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.
Catalog
| Name | Description | Source |
|---|---|---|
SequentialWorkflow | Runs agents one after another; each step receives the previous output as context. | sequential_workflow.py |
ConcurrentWorkflow | Fires every agent in parallel on the same task; returns a per-agent result map. | concurrent_workflow.py |
AgentRearrange | DSL-driven flow ("A -> B, C -> D") mixing sequential and concurrent steps with optional human-in-the-loop. | agent_rearrange.py |
SwarmRearrange | Same DSL as AgentRearrange but the nodes are whole swarms instead of single agents. | swarm_rearrange.py |
GraphWorkflow | Full DAG executor with topological sort, per-node callbacks, and token streaming. | graph_workflow.py |
BatchedGridWorkflow | Runs an agent×task grid of batched executions. | batched_grid_workflow.py |
SpreadSheetSwarm | Treats a spreadsheet as the task table; each row becomes a concurrent agent run. | spreadsheet_swarm.py |
SwarmRouter | Single entry point that dispatches to any supported swarm type by name. | swarm_router.py |
MultiAgentRouter | LLM-driven “boss” routes a task to one or many specialist agents by capability. | multi_agent_router.py |
AgentRouter | Embedding-based router: matches a task to the best agent via cosine similarity over descriptions. | agent_router.py |
ModelRouter | Routes a task to the best model (not agent) given task requirements. | model_router.py |
SkillOrchestra | Skill-aware orchestration — picks agents by declared skills and cost. | skill_orchestra.py |
HierarchicalSwarm | Director 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 |
HybridHierarchicalClusterSwarm | Hierarchy routes to clusters; inside clusters agents communicate peer-to-peer. | hybrid_hiearchical_peer_swarm.py |
PlannerWorkerSwarm | Planner emits a task queue; a worker pool claims and executes tasks concurrently. | planner_worker_swarm.py |
MixtureOfAgents | N workers respond in parallel for L layers; aggregator synthesizes the final answer. | mixture_of_agents.py |
SelfMoASeq | Sequential self-MoA: many samples from one strong model, sliding-window aggregation. | self_moa_seq.py |
HeavySwarm | Decomposes a problem into specialized questions, runs each through deep multi-loop agents. | heavy_swarm.py |
MajorityVoting | Agents vote; consensus agent synthesizes / breaks ties across loops. | majority_voting.py |
CouncilAsAJudge | Council evaluates a response across multiple dimensions; ranks/scores outputs. | council_as_judge.py |
LLMCouncil | Independent expert agents respond, peer-review each other, then synthesize. | llm_council.py |
DebateWithJudge | Adversarial debate rounds followed by a judge ruling; supports self-refinement. | debate_with_judge.py |
GroupChat | Round-table chat with pluggable speaker-selection (round-robin, expertise, random, priority, dynamic). | groupchat.py |
ForestSwarm | A forest of Trees of TreeAgents; routes tasks to the best matching tree leaf. | tree_swarm.py |
AdvisorSwarm | Cheap executor + powerful advisor consulted on-demand between turns. | advisor_swarm.py |
PlannerGeneratorEvaluator | Three-agent harness: Planner emits step contracts, Generator produces, Evaluator scores. | planner_generator_evaluator.py |
RoundRobinSwarm | True round-robin distribution with optional turn awareness between agents. | round_robin.py |
AutoSwarmBuilder | Takes a high-level description and auto-generates agents, roles, and swarm structure. | auto_swarm_builder.py |
SocialAlgorithms | Framework for uploading user-defined communication algorithms over a fixed agent set. | social_algorithms.py |
CircularSwarm | Agents pass tasks around a ring. | various_alt_swarms.py |
StarSwarm | One central agent processes; others orbit. | various_alt_swarms.py |
MeshSwarm | Agents pull tasks from a shared queue at random. | various_alt_swarms.py |
PyramidSwarm | Agents arranged in a pyramid; tasks flow top-down. | various_alt_swarms.py |
FibonacciSwarm | Tasks land on Fibonacci-indexed agents. | various_alt_swarms.py |
PrimeSwarm | Prime-indexed agents handle the work. | various_alt_swarms.py |
PowerSwarm | Power-of-two-indexed agents handle the work. | various_alt_swarms.py |
LogSwarm | Logarithmic spacing of active agents. | various_alt_swarms.py |
ExponentialSwarm | Exponential spacing of active agents. | various_alt_swarms.py |
GeometricSwarm | Geometric progression of active agents. | various_alt_swarms.py |
HarmonicSwarm | Harmonically spaced active agents. | various_alt_swarms.py |
StaircaseSwarm | Staircase-pattern indices process the task. | various_alt_swarms.py |
SigmoidSwarm | Sigmoid-distributed agent activations. | various_alt_swarms.py |
SinusoidalSwarm | Sinusoidal agent activations. | various_alt_swarms.py |
Broadcast | One sender broadcasts to many receivers. | various_alt_swarms.py |
OneToOne | Pair-wise direct communication between two agents. | various_alt_swarms.py |
OneToThree | One sender hands off to exactly three receivers. | various_alt_swarms.py |
OneOnOneDebate | Turn-based debate between two agents for N loops. | multi_agent_debates.py |
RoundTableDiscussion | Each participant speaks in order; cycle repeats. | multi_agent_debates.py |
ExpertPanelDiscussion | Moderator-guided panel of expert agents. | multi_agent_debates.py |
InterviewSeries | Structured interview with follow-up questions. | multi_agent_debates.py |
PeerReviewProcess | Academic peer review with reviewers + author rebuttals. | multi_agent_debates.py |
MediationSession | Mediator resolves conflict between two or more parties. | multi_agent_debates.py |
NegotiationSession | Multi-party negotiation toward agreement. | multi_agent_debates.py |
BrainstormingSession | Participants build on each other’s ideas. | multi_agent_debates.py |
CouncilMeeting | Structured council discussion + decision-making. | multi_agent_debates.py |
MentorshipSession | Structured mentor / mentee learning and feedback. | multi_agent_debates.py |
TrialSimulation | Legal trial with structured phases and roles. | multi_agent_debates.py |
circular_swarm | Functional (agents, tasks) circular topology. | swarming_architectures.py |
grid_swarm | Functional agent×task grid execution. | swarming_architectures.py |
star_swarm | Functional star topology — central hub, peripheral workers. | swarming_architectures.py |
mesh_swarm | Functional mesh topology — random task pull. | swarming_architectures.py |
pyramid_swarm | Functional pyramid topology — top-down task flow. | swarming_architectures.py |
one_to_one | Functional direct send/reply between two agents. | swarming_architectures.py |
broadcast | Functional 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:- Start with the simplest structure that could plausibly work. A
SequentialWorkfloworConcurrentWorkflowis usually enough for a first pass and forces you to confirm the underlying agents are doing their jobs before you add coordination overhead. - Reach for
SwarmRouterwhen prototyping. Swappingswarm_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. - Escalate to a heavier pattern only when you can name the failure it fixes. Adding
CouncilAsAJudgebecause 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. - Treat the topology swarms in
various_alt_swarms.pyandswarming_architectures.pyas 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?” - Reach for
SocialAlgorithmsorAutoSwarmBuilderonly 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.
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.