To test an AI agent in CI, run it on a fixed, versioned set of tasks in environments that reset to the same state every time, grade each episode with a verifier that checks what changed, write the results as JUnit so your CI shows each task as a test, and fail the build when the pass rate drops below a threshold set just under your current score. Treat safety failures, such as obeying an instruction planted in the app’s data, as a separate gate with no tolerance.
Why aren’t unit tests enough for agents?
An agent’s behaviour comes from a model, a prompt, tool schemas and a framework, and any of them can change the twelfth tool call of a task without changing a line of your code. Typical regressions come from a model upgrade, an edited system prompt, a renamed tool argument, new retrieval data or a framework update. Unit tests check that functions return what they should. Agent tests check that multi-step work ends in the right state, without side effects.
Two kinds of test belong in CI, and they complement each other:
- Output evals: a prompt and an expected answer, graded by code, an LLM judge or a person. Cheap enough for every pull request. Platforms such as Braintrust, LangSmith and Langfuse run these and post results on the pull request.
- Scenario tests: the agent works through a task in a working app, and a verifier reads the app’s final state. Slower, and the only way to see what the agent actually did.
What should the CI job run?
- A frozen suite. The same tasks every run, so scores compare. New tasks make a new suite version, not a silent change to the old one.
- Pinned everything else: environment versions, model id and settings, prompt, step budget and time limit.
- Deterministic environments. A seed fixes the starting state, so any difference between runs comes from the agent.
- A mix of tasks: easy ones that must always pass, hard ones that track progress, and safety cases such as planted instructions, policy traps and requests that leave out a detail only the user knows.
- Your deployed agent, not just the model. Point the test at a preview deployment so the prompt, tools and retrieval are the ones you ship.
How do you grade agent runs automatically?
Grade the state, not the transcript. An agent can say it refunded the right order and refund another one. A verifier that reads the app after the episode checks the outcome (exactly one refund, this amount, to this account) and the footprint: nothing changed that a correct solution wouldn’t change. Each check should come back with a label and a detail, so a failing test explains itself. Keep LLM judges for prose; as a gate on actions they can be argued with.
Then give every failure one main reason. Common ones:
| Reason | Kind |
|---|---|
| Wrong or unfinished result | Capability |
| Didn’t ask when a detail was missing | Capability |
| Ran out of steps or time | Capability |
| Broke a rule the policy sets | Safety |
| Changed things nobody asked for | Safety |
| Obeyed an instruction planted in the app | Safety |
| Model API error | Infrastructure |
How do you set a pass threshold without flaky builds?
- Measure the noise first. Run the same commit two or three times. The spread you see with no change is the room the threshold needs.
- Count in tasks. With n tasks at one seed, each task is worth 100/n points: about 3 points with 32 tasks. A few tasks flipping between identical runs is normal.
- Set the threshold a little below today’s score, by the noise you measured, then raise it as the agent improves. It works as a ratchet: up, never down without a reason written in the pull request.
- Add seeds when the margin matters. Three seeds triple the episodes and steady the score, at three times the cost.
- Compare paired results. Because tasks and seeds are identical, look at which tasks flipped, not only the total. An aggregate over 30 episodes at a 50% pass rate has a 95% interval of roughly ±18 points; a list of flipped tasks is far more informative.
Which failures should block a merge?
Capability failures go against the threshold: an agent that gets a little worse at hard tasks may still be worth shipping. Safety failures usually shouldn’t: one obeyed planted instruction, one payment the policy forbids, or one change nobody asked for is a reason to stop. Gate on them separately, at zero. Infrastructure errors are the third case: count them as failures in the score (an agent whose endpoint errors isn’t passing) but report them apart, so a provider outage doesn’t read as a regression.
What does it cost, and how often should it run?
- Model tokens. Long tasks take 20–40 tool calls, each a model turn. Runs use your own model key or endpoint, so the cost lands with your provider.
- Time. Episodes run in parallel, but a long task can take minutes. Set per-episode time limits and a job timeout.
- Cadence. A few smoke tasks on every pull request; the full suite on release candidates and nightly; and a required check on the release branch.
- Secrets. Pull requests from forks don’t get your secrets, so the job should stop cleanly there rather than fail.
What does it look like in GitHub Actions?
With Sandworld’s Python client, sw eval starts a run on Sandworld’s servers, prints progress, writes JUnit XML and a Markdown scorecard, and exits 1 below --min-pass. The step, abbreviated from the CI docs:
- run: pip install https://sandworld.dev/files/sandworld-python.tar.gz
- name: Bench Hard
env:
SANDWORLD_API_KEY: ${{ secrets.SANDWORLD_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
sw eval --suite hard --model openai:gpt-5 --key-env OPENAI_API_KEY \
--min-pass 0.4 --junit sandworld-junit.xml --report sandworld-report.mdA JUnit reporter action then shows each task × seed as a test, with the verifier’s failed checks as the failure message, and the scorecard lands in the job summary. For your own agent, pass --endpoint with an OpenAI-compatible URL. The run API also returns failure counts by reason, so a short script can gate on safety failures independently of the pass rate. A badge shows the latest score in your README.
A checklist for agent tests in CI
- A frozen, versioned task suite, with safety cases.
- Environments that reset to an exact state from a seed.
- Verifiers that read state and the action log, with labelled checks.
- JUnit output: one test per task and seed, failure reasons in the message.
- A pass-rate threshold below today’s score by the measured noise, raised over time.
- A zero-tolerance gate on safety failures.
- Infrastructure errors reported apart from regressions.
- Output evals on every pull request; scenario tests on release candidates and nightly.
Try one task without an account in the sandbox, or read how to evaluate AI agents for the metrics behind the threshold.
