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

# SpreadSheetSwarm Guide

> Run many agents at once, collect one row per agent per run, save the rows to CSV, and load agents and their tasks from a CSV file

A `SpreadSheetSwarm` runs its agents at the same time and records each agent's answer as a row: agent name, task, result and timestamp. You can give every agent the same task, or load agents from a CSV file where each row has its own task. With `autosave=True`, the rows are appended to a CSV file you can open in any spreadsheet tool.

Reference: [SpreadSheetSwarm](https://docs.swarms.world/api/spreadsheet-swarm.md).

## 1. Run every agent on one task

Three analysts look at the same launch plan, each from its own angle:

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


def analyst(name: str, focus: str) -> Agent:
    """Build a one-loop analyst with a narrow focus."""
    return Agent(
        agent_name=name,
        system_prompt=f"You are a product analyst. Focus only on {focus}. Answer in two sentences.",
        model_name="gpt-5.4-mini",
        max_loops=1,
        print_on=False,
    )


swarm = SpreadSheetSwarm(
    name="Launch-Review",
    agents=[
        analyst("Pricing-Analyst", "pricing"),
        analyst("Risk-Analyst", "risks"),
        analyst("Marketing-Analyst", "marketing channels"),
    ],
)

summary = swarm.run("We plan to launch a $9 per month habit-tracking app for students.")

print(summary["tasks_completed"], "of", summary["number_of_agents"], "agents finished")
for row in summary["outputs"]:
    print(f"{row['agent_name']}: {row['result']}\n")
```

This prints `3 of 3 agents finished`, then one answer per analyst. The agents run in parallel, so the run takes about as long as the slowest agent.

`autosave` is `False` by default, so this run writes nothing to disk.

## 2. Read the summary

`run()` returns a dict. Continuing from step 1:

```python theme={null}
print(summary["run_id"], summary["name"])
print(summary["start_time"], "->", summary["end_time"])
print(summary["outputs"][0].keys())
print(swarm.export_to_json()[:300])
```

| Key | What it holds |
| - | - |
| `run_id` | A new id for every run, such as `spreadsheet_swarm_run_4dd7...` |
| `name`, `description` | The swarm's name and description |
| `start_time`, `end_time` | ISO 8601 timestamps |
| `tasks_completed` | Rows whose agent finished without an error |
| `number_of_agents` | How many agents the swarm holds |
| `outputs` | One dict per agent per loop, with `agent_name`, `task`, `result` and `timestamp` |

Every `run()` starts a fresh `run_id`, `outputs` and `tasks_completed`, so a second run returns only its own rows. `export_to_json()` returns the latest run as a JSON string with the same keys, minus the two timestamps.

## 3. Save rows to a CSV file

With `autosave=True`, each run appends its rows to the CSV at `save_file_path` and writes a JSON copy of the summary to the swarm's workspace folder. `max_loops=2` runs every agent twice, one loop after the other, so this run makes four rows:

```python theme={null}
import csv
import os

from swarms import Agent, SpreadSheetSwarm

os.makedirs("runs", exist_ok=True)

swarm = SpreadSheetSwarm(
    name="Headline-Writers",
    agents=[
        Agent(
            agent_name=f"Writer-{i}",
            system_prompt="Write one headline. Reply with the headline only.",
            model_name="gpt-5.4-mini",
            max_loops=1,
            print_on=False,
        )
        for i in range(1, 3)
    ],
    max_loops=2,
    autosave=True,
    save_file_path="runs/headlines.csv",
)

summary = swarm.run("Write a headline for a story about a city that banned cars downtown.")
print(len(summary["outputs"]), "rows from", summary["number_of_agents"], "agents")

with open("runs/headlines.csv", newline="") as file:
    for row in csv.reader(file):
        print(row)

print(os.listdir(swarm.swarm_workspace_dir))
```

Output from one run, shortened:

```
4 rows from 2 agents
['Run ID', 'Agent Name', 'Task', 'Result', 'Timestamp']
['spreadsheet_swarm_run_6a28...', 'Writer-1', 'Write a headline ...', 'City Bans Cars Downtown, Reclaiming Streets for People', '2026-12-02T13:43:39.957423']
['spreadsheet_swarm_run_6a28...', 'Writer-2', 'Write a headline ...', 'City Bans Cars Downtown in Bold Move to Reclaim Streets', '2026-12-02T13:43:39.957432']
['spreadsheet_swarm_run_6a28...', 'Writer-1', 'Write a headline ...', 'City Downtown Goes Car-Free in Landmark Ban', '2026-12-02T13:43:40.901044']
['spreadsheet_swarm_run_6a28...', 'Writer-2', 'Write a headline ...', 'Downtown Goes Car-Free as City Bans Traffic to Boost Walkability', '2026-12-02T13:43:40.901048']
['spreadsheet_swarm_run_6a28...-metadata.json']
```

* The header row is written only when the file is new. Later runs append below it, each with its own `Run ID`.
* The swarm does not create the CSV's folder. Create it first, as above.
* Without `save_file_path`, the CSV is named `spreadsheet_swarm_run_id_<hex>.csv` and goes in the workspace folder.
* Each agent starts every loop on a fresh conversation, so loops are independent samples, not revisions.

## 4. Give each agent its own task from a CSV

A CSV with `agent_name` and `task` columns defines both the agents and their work. Pass it as `load_path` and call `run()` with no task. The other columns set the agent's settings; `description` becomes the agent's `agent_description`.

```python theme={null}
import os

from swarms import SpreadSheetSwarm

os.makedirs("runs", exist_ok=True)

with open("runs/agents.csv", "w") as file:
    file.write(
        "agent_name,description,system_prompt,task,model_name\n"
        "Translator,Translates text,Translate into French. Reply with the translation only.,Good morning and welcome to the team,gpt-5.4-mini\n"
        "Summarizer,Summarizes text,Summarize in five words or fewer.,The meeting moved to Thursday because the client asked for more time to review the budget,gpt-5.4-mini\n"
        "Classifier,Labels sentiment,Reply with positive or negative or neutral only.,The new update made the app slower and harder to use,gpt-5.4-mini\n"
    )

swarm = SpreadSheetSwarm(name="Text-Jobs", load_path="runs/agents.csv")
summary = swarm.run()

for row in summary["outputs"]:
    print(f"{row['agent_name']} | {row['task']} | {row['result']}")
```

Output:

```
Translator | Good morning and welcome to the team | Bonjour et bienvenue dans l’équipe
Summarizer | The meeting moved to Thursday because the client asked for more time to review the budget | Meeting postponed for budget review
Classifier | The new update made the app slower and harder to use | negative
```

How the CSV is used:

* With no `agents` passed, the first `run()` builds one agent per row with [AgentLoader](https://docs.swarms.world/api/agent-loader.md). `run()` with no task then calls `run_from_config()`, which runs each agent on its own row's task.
* A blank cell leaves that setting at the `Agent` default. Agents built from the CSV print their replies, since `print_on` defaults to `True`.
* An agent whose name has no task in the CSV is skipped by `run_from_config()`.
* If you pass `agents` as well, call `swarm.load_from_csv()` yourself to add the CSV's agents and tasks.

## 5. Spot a failed agent

One agent's failure does not stop the others. Its row still appears, with `result` set to `"Error: "` plus the error message, and it is not counted in `tasks_completed`:

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

swarm = SpreadSheetSwarm(
    name="Mixed-Models",
    agents=[
        Agent(agent_name="Working", model_name="gpt-5.4-mini", max_loops=1, print_on=False),
        Agent(agent_name="Broken", model_name="openai/no-such-model", max_loops=1, print_on=False),
    ],
)

summary = swarm.run("Name one prime number.")

print(summary["tasks_completed"], "of", summary["number_of_agents"], "agents finished")
for row in summary["outputs"]:
    status = "failed" if row["result"].startswith("Error:") else "ok"
    print(f"{row['agent_name']} [{status}]: {row['result'][:80]}")
```

Output, after the error is logged:

```
1 of 2 agents finished
Working [ok]: 2
Broken [failed]: Error: Agent 'Broken': model 'openai/no-such-model' failed: Error code: 404 - {'
```

With `autosave=True`, the failed row is saved to the CSV too, so check the `Result` column for `Error:` when you read the file back.

## Tips

* **Give every agent a distinct `agent_name`.** Rows show only the name, and CSV tasks are matched to agents by name.
* **Set `print_on=False`** on agents you build yourself when you only want the rows.
* **Read token usage** with `swarm.usage`, which adds up every agent's provider usage.
* **Pass at least `agents` or `load_path`.** With neither, the constructor raises `ValueError("No agents are provided.")`.

## Next steps

* [SpreadSheetSwarm reference](https://docs.swarms.world/api/spreadsheet-swarm.md)
* [AgentLoader](https://docs.swarms.world/api/agent-loader.md), for the CSV columns an agent accepts
* [ConcurrentWorkflow](https://docs.swarms.world/api/concurrent-workflow.md), to run agents in parallel without the spreadsheet bookkeeping


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