Overview
Swarms ships a set of lightweight communication topologies. Each one takesAgent objects and a task (or a task list), drives the agents through a fixed message-passing pattern, and returns the conversation history in the format output_type selects.
There is no orchestration object to configure. Reach for these when you want a one-off interaction pattern, or when you want to test whether the shape of the conversation changes the result.
The topologies live in four modules. Every name below is exported from the top-level swarms package.
one_to_one and broadcast no longer live in swarming_architectures.py, and the old various_alt_swarms.py module is gone. Import every name from swarms. from swarms.structs.swarming_architectures import broadcast now raises ImportError. star_swarm, mesh_swarm and pyramid_swarm were removed; use AgentRearrange with a flow such as "Hub -> A, B" when one agent should answer first, and run_agents_with_different_tasks to spread tasks over a pool of agents.
The classes are thin wrappers around the functions. They hold the agents and the output format, so you can run the same group on many tasks.
Installation
What each agent sees
Every call starts a fresh sharedConversation and returns its history. The topologies differ in what each agent reads.
- Reads the shared conversation: every agent in
circular_swarm,one_to_one,broadcastandone_to_three. The agent receives the conversation as typed chat turns: its own messages asassistantturns, everyone else’s asuserturns labelled with the speaker’s name. Its final answer, not its whole transcript, is recorded under itsagent_name. - Gets only its task: every agent in
grid_swarm. These callagent.run(task)and record whatever it returns.
Return shape
All topologies pass the conversation throughhistory_output_formatter with your output_type. The default is "dict".
The conversation history as a list of message dicts, oldest first:
[{"role": "User", "content": task}, {"role": "Writer", "content": "..."}, ...]. Each agent’s turn uses its agent_name as the role. Despite the name, this is a list, so iterate it directly."list", "json", "yaml", "all", "dict-all-except-first", "str-all-except-first", "dict-final" and "list-final".
circular_swarm()
For each task, the task is posted once as aUser message, then every agent answers it in order on the shared conversation. Later agents see what earlier agents said, and the conversation carries over from one task to the next.
ValueError if tasks is empty or the flattened agent list is empty. An empty agents list fails with IndexError before that check.
grid_swarm()
Places agents in a square grid of sideint(sqrt(len(agents))) and assigns tasks to cells row by row. Each agent runs only its own task.
len(agents) is a perfect square and len(tasks) matches the cell count. Agents beyond the square are idle, and tasks beyond the cell count are not processed.
one_to_one()
Two-agent exchange. The task is posted as aUser message, then the sender answers and the receiver replies to the sender. The pair repeats this max_loops times on the same conversation, so each agent can tell its own earlier messages from the other agent’s.
ValueError if sender, receiver, or task is empty.
OneToOne
A reusable wrapper aroundone_to_one() that holds the pair and the output format.
Constructor
run()
one_to_one() with the stored agents and output_type. max_loops is passed per call, not set on the instance.
broadcast()
One-to-many. The task is posted as aUser message and the sender answers it. Then each receiver, in list order, reads the shared conversation and replies.
ValueError if sender, agents, or task is empty.
Broadcast
A reusable wrapper around the same logic asbroadcast(). Unlike the function, Broadcast.run is synchronous, so you call it without await.
Constructor
The receivers, as a flat list or a list of lists. Flattened at construction and stored as
self.receivers.run()
ValueError if task is empty or there are no receivers.
The receivers argument is named
agents on the broadcast() function and receivers on the Broadcast class.one_to_three()
The same flow asbroadcast(), fixed to exactly three receivers and synchronous. The task is posted as a User message, the sender answers, then each of the three receivers replies in turn on the shared conversation.
ValueError if there are not exactly three receivers, or if sender or task is empty.
OneToThree
A reusable wrapper aroundone_to_three().
Constructor
Exactly three receiving agents. Checked at construction; any other count raises
ValueError.run()
one_to_three() with the stored agents and output_type.
Usage examples
Circular: every agent reviews every document
OneToOne: writer and editor
one_to_one: generator and critic, final answer only
Broadcast: one announcement, departmental replies
broadcast: the async function
OneToThree: a pitch to three investors
examples/multi_agent/one_to_one_examples, broadcast_examples and one_to_three_examples.
Choosing a topology
For richer orchestration (planning, voting, hierarchies) see SwarmRouter, HierarchicalSwarm, or MajorityVoting. For side-by-side snippets of every pattern, see Social swarm patterns.