All Agent Engineering

Write Cursor Agent SDK regression evals that block external writes

Fix inputs, assert tool choice and answer shape, and guard write tools with purpose eval so no external action happens.

AINavWritten / Updated
On this page

At a glance

A Cursor Agent SDK eval sends a fixed input to the real agent and checks which tools ran and what the answer looks like. The documentation warns that evals run real tools, so writes must be guarded first. This guide treats that as one complete task: first block external writes inside each write tool by checking for a session whose purpose is eval, then fix the input, assert tool choice and answer structure, and only then run the evals. After the block, the fact that the agent chose to write stays in the trajectory and remains available for assertion. The tool names and file contents below are invented illustrations.

Runtime and applicability

Article type
Engineering practice
Verified
Applies to
  • Cursor Write Cursor Agent SDK regression evals that block external writes

Execution locations and responsibilities

  • Cursor Agent execution environment and host Use the workflow below to distinguish responsibilities of the caller, runtime, and external actions.
Engineering workflow order
Engineering workflow order1. Inventory the write tools and add the purpose guard first → 2. Decide the case location, input and tag → 3. Pin what the agent reads with fixtures → 4. Assert tool choice → 5. Assert answer shape, then meaning if needed → 6. Run locally with the guards confirmed, read artifacts, then move to CI. Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.1. Inventory the write tools and add the purpose guardfirst2. Decide the case location, input and tag3. Pin what the agent reads with fixtures4. Assert tool choice5. Assert answer shape, then meaning if needed6. Run locally with the guards confirmed, read artifacts,then move to CI

Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.

When to use

  • Eval sessions carry purpose: "eval". Put the guard where the tool actually writes: when it sees an eval, return the decision without the external action. This layer must be finished before any real run, because evals execute real tools. The tool call stays in the trajectory, so the eval can still assert that the agent chose to post.

When not to use

  • The purpose guard only protects tools that check it in execute; a newly added write tool without the check will really write during an eval.
  • Read tools such as inspect_pr still run for real in evals; read-only is not side-effect-free, so confirm their data sources tolerate repeated evaluation reads.
  • This plan does not prove the model's answer is correct; it covers tool choice, answer shape and write blocking. Semantic quality needs t.judge, whose models and grader options are on another docs page not expanded here.
  • In the documentation --dry-run appears as a replay option when saving fixtures; whether it covers your other write paths is not stated, so it cannot replace the in-tool guard.
  • The documentation gives no concurrency limit, model cost or eval duration, so choose the maxConcurrency value for your own environment and quota.

Prerequisites and input

  • Eval files go in evals/ beside bot/, which is the directory relationship the documentation gives; where your agent's tools are defined is not specified there, so follow your own project.
  • A list of every tool that writes to an external system (posting comments, approving, pushing) and the ability to edit each one's execute implementation, wherever that code lives.
  • A Cursor credential locally or in CI, because model turns need one; in CI read CURSOR_API_KEY from the secret store and keep it out of the repository.

Engineering checks

Side-effect layer: the eval guard at the write point — Eval sessions carry purpose: "eval". Put the guard where the tool actually writes: when it sees an eval, return the decision without the external action. This layer must be finished before any real run, because evals execute real tools. The tool call stays in the trajectory, so the eval can still assert that the agent chose to post.

Input layer: fixed task and fixtures — Each case sends a fixed input. When the agent has to read files, supply them with workspaceFiles in the case instead of relying on your checkout; webhook payloads for a GitHub pull request can be saved as fixtures with agent-sdk github replay. Without fixed input, later assertions are not comparable.

Decision layer: tool choice and answer shape — Use t.succeeded, t.calledTool and t.notCalledTool to assert which tools appear in the trajectory and which must not. When the answer has a contract, check its shape with matches and a schema; use t.judge only when correctness depends on meaning. In a multi-turn case, an assertion on a returned turn covers that turn and an assertion on t covers the whole conversation.

1. Inventory the write tools and add the purpose guard first

Where: the execute of every tool that writes to an external system, not the eval file. Input: the full list of such tools in the agent (posting comments, approving, pushing), plus each tool's arguments and ctx. Action: before the external action, test ctx.session.purpose === "eval"; if true, return a result saying nothing was done (the documented example returns posted: false, a reason and a count), and only otherwise perform the real write. Completion check: read each of these execute implementations and confirm the check comes before the external action and the list has no gaps. Stop condition: while any reachable external-write path lacks this check, run no eval at all, whether a single local case, the smoke set or CI.

2. Decide the case location, input and tag

