Skip to main content

Overview

RoundRobinSwarm visits agents in their declared insertion order, cycling through the full roster once per loop. The schedule is deterministic and identical on every loop:
Every agent reads the full conversation transcript accumulated by the agents that spoke before it, and each agent receives exactly max_loops turns. Before each turn the swarm injects a role header telling the agent its position, the current loop, the previous/next speaker, and the other participants, then asks it to build on the prior contribution.
Earlier versions of RoundRobinSwarm shuffled agents randomly each loop and supported callback / max_retries parameters. Those are removed — the order is now strictly deterministic and those parameters no longer exist.

Installation

Import

The per-turn prompt builders are also importable for inspection or reuse:

Constructor

str
default:"RoundRobinSwarm"
Name of the swarm. Also used to name the internal conversation.
str
Description of the swarm’s purpose.
List[Agent]
required
Agents that take turns in declared order. Required — constructing the swarm without agents raises ValueError.
bool
default:"False"
Enable verbose logging of each turn and loop.
int
default:"1"
Number of full passes over the roster. Each agent speaks exactly once per loop, so with N agents and max_loops loops the swarm runs N * max_loops turns total.
OutputType
default:"final"
Output format applied to the conversation history. Common values: "final" (last message only), "list", "dict", "str", "json".

Methods

run(task, *args, **kwargs)

Execute the task across the agents in deterministic round-robin order. Returns the conversation in the format specified by output_type.
str
required
The task to execute. Posted as the opening User message that the first agent responds to.
*args / **kwargs are forwarded to each underlying agent.run() call. Returns: the task result formatted per output_type. Raises: re-raises any exception thrown by an agent during execution.

run_batch(tasks)

Execute multiple tasks sequentially. Each task runs through its own full round-robin cycle.
List[str]
required
Tasks to execute, one full round-robin run per task.
Returns: a list of results in the same order as tasks.

Usage Examples

Basic round-robin execution

Multiple loops

Different output types

Batch processing

How It Works

  1. Opening message — the user task is added to the conversation as the first User message.
  2. Deterministic schedule — for max_loops loops, the swarm iterates agents in insertion order: turn t goes to agents[t % N].
  3. Full context — before each turn, the current full transcript is read and passed to the agent.
  4. Role header — a per-turn header (see below) tells the agent its position, loop, previous/next speaker, and peers.
  5. Collaborative reply — the agent is asked to build on the prior speaker’s contribution (or address the task directly if it opens), and its response is appended to the transcript.
  6. Formatted output — after all loops complete, the conversation is returned per output_type.

Per-turn prompt

Each agent receives a generated header and a standing instruction, produced by build_turn_header and build_collaborative_task. The running transcript is not concatenated into this prompt string — run() calls build_collaborative_task(conversation_context="", turn_header=turn_header), so the prior-turns transcript is delivered separately to the agent via the messages argument of agent.run(), not as literal text in the task prompt:

Features

  • Deterministic order — agents always speak in declared insertion order, identically every loop.
  • Full context — each agent sees the complete transcript accumulated so far.
  • Collaborative prompting — agents are told their position and neighbors and asked to build on prior turns.
  • Flexible output — choose "final", "list", "dict", "str", or "json".
  • Batch processingrun_batch runs many tasks, one full cycle each.
  • Serializable — inherits SerializableMixin for config serialization.

Best Practices

  1. Order matters — place agents in the sequence you want them to speak; the opener sets the framing for everyone after.
  2. Agent diversity — use complementary roles so each turn adds a distinct perspective.
  3. Loop count — start with max_loops=1; increase only when deeper back-and-forth is needed (cost scales with N * max_loops).
  4. Output type — use "final" for a single answer, "list"/"dict" to inspect the whole collaboration.
  5. Verbose mode — enable verbose=True while debugging to trace each turn.

Source Code

View the source code on GitHub.