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:
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
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.
tasks.
Usage Examples
Basic round-robin execution
Multiple loops
Different output types
Batch processing
How It Works
- Opening message — the user task is added to the conversation as the first
Usermessage. - Deterministic schedule — for
max_loopsloops, the swarm iteratesagentsin insertion order: turntgoes toagents[t % N]. - Full context — before each turn, the current full transcript is read and passed to the agent.
- Role header — a per-turn header (see below) tells the agent its position, loop, previous/next speaker, and peers.
- 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.
- 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 bybuild_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 processing —
run_batchruns many tasks, one full cycle each. - Serializable — inherits
SerializableMixinfor config serialization.
Best Practices
- Order matters — place agents in the sequence you want them to speak; the opener sets the framing for everyone after.
- Agent diversity — use complementary roles so each turn adds a distinct perspective.
- Loop count — start with
max_loops=1; increase only when deeper back-and-forth is needed (cost scales withN * max_loops). - Output type — use
"final"for a single answer,"list"/"dict"to inspect the whole collaboration. - Verbose mode — enable
verbose=Truewhile debugging to trace each turn.