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
- 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.
- It makes the baseline the same way, from the same file on
main. - It starts one run with both versions, so both get the same jobs at the same time.
- It waits for the run and checks the result.
The change passes only when all of these hold:
| Check | Default |
|---|---|
Verified success reaches min-success | No minimum |
Episodes with a rule violation stay at or under max-violations | 0: any broken rule fails |
Verified success is not lower than the baseline's, minus tolerance | 0 |
| No more rule violations, false completions or duplicate side effects than the baseline | Always on with a baseline |
| At least one episode was scored | Always 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 listKeep 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
| Input | Meaning |
|---|---|
api-key | Required. A key with Build and evaluate access |
world-version | Required. The published world version |
prompt-file and name | The instructions file and the agent's name. Or give profile, a profile id |
baseline-ref | A git ref whose prompt-file is the baseline, for example origin/main. Or give baseline, a profile id |
splits | Comma-separated: train, dev, holdout. Empty runs every split |
repeats | Attempts at each job. Default 1 |
min-success | Fail below this verified success rate, from 0 to 1 |
max-violations | Fail above this many episodes with a rule violation. Default 0 |
tolerance | How far below the baseline's success rate still passes. Default 0 |
timeout-minutes | How long to wait for the run. Default 90 |
server | Default 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 2It 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_errorsare the environment's fault. The gate reports them and does not fail on them, unless nothing at all was scored.
Keep the cost down
| Do | Why |
|---|---|
Run only the holdout split | It is the score that matters, and it is the smallest set |
| Run only when the agent's files change | The paths filter in the workflow |
| Give the run a budget | The run stops itself at --budget |
| Cancel a run that a newer push replaces | The 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 prints | Meaning | Do this |
|---|---|---|
could not run: HTTP 402 | The plan's episodes or allowance are used up | Add a top-up, or wait for the month to renew |
could not run: HTTP 429 | Every sandbox of the plan is in use | Run again later. Limit CI to one run at a time |
could not run: HTTP 401 | The key is wrong or revoked | Replace the secret |
could not run: HTTP 409 | The world version is not published | Fix REHEARSAL_WORLD_VERSION |
The run did not finish (failed) | The server could not run it | Open the run page. See Read results |
Next
Was this page helpful?
Bring your own agent
Test agent code that you run yourself, in any framework. Rehearsal sends each turn over the API, and your agent answers with one action.
AI assistants
Let Claude Code, Codex, Cursor and other assistants build worlds, run evaluations and explain results for you. What the plugin installs, and what an assistant may do.