RoundRobinSwarm passes one task around a table of agents. Agents speak in the order you list them, and each one reads everything said so far before it adds its turn. max_loops sets how many times the whole roster goes around, so one run() makes len(agents) * max_loops agent calls. By default run() returns the last agent’s answer.
Reference: RoundRobinSwarm.
1. Draft, critique, edit
A drafter writes, a critic finds weaknesses, and an editor fixes them. The order of theagents list is the speaking order.
output_type="final", final_draft is the Editor’s text as a string. Each run() clears the conversation first, so a reused swarm never carries an earlier task’s transcript.
2. What each agent is told
On its turn, an agent receives the whole conversation so far as chat messages: the task, its own earlier replies, and every other agent’s replies under their names. Above that, the swarm adds a header that says where the agent sits in the order, and an instruction to build on the previous speaker. You can print the header the swarm builds:3. More rounds, and reading the whole transcript
Withmax_loops=2, the roster goes around twice in the same order, so every agent speaks twice. Set output_type="list" to get every message as a {"role", "content"} dict instead of only the last answer. This block reuses the agents from section 1:
output_type values work the same way as in the other structures:
4. Run several tasks
run_batch() runs each task through a full round-robin, one task after another, and returns the results in task order. Each task starts from an empty conversation.
Tips
- Order is the design. The first agent frames the work for everyone after it. Put the agent that should have the last word at the end of the list.
- Watch the cost. Each round calls every agent once, and every turn sends the whole transcript so far. Start with
max_loops=1. - Errors stop the run. If an agent raises,
run()raises the same exception. - Name every agent. Turns are recorded under
agent_name, and the header tells each agent who the others are. - Total usage.
swarm.usagesums the token usage of all the agents.
Next steps
- RoundRobinSwarm reference
- AgentRearrange guide, when some agents should run in parallel
- Runnable scripts