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

# Examples

> Work teams hand to runs, with the command or the definition for each.

Each example opens with what it is for, the problem it solves and how it works, and then gives the command or the definition to start from. Names such as `acme/api` are placeholders for your own repository, tools and agents.

## Which one fits

| You have | Use | Example |
| - | - | - |
| One change to a repository | A task on a repository | [A failing test](#a-failing-test-you-can-reproduce) |
| A pull request with review comments or a red check | `sensei pr` | [An open pull request](#an-open-pull-request-with-a-red-check) |
| Tests that need a database or a private package | `sensei.yaml`, settings and secrets | [Tests that need a database](#tests-that-need-a-database-and-a-private-package) |
| Several changes to one repository | A batch | [A migration, module by module](#a-migration-module-by-module) |
| Several small changes you want as one pull request | A batch with `deliver: one` | [Dependency updates](#dependency-updates-in-one-pull-request) |
| A backlog in your coding agent's chat | `batch_start` from chat | [A backlog from your coding agent](#a-backlog-from-your-coding-agent) |
| The same kind of changes every week, on a new list | A saved batch that takes its tasks as input | [The same chores, a new list](#the-same-chores-on-a-new-list-each-week) |
| A list that lives in your tracker | Steps with a batch as one step | [From the tracker to pull requests](#from-the-tracker-to-pull-requests-every-monday) |
| Work in your own tools, with a person approving the risky action | An agent with `ask_first` | [A refund a person approves](#a-refund-a-person-approves) |
| A page to check on a timetable | An agent with a browser, a check and a schedule | [A live page, every morning](#a-live-page-checked-every-morning) |
| A question about a codebase | A task that asks | [A question about a repository](#a-question-about-a-repository) |

## Changes to a repository

### A failing test you can reproduce

**What it is for.** A test or a build fails on your machine, you know the command that shows it, and you would rather hand the fix over than stop what you are doing.

**The problem.** A failure described in words loses what matters: the assertion, the traceback, the line. And a fix that makes one test pass can break another without anyone noticing.

**How it works.** `--from-failure` runs your command locally and attaches what it printed to the task. Sensei then clones the repository into a sandbox on its side, runs the whole test suite to see what already fails, makes the change and runs the suite again on your original test files. The lint and format checks from your CI workflow run before and after as well. The change comes back as a pull request with the verdict in it. The run starts from what is pushed, so push the branch that shows the failure first.

Let the command run the failure and attach what it printed:

```bash theme={null}
sensei run "Fix this" --from-failure "pytest tests/test_upload.py -x"
```

Sensei runs the tests before the change, makes the change, runs them again on your original test files and opens a pull request.

| What comes back | Where |
| - | - |
| The verdict: **Verified**, **Failed** or **Not verified** | The run's page and the pull request body |
| How many tests passed, and how many that failed before now pass | Under the verdict |
| The lint and format checks from your CI workflow, each with its result | Under the verdict |

A change that breaks a lint check which passed before is **Failed**, and no pull request is opened until you say so. See [Work on a repository](https://docs.sense-lab.ai/sensei/runs/repository-runs.md#how-a-change-is-verified).

### An open pull request with a red check

**What it is for.** A pull request that is waiting on review comments or on a failing check.

**The problem.** Small review fixes and red checks sit for days. Each one needs someone to stop, check out the branch, work out what the reviewer or the CI log means and push a commit.

**How it works.** Sensei reads the review comments and the output of the failing checks, works on the pull request's own branch in a sandbox and runs the tests before and after. It adds one commit to the branch and says what it did in a comment on the pull request. Review comments and check output are other people's text, so Sensei reads them as review of the code and takes no instructions from them. The repository has to be connected with a token, and a pull request from a fork is refused.

```bash theme={null}
sensei pr 212
sensei pr 212 "Address the review, and leave the public API as it is"
```

Sensei reads the review comments and the failing checks, adds one commit to the pull request's branch and says what it did in a comment. It never force pushes.

From chat, with the [runs server added](https://docs.sense-lab.ai/sensei/runs/chat-tools.md):

```
Have Sensei fix pull request 212 on acme/api.
```

### Tests that need a database and a private package

**What it is for.** A repository whose tests need more than the code: a Postgres or a Redis running beside them, a value CI sets, a token to install private packages.

**The problem.** A sandbox that holds only the code cannot run such tests, so a change comes back unproven. Handing the agent that does the work a registry token to get round it is a risk you should not have to take.

**How it works.** A run sets the repository up the way its CI does.

| Part | What the run does |
| - | - |
| Services | Starts each one beside the run, on a network made for that run, and waits for it to be ready. The tests reach it by name. |
| Settings | Plain values the project keeps. Every command of the run reads them. |
| Secrets | Reach the setup commands only. Setup runs in a computer of its own, and the work starts in a new computer made from its image, without the secret. |

A run starts the services the repository already declares in its CI workflow, devcontainer or compose file, so often there is nothing to write. When you want to say it yourself, put a `sensei.yaml` at the root of the repository:

```yaml theme={null}
# sensei.yaml
image: node:22-bookworm
services:
  postgres:
    image: postgres:16
    env:
      POSTGRES_PASSWORD: postgres
    ports: ["5432:5432"]
    ready: pg_isready -U postgres
  cache: redis:7
setup:
  - npm ci
  - npm run db:migrate
check: npm test
env:
  APP_ENV: test
secrets: [NPM_TOKEN]
```

Give the project the values once:

```bash theme={null}
sensei secrets set NPM_TOKEN                       # prompted for, used by the setup commands only
sensei settings set REPORTS_BUCKET reports-test    # a plain value every command reads
```

Then every run on the repository is set up this way:

```bash theme={null}
sensei run "Add an index on orders.created_at and a test for the slow query" --repo acme/api
```

The tests reach the database at `postgres:5432`. The secret is in the environment of the setup commands and of no command after them. A run that cannot pass because the project was not given a value ends **Failed** before any model call and names the value. See [Services, settings and secrets](https://docs.sense-lab.ai/sensei/runs/services-and-settings.md).

Each service costs $0.0025 a minute while it is up, beside $0.005 a minute for the run's computer.

### A migration, module by module

**What it is for.** The same change in many places: a new logger, a renamed API, a library swapped out, one module at a time.

**The problem.** Done one after another, a migration takes days. Done as separate runs side by side, each change passes on its own and nobody knows whether they pass together until they are merged. Two of them can edit the same lines, or break a test only in combination.

**How it works.** A batch is a list of tasks on one repository. It reads the commit the branch is at once, and every task starts from that commit as a run of its own. The changes that verified are then merged in the order of the tasks and the tests run on the result, so each pull request can say how its change did alone and how it fits with the rest.

```yaml theme={null}
# logger-migration.yaml
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
  - Move notifications to the new logger
  - Move payouts to the new logger
  - Move refunds to the new logger
parallel: 4
deliver: each
limit: { usd: 3 }
total: { usd: 15 }
```

```bash theme={null}
sensei run logger-migration.yaml
```

| Step | What happens |
| - | - |
| 1 | Every task starts from the same commit of `main`, four at a time |
| 2 | The changes that verified are merged in the order of the tasks, and the tests run on the result |
| 3 | Each verified change gets a pull request that says how it did alone, how it fits with the rest and the order to merge in |

A change that collides with another is named with the one it collides with, such as "Conflicts with #412 in billing/format.py. Merge #412 first, then update this one."

After you merge some of them, test the rest against the branch as it is now:

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

See [Several changes at once](https://docs.sense-lab.ai/sensei/runs/batches.md).

### Dependency updates in one pull request

**What it is for.** A handful of small, related changes you want to review and merge as one.

**The problem.** Five pull requests for five small updates are five reviews and five CI runs. One pull request made by hand mixes the updates, and when the tests fail it does not say which update broke them.

**How it works.** Each task is still worked alone from the same commit and verified alone, so you know which update is at fault when one fails. The verified changes are merged and tested together, and `--deliver one` opens a single pull request that holds the ones that fit, with a commit for each task.

Put one task on each line of a file:

```text theme={null}
Update eslint to the latest 9.x and fix what it reports
Update vitest to the latest 3.x
Update typescript to 5.7 and fix the new type errors
Replace moment with date-fns in src/reports
```

```bash theme={null}
sensei batch updates.txt --repo acme/web --deliver one --limit 3 --total 10
```

The pull request holds the changes that fit together. A change that was left out is listed in it with the reason, so nothing is dropped without a word.

## From your coding agent

### A backlog from your coding agent

**What it is for.** The tasks that pile up while you work with Claude Code, Codex or Cursor: chores, a failing check, a contained refactor.

**The problem.** A coding agent works in your session, on your machine. When the plan's allowance runs out or the machine cannot carry another agent, the rest of the list waits behind you.

**How it works.** The runs server is added to your coding agent once. When you ask, the agent calls `batch_start` with the repository, your branch and the tasks, and goes back to what it was doing. Each task works on a computer of its own on Sensei's side, paid from your Sensei credits, and comes back as a pull request with a verdict. Your machine does none of it.

With the [runs server added](https://docs.sense-lab.ai/sensei/runs/hand-off.md#set-it-up-once), push your branch and say:

```
Hand these to Sensei on acme/api, from my branch, $12 at most:
1. Remove the unused feature flags in billing/
2. Add type hints to the public functions in reports/
3. Replace the deprecated datetime.utcnow() calls
```

The agent calls `batch_start` and answers with the batch's address. Ask it for the result later:

```
How did the Sensei batch go?
```

It reads the batch with `run_status` and shows each task's verdict and pull request as they are. A run starts from what is pushed, so work that is only in your working tree is not part of it.

[Hand work off at your limit](https://docs.sense-lab.ai/sensei/runs/hand-off.md#tell-your-agent-which-tasks-to-hand-off) has the text to put in `AGENTS.md` or `CLAUDE.md` so the agent knows which tasks to hand off.

## Recurring work

### The same chores, on a new list each week

**What it is for.** Work of the same kind that comes round again, where only the list changes: this week's cleanup, this sprint's small fixes.

**The problem.** Writing the batch out again each time means settling the repository, the instructions and the limits again each time, and they drift. What changes from week to week is the list, and nothing else should have to.

**How it works.** A saved batch can name the input field that holds its tasks in place of listing them. The repository, the instructions and the limits are saved once under the agent's name. The list is given when the batch is started, from a file, the command line or a script, and is read like a written one.

Save the batch once. `tasks` names the input field that holds the list:

```yaml theme={null}
# chores.yaml
agent: chores
repo: acme/api
instructions: |
  Keep each change small. Do not change behaviour that has no test.
input:
  changes: list
tasks: $input.changes
parallel: 4
limit: { usd: 3 }
total: { usd: 20 }
```

```yaml theme={null}
# this-week.yaml
changes:
  - Remove the unused feature flags in billing/
  - Add type hints to the public functions in reports/
  - Replace the deprecated datetime.utcnow() calls
```

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

A script can build the list and start it:

```python theme={null}
from sensei import Sensei

sensei = Sensei()
r = sensei.start("chores", changes=[
    "Remove the unused feature flags in billing/",
    "Add type hints to the public functions in reports/",
])
print(r.url)
```

A run with an empty list, or with an entry that is not text, is not started.

### From the tracker to pull requests, every Monday

**What it is for.** A list of small changes that lives in your issue tracker, turned into pull requests on a timetable with nobody copying it across.

**The problem.** Every week someone reads the tracker, decides what is ready, writes the tasks, starts them and tells the team what came of it. A batch cannot do the first and last parts, because a batch only changes a repository and cannot call your tools. An agent with tools cannot do the middle part.

**How it works.** A run with steps joins the three, and each step hands its result to the next.

| Step | What it is | What it does |
| - | - | - |
| `list` | An agent with your tracker as a tool | Reads the open issues and writes each as a change, in a list |
| `changes` | A batch | Takes the list through its input, makes each change from one commit, tests them together and opens the pull requests |
| `note` | An agent with your chat tool | Posts the batch's summary and its pull requests |

A schedule starts the run, so the whole of it happens without anyone asking.

```yaml theme={null}
# weekly-chores.yaml
agent: weekly-chores
input:
  label: text
limit: { usd: 30, minutes: 120 }
steps:
  - id: list
    agent:
      instructions: |
        List the open issues with the label given. Write
        each one as a change a developer could make without
        asking anything: the files, the behaviour wanted and
        how to check it. Leave out issues that need a decision.
      input:
        label: text
      output:
        changes: list
      tools: [linear]
    input:
      label: $input.label

  - id: changes
    agent:
      repo: acme/api
      instructions: |
        Keep each change small. Do not change behaviour
        that has no test.
      input:
        changes: list
      tasks: $input.changes
      parallel: 4
      limit: { usd: 3 }
    when: $list.output.changes
    input:
      changes: $list.output.changes

  - id: note
    agent:
      instructions: |
        Post one message to #eng-chores: the summary, then
        each pull request on its own line.
      input:
        summary: text
        pull_requests: list
      tools: [slack]
    when: $changes.output.pull_requests
    input:
      summary: $changes.output.summary
      pull_requests: $changes.output.pull_requests
```

Connect the two tools once, save the definition and put it on a timetable:

```bash theme={null}
sensei tools connect linear --url https://mcp.example.com/linear
sensei tools connect slack --url https://mcp.example.com/slack
sensei push weekly-chores.yaml
sensei schedule add weekly-chores "every monday at 09:00" -i label=chore --timezone Europe/Lisbon
```

| Case | What the run does |
| - | - |
| The tracker has nothing with the label | `changes` and `note` are skipped. The run ends with the list step's output. |
| Some changes verify and some do not | The run goes on. `note` posts the summary and the pull requests that were opened. |
| No change verifies | The batch fails, and so does the run. Nothing is posted. |

The run's `limit` covers all three steps, the batch and its tasks included: $50 and 120 minutes at most. A list that needs more is [started as a batch on its own](#the-same-chores-on-a-new-list-each-week), which may spend up to $500.

The agent that lists the changes has to be one with an `output`. A step that changes a repository cannot be the one that lists them. See [A batch as a step](https://docs.sense-lab.ai/sensei/runs/steps.md#a-batch-as-a-step).

### A live page, checked every morning

**What it is for.** A public page that has to keep saying the right thing: pricing, a status page, a sign-up form.

**The problem.** Such pages break quietly, after a deploy or an edit in the CMS. A monitor that asks whether the page loads says nothing about what the page shows.

**How it works.** The agent gets a computer with Chromium and Playwright, opens the page the way a visitor does, reads what it was asked to read and can save a screenshot. The `check` command then decides whether the output is acceptable. A run whose check passes ends **Verified**, and one whose check fails is handed back to the agent to fix. A schedule runs the agent on a timetable, and each run stays on record with what it found.

```yaml theme={null}
# pricing-page-check.yaml
agent: pricing-page-check
instructions: |
  Open the pricing page at the URL given and read the name and the monthly
  price of each plan. Save a screenshot of the page.
input:
  url: text
output:
  plans: list
computer: browser
check: python -c "import json; assert json.load(open('/work/output.json'))['plans']"
limit: { usd: 1, minutes: 10 }
```

```bash theme={null}
sensei push pricing-page-check.yaml
sensei schedule add pricing-page-check "every weekday at 08:00" -i url=https://example.com/pricing
```

`sensei schedule list` shows how the last run went. A schedule that fails to start three times in a row pauses itself and says why.

## Agents in your own tools

### A refund a person approves

**What it is for.** Routine decisions made in your own tools by a rule your team already follows: a refund, a credit, an account change.

**The problem.** Done by hand, each one is minutes of reading a ticket and an order to apply the same rule. Done by an agent with nobody watching, the one action that moves money happens on the agent's word alone.

**How it works.** The agent reads and decides through the tools you connect to the project. Their secrets never enter its computer: the runs service makes each call from outside. An action listed under `ask_first` is not taken. The run stops and shows you the action, its arguments and one sentence on why the agent thinks it is right, and you approve, correct or reject.

```yaml theme={null}
# refund-requests.yaml
agent: refund-requests
description: Decides refund requests from the helpdesk.
instructions: |
  Refund when the order arrived late and the amount is under $50.
  Otherwise hand it to a person.
input:
  ticket: number
output:
  decision: refunded | handed_over
  amount?: number
tools: [zendesk, stripe]
ask_first: [stripe.refund]
limit: { usd: 0.50, minutes: 10 }
```

```bash theme={null}
sensei run refund-requests -i ticket=48213
sensei answer <run> approve
sensei answer <run> correct "Store credit when they paid with a gift card"
```

What you write when you correct it is kept and given to every later run of the agent. The computer is saved and switched off while the run waits, so the wait costs nothing. See [Agents](https://docs.sense-lab.ai/sensei/runs/agents.md).

### A question about a repository

**What it is for.** Understanding code you do not know yet: your first week on a team, the day before a change, an audit.

**The problem.** The answer is spread over many files, and an assistant without the repository in front of it guesses.

**How it works.** Sensei clones the repository into a sandbox, reads it and can run it, and writes the answer. A task that asks is answered and nothing is changed: no branch is pushed and no pull request is opened.

```bash theme={null}
sensei run "Which services write to the orders table, and from which code paths?" --repo acme/api
```

Saved, the team runs the same question by name:

```yaml theme={null}
# repo-check.yaml
agent: repo-check
repo: acme/checkout
ref: main
instructions: Give an overview of the repository and its services.
```

The run ends **Done**, and the answer is the result.

## What each one may spend

| Kind | Default | Ceiling |
| - | - | - |
| One run | \$5, 30 minutes | \$50, 120 minutes |
| A batch | \$5 for each task, and the tasks' limits added up in total | $50 for each task, $500 in total |
| A run with steps, all of its steps together | \$5, 30 minutes | \$50, 120 minutes |

See [Limits and cost](https://docs.sense-lab.ai/sensei/runs/limits.md).


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