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.
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, plus the hub instar_swarm. 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,mesh_swarmandpyramid_swarm, plus the non-hub agents instar_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".
List[Dict[str, Any]]
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.str
The history as one string,
"role: content" blocks separated by blank lines.str
The content of the last message only.
"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.
AgentListType
required
A flat list of
Agent instances, or a list of lists (flattened one level).List[str]
required
Tasks processed in order. Every agent answers every task.
OutputType
default:"\"dict\""
Format for the returned conversation history.
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.
star_swarm()
agents[0] is the hub. For each task, the task is posted as a User message and the hub answers it on the shared conversation. Every other agent then runs the same task on its own; it does not see the hub’s answer.
ValueError if agents or tasks is empty.
mesh_swarm()
Posts the full task list as oneUser message, copies it into a FIFO queue, then loops over agents, each taking the next task off the front of the queue, until the queue is empty. Despite the name, assignment is deterministic, not random. Your tasks list is not modified.
ValueError if agents or tasks is empty.
pyramid_swarm()
Arranges agents into triangular levels (leveli holds i + 1 agents) and assigns tasks to each cell, level by level. Each agent runs only its own task. No User message is posted, so the history holds only agent turns.
len(agents) is a triangular number (1, 3, 6, 10, …) and len(tasks) matches. Extra agents are idle; extra tasks are not processed.
Raises: ValueError if agents or tasks is empty.
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.
Agent
required
The agent that speaks first in each exchange.
Agent
required
The agent that replies to the sender.
str
required
The task posted at the start of the conversation.
int
default:"1"
Number of sender-then-receiver exchanges.
OutputType
default:"\"dict\""
Format for the returned conversation history.
ValueError if sender, receiver, or task is empty.
OneToOne
A reusable wrapper aroundone_to_one() that holds the pair and the output format.
Constructor
Agent
required
The agent that speaks first.
Agent
required
The agent that replies.
str
default:"\"OneToOne\""
Name of the pattern.
str
Description of the pattern’s purpose.
OutputType
default:"\"dict\""
Format for the returned conversation history.
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.
Agent
required
The agent that speaks first.
AgentListType
required
The receivers, as a flat list or a list of lists (flattened one level).
str
required
The task posted at the start of the conversation.
OutputType
default:"\"dict\""
Format for the returned conversation history.
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
Agent
required
The agent that speaks first.
AgentListType
required
The receivers, as a flat list or a list of lists. Flattened at construction and stored as
self.receivers.str
default:"\"Broadcast\""
Name of the pattern.
str
Description of the pattern’s purpose.
OutputType
default:"\"dict\""
Format for the returned conversation history.
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.
Agent
required
The agent that speaks first.
AgentListType
required
Exactly three receiving agents.
str
required
The task posted at the start of the conversation.
OutputType
default:"\"dict\""
Format for the returned conversation history.
ValueError if there are not exactly three receivers, or if sender or task is empty.
OneToThree
A reusable wrapper aroundone_to_three().
Constructor
Agent
required
The agent that speaks first.
AgentListType
required
Exactly three receiving agents. Checked at construction; any other count raises
ValueError.str
default:"\"OneToThree\""
Name of the pattern.
str
Description of the pattern’s purpose.
OutputType
default:"\"dict\""
Format for the returned conversation history.
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.