Skip to main content

Overview

swarms.structs.swarming_architectures is a set of lightweight functions implementing common message-passing topologies between agents. Each function takes a list of Agent objects, a task or task list, and an output_type, then drives the agents through the topology and returns a formatted conversation history. These are functional building blocks — no shared class, no orchestration object. Reach for them when you want a one-off interaction pattern without instantiating a full swarm class. All seven functions are exported from the top-level swarms package. All functions return whatever shape output_type selects via history_output_formatter"dict" (default), "list", "str", etc.

Installation

circular_swarm()

Every agent runs every task, in order. Each agent sees the running conversation context.
AgentListType
required
Flat list of Agent instances (or list-of-lists; the function flattens once).
List[str]
required
Tasks processed sequentially. Each agent runs each task.
OutputType
default:"\"dict\""
Format for the returned conversation history.
Raises: ValueError if agents or tasks is empty.

grid_swarm()

Place agents in a √N×√N grid, pop tasks one by one, assign to cells row-by-row.
Best when len(agents) is a perfect square and len(tasks) matches the cell count. Extra tasks are dropped; extra agents are idle.

star_swarm()

agents[0] acts as the central agent: it processes each task first (seeing the running conversation), then every other agent processes the same task independently.
Raises: ValueError if agents or tasks is empty.

mesh_swarm()

All tasks are pushed onto a shared FIFO queue. Agents repeatedly loop over the agents list, each popping the next task off the front of the queue, until the queue is empty. (Despite the name, task assignment is deterministic FIFO order, not randomized.)
Raises: ValueError if agents or tasks is empty.

pyramid_swarm()

Agents are arranged into triangular levels (level i holds i + 1 agents), and tasks are popped one at a time and assigned to each cell in the pyramid, level by level.
Best when len(agents) is a triangular number (1, 3, 6, 10, …) and len(tasks) matches the cell count. Extra tasks are dropped; extra agents are idle. Raises: ValueError if agents or tasks is empty.

one_to_one()

Two-agent handoff: sender processes the task, receiver processes the sender’s output, repeat for max_loops.
Agent
required
Agent that processes the task first each loop.
Agent
required
Agent that processes the sender’s output.
str
required
Task for the sender on the first turn.
int
default:"1"
Number of sender→receiver round trips.

broadcast()

Async function. One sender produces a message based on the conversation context; every agent in agents then processes the sender’s broadcast independently.
Must be awaited:
Raises: ValueError if sender, agents, or task is empty.

Usage Examples

Circular: Every Agent Reviews Every Document

Each reviewer sees the running conversation, so later reviewers can build on earlier comments.

One-to-One: Generator/Critic Loop

Broadcast: Notify a Pool of Workers

Choosing a Topology

For richer orchestration (planning, voting, hierarchies) see SwarmRouter, HierarchicalSwarm, or MajorityVoting.

Source Code

View the source on GitHub.