Skip to content
Sandworld

Search the docs and guides

    Evaluation

    How to test an AI agent in CI

    Run a frozen task suite in resettable environments on every release, grade it with verifiers, report JUnit and fail the build below a pass rate you set.

    By the Sandworld teamUpdated 6 min read

    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:

    ReasonKind
    Wrong or unfinished resultCapability
    Didn’t ask when a detail was missingCapability
    Ran out of steps or timeCapability
    Broke a rule the policy setsSafety
    Changed things nobody asked forSafety
    Obeyed an instruction planted in the appSafety
    Model API errorInfrastructure

    How do you set a pass threshold without flaky builds?

    1. 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.
    2. 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.
    3. 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.
    4. Add seeds when the margin matters. Three seeds triple the episodes and steady the score, at three times the cost.
    5. 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.md

    A 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

    1. A frozen, versioned task suite, with safety cases.
    2. Environments that reset to an exact state from a seed.
    3. Verifiers that read state and the action log, with labelled checks.
    4. JUnit output: one test per task and seed, failure reasons in the message.
    5. A pass-rate threshold below today’s score by the measured noise, raised over time.
    6. A zero-tolerance gate on safety failures.
    7. Infrastructure errors reported apart from regressions.
    8. 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.

    Frequently asked questions

    How do you test an AI agent in CI?

    Run the deployed agent on a fixed, versioned set of tasks in environments that reset to the same state each time, grade each episode with a verifier that reads the final state, write JUnit XML so CI shows each task as a test, and fail the build below a pass-rate threshold. Gate safety failures separately.

    How do you avoid flaky agent tests?

    Pin the model, prompt and environment versions; use environments that reset to an exact state from a seed; measure how much the score moves when you rerun the same commit; and set the threshold below today’s score by that much. More seeds make the score steadier.

    Should agent tests run on every pull request?

    Run a few fast smoke tasks on every pull request, and the full suite on release candidates and nightly. Long agent tasks take minutes each and use model tokens.

    Can an LLM judge be a CI gate for agents?

    For prose, with care. For actions with observable effects, such as payments or records, check the app’s state instead: it’s exact, cheap and can’t be argued into a pass.

    What output format do CI systems understand?

    JUnit XML. GitHub Actions (through a reporter action), GitLab and most other CI systems show each testcase as a test, so one testcase per task and seed, with the verifier’s failed checks in the message, makes failures readable.

    Try it

    See every idea here in a working environment.

    The examples come from real Sandworld tasks. Play one in your browser — every tap is the tool call an agent would make — then read the verifier’s check-by-check verdict.