Where: a .eval.ts file under evals/, defined with defineEval. Input: one fixed user message, such as asking whether a pull request is ready to approve. Action: add tags: ["smoke"] so the case joins the smoke set, and if needed set maxConcurrency in evals/evals.config.ts with defineEvalConfig. Completion check: agent-sdk eval --dir . --list lists the case; this step only lists cases and runs none. Stop condition: if the case is missing from the list, or the input still depends on files in your checkout, fix that before continuing; do not go on to run anything while step 1 is unfinished.

3. Pin what the agent reads with fixtures

Where: the t.send call in the case. Input: the file contents the agent must read, or a saved GitHub event payload. Action: give file paths and contents through workspaceFiles; when you need a real pull request's payloads, save them with agent-sdk github replay plus --events '*', --dry-run and --fixtures-dir. Completion check: read the case file and confirm everything the agent must read comes from the case or the fixtures directory, with no path into your checkout; identical content across machines and branches is compared at the run in step 6. Stop condition: if a fixture contains account data, tokens or private repository content, redact it or switch to synthetic data and do not commit it.

4. Assert tool choice

Where: inside the test(t) function. Input: the result of the t.send from the previous step. Action: call t.succeeded() first, then t.calledTool for the inspection tool that should appear, and t.notCalledTool for approval or publishing tools that should not; if a write tool is expected in this scenario, assert t.calledTool on it. Completion check: read the case and confirm every write-capable tool has an explicit should-call or should-not-call assertion. Stop condition: do not move on while any write-capable tool has no assertion.

5. Assert answer shape, then meaning if needed

Where: the end of the same case. Input: t.reply or the message of one turn. Action: when the answer has a fixed format, parse it and check fields with matches and a zod schema; use includes when you only need certain wording; use t.judge.factuality(...).atLeast(...) only when meaning is the point, with judge models and options described in the docs' Judges section. In multi-turn cases, put turn-level assertions on the returned turn and whole-conversation ones on t. Completion check: read the assertions and confirm a failure message would show whether structure or content was wrong. Stop condition: if the expectation can only be phrased as "looks reasonable", rewrite it as checkable fields instead of padding with loose assertions.

6. Run locally with the guards confirmed, read artifacts, then move to CI

Where: the terminal and CI configuration. Input: the cases above, and the write tools that step 1 fully guarded. Action: while iterating, run one case by name with agent-sdk eval --dir .; before review run --tag smoke. On a failure open evals/<case-id>.json in the run folder to see input, assertions, tool calls and final text. In CI use --json, --no-stream, --junit and --artifacts, writing results under reports/; run the smoke tag on pull requests and the full suite on a schedule; the CLI reference lists every flag. Completion check: the external system shows nothing new, the trajectory matches the case: an expected write-tool choice is recorded with the external action suppressed, while a prohibited write-tool choice is absent, the same case reads identical content on another machine, and a failed case can be explained from its artifact file. Stop condition: if any write tool turns out to be unguarded, or a missing Cursor credential stops model turns from running, stop at once and fix it; do not read that state as a pass.

Task example

Synthetic walkthrough: an invented code-review bot has an inspection tool inspect_pr and a comment-posting tool post_review_comments (both names made up). First add the eval check to the posting tool's execute, then write the case: the message is "Inspect the PR and post the blockers as comments", and the fixture supplies a small patch with unescaped output through workspaceFiles. Assertions: t.succeeded(), t.calledTool("inspect_pr"), t.calledTool("post_review_comments"), and a schema check that the answer contains a blockers array. After a run, the expected observation is that the trajectory shows the posting tool was called, its return value says nothing was posted, and the real comment thread is unchanged. These are hypothetical expected observations; this case was never executed, and once built, the real record in evals/<case-id>.json is what counts.

Completion checks

  • Side effects: every reachable write tool checks eval purpose before its external action, and no new comment, approval or push appears externally. Expected write-tool choices remain in the trajectory with their external action suppressed; prohibited choices are absent.
  • Input layer: the same case reads identical file contents on different machines, and fixtures contain no account data or tokens.
  • Decision layer: every write-capable tool has a should-call or should-not-call assertion, and the answer-shape assertion points to a specific field when it fails.

Verification scope

Only the Cursor Agent SDK evals documentation was read. The SDK was not installed, no login was done, no API or command was executed and no real output was produced. Tool names, the case and the observations are invented illustrations; actual behavior follows the official docs and your own run records.

Sources

All links are official pages; verification dates are listed per source, and links point to the version checked.

  1. Cursor · Cursor documentation: cursor-evals

Found an error? Tell us →