Skip to content
RehearsalDocs

Use Rehearsal in CI

Rehearse the changed agent on every pull request, next to the version on main, and fail the check when it verifies too little, breaks a rule or does worse.

Time
10 minutes to set up
Needs:
a published world version, and a key with Build and evaluate access

A pull request that changes your agent's instructions can make the agent worse. The Rehearsal gate is a check for that: it rehearses the changed agent and the agent on main side by side, on the same jobs, and fails the pull request when the change does worse.

How the gate decides

  1. It makes a version of the agent from the instructions file in the pull request. When the latest version already has the same instructions, it reuses it.
  2. It makes the baseline the same way, from the same file on main.
  3. It starts one run with both versions, so both get the same jobs at the same time.
  4. It waits for the run and checks the result.

The change passes only when all of these hold:

CheckDefault
Verified success reaches min-successNo minimum
Episodes with a rule violation stay at or under max-violations0: any broken rule fails
Verified success is not lower than the baseline's, minus tolerance0
No more rule violations, false completions or duplicate side effects than the baselineAlways on with a baseline
At least one episode was scoredAlways on

The gate writes a Markdown report to the job summary: both versions side by side, every check with PASS or FAIL, and a link to the run. It exits with 0 (passed), 1 (failed) or 2 (the run could not start or did not finish). A refused or unfinished run is never reported as the agent failing.

The Free plan waits for quiet hours

On the Free plan, a run starts only in the quiet window, so a CI job can wait for hours. Use a paid plan or your own server for CI.

Set up

Create a key for CI

In the console, open API keys and create a key named for the pipeline, with Build and evaluate access. Store it as the repository secret REHEARSAL_API_KEY. Give the pipeline its own key, so that you can revoke it alone.

Choose the world version

Use one published world version for every run, so that results stay comparable. Find its id:

rehearsal worlds list

Keep the id as the repository variable REHEARSAL_WORLD_VERSION. Change it when you build a new world version for a new release of your application.

Add the workflow

Save this as .github/workflows/rehearse.yml. It runs only when the agent's instructions change.

name: Rehearse the agent
on:
  pull_request:
    paths: ["agent/instructions.md"]

concurrency:
  group: rehearse-${{ github.ref }}
  cancel-in-progress: true

jobs:
  gate:
    runs-on: ubuntu-latest
    timeout-minutes: 60
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0   # the baseline is read from main
      - uses: MitudruDutta/rehearsal@main
        with:
          api-key: ${{ secrets.REHEARSAL_API_KEY }}
          world-version: ${{ vars.REHEARSAL_WORLD_VERSION }}
          prompt-file: agent/instructions.md
          name: support-agent
          baseline-ref: origin/main
          splits: holdout
          repeats: "2"
          min-success: "0.6"

On your own server, add server: https://your-server.

Every input

InputMeaning
api-keyRequired. A key with Build and evaluate access
world-versionRequired. The published world version
prompt-file and nameThe instructions file and the agent's name. Or give profile, a profile id
baseline-refA git ref whose prompt-file is the baseline, for example origin/main. Or give baseline, a profile id
splitsComma-separated: train, dev, holdout. Empty runs every split
repeatsAttempts at each job. Default 1
min-successFail below this verified success rate, from 0 to 1
max-violationsFail above this many episodes with a rule violation. Default 0
toleranceHow far below the baseline's success rate still passes. Default 0
timeout-minutesHow long to wait for the run. Default 90
serverDefault https://rehearsalkit.xyz

Other CI systems

The action runs one command. Any CI system can run it:

pip install rehearsal-kit
git show origin/main:agent/instructions.md > main-instructions.md
rehearsal gate "$REHEARSAL_WORLD_VERSION" --prompt-file agent/instructions.md --name support-agent \
  --baseline-file main-instructions.md --split holdout --repeats 2 --min-success 0.6 --budget 2

It reads REHEARSAL_URL and REHEARSAL_API_KEY from the environment. See every flag in the CLI reference.

The summary, field by field

To build your own check, read the run's summary with rh.runs.get(run_id)["summary"]. It has this shape:

{
  "profiles": {
    "support-agent@v3": {
      "overall": { "episodes": 4, "finished": 4, "successes": 3, "success_rate": 0.75 },
      "holdout": {
        "episodes": 4,
        "finished": 4,
        "environment_errors": 0,
        "successes": 3,
        "success_rate": 0.75,
        "hard_violation_episodes": 0,
        "false_completions": 1,
        "duplicate_effects": 0,
        "recovered": "2/2",
        "unnecessary_interruptions": 0,
        "rejected_attempts": 1,
        "mean_reward": 0.75,
        "cost_usd": 0.0712,
        "tokens": 41250
      },
      "per_scenario": { "<job_slug>": { "episodes": 2, "successes": 1 } }
    }
  },
  "overall": { "episodes": 4, "finished": 4, "successes": 3 }
}

The numbers are an example. overall and each entry of per_scenario have the same fields as holdout: the example shortens them. A split appears only when the run has episodes of it. success_rate is null when no episode was scored.

Choose the thresholds

  • Use counts as well as the share. With 2 jobs and 2 repeats, one episode is 25 points. Ask for more repeats, or compare with the last result, before you block a merge on a small difference.
  • Treat a rule violation as a failure, always. A verified share of 90% with one broken rule is not a pass.
  • Do not count episodes that were not scored. environment_errors are the environment's fault. The gate reports them and does not fail on them, unless nothing at all was scored.

Keep the cost down

DoWhy
Run only the holdout splitIt is the score that matters, and it is the smallest set
Run only when the agent's files changeThe paths filter in the workflow
Give the run a budgetThe run stops itself at --budget
Cancel a run that a newer push replacesThe concurrency block in the workflow

A pull request that does not change the instructions reuses the existing version, and the gate then runs it alone, without a baseline.

Do not tune on holdout

If you change the agent again and again until this check passes, the holdout jobs become jobs you tuned on, and the score no longer tells you how the agent does on new work. Read failures on dev, improve there, and let the check confirm it. Build a new world version from time to time to get fresh jobs.

When the check cannot run

The gate printsMeaningDo this
could not run: HTTP 402The plan's episodes or allowance are used upAdd a top-up, or wait for the month to renew
could not run: HTTP 429Every sandbox of the plan is in useRun again later. Limit CI to one run at a time
could not run: HTTP 401The key is wrong or revokedReplace the secret
could not run: HTTP 409The world version is not publishedFix REHEARSAL_WORLD_VERSION
The run did not finish (failed)The server could not run itOpen the run page. See Read results

Next

Checked against rehearsal-kit 0.1.4 on 27 October 2026.

Was this page helpful?

Edit this page

On this page

Was this page helpful?

Edit this page