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

# Several changes at once

> Hand Sensei a list of changes to one repository. Each is worked alone, then all of them are tested together.

A batch is a list of tasks on one repository, started in one go. Each task is a run of its own. When they finish, the changes that verified are merged and tested together, so you know which of them fit before you merge anything.

## What a batch does

**1. One commit for all of them**

The batch reads which commit the branch is at, once. Every task starts from that commit.

**2. Each task, alone**

Each task is a run with its own page, cost and verdict. Four work at a time unless you say otherwise, and the rest wait their turn.

**3. All of them, together**

One more run applies the verified changes, in the order of the tasks, onto the commit they started from, and runs the tests on the result. It calls no model, so it costs computer time only.

**4. Pull requests**

Each pull request says how its change did alone and with the rest.

## Start a batch

> [tab] Dashboard
>
> Open **Runs**, click **New run** and pick **A task**. Write one task on each line. With a repository connected, several lines are several tasks, and the form asks for the repository, the branch, the pull requests, how many work at once and what each task and all of them may cost. **Start** says how many tasks it starts.
>
> When the lines are one task's detail, click **Make it one task**.
>
> The dashboard takes up to 100 tasks.

> [tab] Terminal
>
> Put one task on each line of a file:
>
> ```bash theme={null}
> sensei batch tasks.txt --repo acme/api
> sensei batch tasks.txt --repo acme/api --deliver one --total 24
> ```
>
> In a checkout, the repository defaults to the checkout's origin.

> [tab] Definition
>
> ```yaml theme={null}
> agent: logger-migration
> repo: acme/api
> ref: main
> instructions: Use the logger in lib/log. Keep the public API as it is.
> tasks:
>   - Move billing to the new logger
>   - Move checkout to the new logger
>   - Move invoices to the new logger
> parallel: 4
> deliver: each
> limit: { usd: 3 }
> total: { usd: 8 }
> ```
>
> Run it with `sensei run tasks.yaml`. `instructions` are said once, to every task.

> [tab] Python
>
> ```python theme={null}
> b = sensei.batch(
>     "acme/api",
>     ["Move billing to the new logger", "Move checkout to the new logger"],
>     total={"usd": 24},
> )
> b.wait()
> for t in b.tasks:
>     print(t["index"], t["status"], t.get("together"), t.get("pr_url"))
> ```

> [tab] Chat
>
> With Sensei added to Claude, Cursor or Codex, say "hand these three tasks to Sensei on acme/api". The assistant calls `batch_start`. See [Run from a chat tool](https://docs.sense-lab.ai/sensei/runs/chat-tools.md).

## Tasks given when it is started

A saved batch does not have to list its tasks. It can name the input field that holds them, and take a new list on every run:

```yaml theme={null}
agent: chores
repo: acme/api
input:
  changes: list
tasks: $input.changes
parallel: 4
```

```bash theme={null}
sensei push chores.yaml
sensei run chores --input-file this-week.yaml
```

`this-week.yaml` holds `changes:` and the list. The field is one field of the batch's own `input`, and it is a `list`. A list given this way is read like a written one: 1 to 200 entries, each text, each up to 4,000 characters. A run with an empty list, or with an entry that is not text, is not started.

## A batch as a step

A batch can be one step of a [run with steps](https://docs.sense-lab.ai/sensei/runs/steps.md#a-batch-as-a-step): one step lists the changes, the batch makes them and checks them together, and a later step reads the pull requests. The step passes the list through the batch's input, as above.

[From the tracker to pull requests](https://docs.sense-lab.ai/sensei/runs/examples.md#from-the-tracker-to-pull-requests-every-monday) is a whole definition that does this on a schedule.

## Options

| Option | Default | Limits | Meaning |
| - | - | - | - |
| Tasks | | 1 to 200, each up to 4,000 characters | One entry for each change, in your words |
| Working at once (`parallel`) | 4 | 1 to 10 | How many tasks work at the same time |
| Test together (`together`) | On | | Merge the verified changes and run the tests on the result before any pull request |
| Pull requests (`deliver`) | `each` | `each` or `one` | See below |
| Each task (`limit`) | \$5 | Up to \$50 | What one task may spend. A task has the time and step limits of any run. |
| All of them (`total`) | The tasks' limits added up | Up to \$500 | What the batch may spend |

When the total is reached, the tasks still working are stopped and none is started. What verified is kept, checked together and delivered.

### Pull requests

| `deliver` | What you get |
| - | - |
| `each` | A pull request for each verified change. Each says how the change did alone and with the rest, the order to merge in, and the commit the check was made against. A change that does not fit still gets its pull request, which says what it collides with. |
| `one` | One pull request holding the changes that fit, with a commit for each task. The changes left out are listed in it with the reason. `one` needs `together` on. |

A batch opens its own pull requests, on branches of its own. In the API, `policy.branch` and `policy.pr` are refused for a batch.

## What "together" finds

| A change | What the batch says |
| - | - |
| Fits | It merges with the others and the tests pass on the result |
| Conflicts | It does not apply after an earlier task's change. The batch names that task and the files. |
| Breaks the tests | The tests fail once it is merged with the others. The batch names the other task and the failing tests. |

When the tests fail on the merged result, the batch looks for the change that breaks it, leaves that change out and tests the rest again. It runs the tests up to 8 times for this. If it does not find the change in that many, it says the changes merge and that the reason the tests fail was not found.

![The end of a batch's timeline: eight tasks started, their verified changes tested together, and the pull request opened](https://mintcdn.com/senselab/7GJRxwA5n_G2FDq5/images/sensei/run-batch-together.png?fit=max\&auto=format\&n=7GJRxwA5n_G2FDq5\&q=85\&s=5d71bd90f09f446efee85bc5e7bbd351)

With one verified change there is nothing to merge, and the batch says the change is the only one.

## A batch's status

| Status | When |
| - | - |
| Verified | Every task verified and the changes fit together |
| Part verified | Some tasks verified, or all did and they do not fit together. In the API this is `unverified`. |
| Failed | No task verified |

In the Runs list a batch is one row, with how many of its tasks verified. Its page lists every task with its verdict alone, how it fits with the rest, its cost and its pull request. Click a task to open its own run.

![A batch's page: every task with its verdict alone, whether it fits with the rest, its time and its cost](https://mintcdn.com/senselab/7GJRxwA5n_G2FDq5/images/sensei/run-batch.png?fit=max\&auto=format\&n=7GJRxwA5n_G2FDq5\&q=85\&s=34d06ce35e42f11abf56ccd94f0705f6)

## Check again

After you merge some of the pull requests, or the branch moves, the rest may no longer fit. **Check again** on the batch's page runs the together step once more, on the changes that are not merged yet, against the branch as it is now. Changes that are already in the branch are left out.

```bash theme={null}
sensei batch check <run>
```

In Python, `b.check_again()`. In chat, `batch_check`. A batch started with `together` off cannot be checked again.

## Limits

| Limit | Value |
| - | - |
| Tasks in one batch | 200, or 100 from the dashboard |
| Tasks of all your batches queued or working | 400 |
| Runs working at once for an account | 12. See [Limits and cost](https://docs.sense-lab.ai/sensei/runs/limits.md#how-many-runs-at-once). |

A batch counts as one run towards the runs an account may have queued or running, whatever its tasks.

A batch cannot list `tools`, use a browser or have `steps` inside it. Each task is a change to the repository. A batch can be a step of another run; see [A batch as a step](https://docs.sense-lab.ai/sensei/runs/steps.md#a-batch-as-a-step).

A batch that was a step can be checked again once the run it is a step of has finished.


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