> ## Documentation Index
> Fetch the complete documentation index at: https://docs.swarms.world/llms.txt
> Use this file to discover all available pages before exploring further.

# RoundRobinSwarm Guide

> Let agents take turns on one task in a fixed order, each building on the full transcript, over one or more rounds

A `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](https://docs.swarms.world/api/round-robin-swarm.md).

## 1. Draft, critique, edit

A drafter writes, a critic finds weaknesses, and an editor fixes them. The order of the `agents` list is the speaking order.

```python theme={null}
from swarms import Agent, RoundRobinSwarm


def make_agent(name: str, system_prompt: str) -> Agent:
    """Build a one-loop agent on a small model."""
    return Agent(
        agent_name=name,
        system_prompt=system_prompt,
        model_name="gpt-5.4-mini",
        max_loops=1,
    )


drafter = make_agent("Drafter", "You write a first draft of the requested text, under 80 words.")
critic = make_agent("Critic", "You list the two biggest weaknesses of the latest draft.")
editor = make_agent("Editor", "You rewrite the latest draft to fix the critic's points. Return only the new draft.")

swarm = RoundRobinSwarm(
    name="Launch-Copy",
    agents=[drafter, critic, editor],
    max_loops=1,
)

final_draft = swarm.run("Write a launch announcement for a budget e-bike called the Volt One.")
print(final_draft)
```

With the default `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:

```python theme={null}
from swarms.structs.round_robin import build_turn_header

print(
    build_turn_header(
        agent_name="Critic",
        position=2,
        total=3,
        loop=1,
        max_loops=2,
        prev_name="Drafter",
        next_name="Editor",
        agent_names=["Drafter", "Critic", "Editor"],
    )
)
```

```text theme={null}
You are Critic, agent 2 of 3 in loop 1 of 2. Previous speaker: Drafter. Next speaker: Editor. Other participants: Drafter, Editor.
```

Write each agent's system prompt about the conversation, for example "the latest draft", since every agent sees the turns before it.

## 3. More rounds, and reading the whole transcript

With `max_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:

```python theme={null}
two_rounds = RoundRobinSwarm(
    name="Launch-Copy-Two-Rounds",
    agents=[drafter, critic, editor],
    max_loops=2,
    output_type="list",
)

messages = two_rounds.run("Write a launch announcement for a budget e-bike called the Volt One.")

print([message["role"] for message in messages])
print(messages[-1]["content"])
```

```text theme={null}
['User', 'Drafter', 'Critic', 'Editor', 'Drafter', 'Critic', 'Editor']
Introducing the Volt One: the budget e-bike that brings a little more freedom to every ride. ...
```

The order is the same on every round. In round two the Drafter sees the Editor's round-one draft and the Critic's notes, so the second pass refines the first.

Other `output_type` values work the same way as in the other structures:

| `output_type` | `run()` returns |
| - | - |
| `"final"` (default), `"last"` | The last agent's answer as a string |
| `"list"` | A list of `{"role", "content"}` dicts, starting with the task |
| `"dict"` | The message dicts with their timestamps and ids |
| `"str"`, `"all"` | The whole transcript as one string, one timestamped line per message |

## 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.

```python theme={null}
products = [
    "Write a launch announcement for a budget e-bike called the Volt One.",
    "Write a launch announcement for a folding cargo trailer called the HaulPack.",
]

drafts = swarm.run_batch(products)

for product, draft in zip(products, drafts):
    print(f"=== {product}\n{draft}\n")
```

## 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.usage` sums the token usage of all the agents.

## Next steps

* [RoundRobinSwarm reference](https://docs.swarms.world/api/round-robin-swarm.md)
* [AgentRearrange guide](https://docs.swarms.world/examples/multi-agent/agent-rearrange-example.md), when some agents should run in parallel
* [Runnable scripts](https://github.com/kyegomez/swarms/tree/master/examples/multi_agent/round_robin_examples)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.