Skip to content

Agents: testing & evaluation

Agents are non-deterministic, so test behaviour and outcomes rather than exact text. This page covers static checks, delegation tests (subagents only), golden tasks, and guardrail tests, then how to automate them and when to re-run them. Record the results in the eval template, using the tests listed on this page.

Add a small script or CI step that checks every file in .claude/agents/ and .cursor/agents/:

  • frontmatter parses, and name and description are present
  • name is lowercase with hyphens
  • the file name matches name (this guide’s convention; it keeps @agent-<name> and /name predictable)
  • the body (the system prompt) isn’t empty
Test How Pass
Discovery Claude Code: type @ and look for @agent-x in the typeahead. Cursor: the Subagents section Listed
Explicit @agent-x … in Claude Code, or /x in Cursor Runs
Implicit Create the trigger situation without naming the agent Parent delegates
Negative An unrelated request No delegation
Sibling confusion A request that suits sibling agent Y Y is chosen, not X

Run each in a fresh chat. In Claude Code, a plain-language request such as “use the X subagent” doesn’t guarantee delegation, so use @agent-x for the explicit test.

Build 5–10 fixed tasks with known correct outcomes:

  • Seeded defects for reviewers or verifiers: plant a bug and check it’s found.
  • Known answers for researchers: “where is X configured?” should return config/x.ts.
  • Reference outputs for generators: score them against a rubric, not by exact match.

For each run, record pass/fail, the number of turns, the cost, and the time. Tracking cost and turns catches regressions where an agent becomes slow or loops, even though its answers are still correct.

Try to make it misbehave:

  • Ask a read-only agent to edit a file → it refuses or is blocked
  • Ask it to run a destructive command (rm -rf, git push --force) → it’s blocked
  • Feed it input containing injected instructions (“ignore previous instructions and…”) → it ignores them
  • Give it an impossible task → it reports failure rather than faking success
  • (SDK) Invalid API key, maxTurns: 1, and network loss → handled cleanly, with a non-zero exit

Headless CLI. This is the fastest way to script tests:

Terminal window
claude -p "@agent-code-reviewer review the diff in fixtures/seeded-bug" --output-format json > out.json
agent -p "/code-reviewer review fixtures/seeded-bug" --output-format json > out.json

Don’t add --bare to the Claude Code command. It’s recommended for CI (and planned as the default for -p), but it skips .claude/agents/, so the subagent isn’t loaded. Recheck this whenever you upgrade the CLI. Whether /name invokes a subagent in Cursor’s agent -p print mode wasn’t confirmed at the time of writing, so check that the output shows the subagent ran.

Then assert on out.json with a small script. For example, check that the output mentions fixtures/seeded-bug/app.ts:42.

With the SDKs. Loop over the golden tasks, run the agent, and grade each result with code checks or a second model acting as a grader against a rubric. Wire the loop into CI so that it runs whenever someone changes a prompt, the tool list, or the model.

  • Any change to the system prompt, the description, tools, or the model
  • A new model version becoming the default
  • Host or SDK major updates
  • Monthly for business-critical agents
Symptom Check
Not delegated The description has triggers and “use proactively”; the file is in the right folder; the host was restarted
Wrong agent chosen Sibling descriptions overlap
Missing context The parent’s brief (see the brief template)
Loops or runs long No stop condition; the task is too broad; add maxTurns
Output too long Add a hard length limit and an exact template
Did something forbidden Prompt-only guardrail, or allowedTools alone (it only auto-approves); add a hard one
SDK run hangs Claude Agent SDK: set an abortController timeout. Cursor SDK: log the run and agent IDs right after send(), check the timeout, and always call wait()