Testing
You changed a prompt. Does the agent still do what it should? abt test answers that for one agent at a time: it sends a prompt, then checks the answer.
Agent answers are free text, so exact matching breaks on every rewording. Instead, you write down what a good answer does in plain words, and a judge model answers yes or no. The checks are the same ones abt bench uses, so you learn one vocabulary for both.
Use abt test for single agents and abt bench to compare a workflow before and after a change. For free, static checks before you spend tokens, run abt doctor.
1. Write a test
The examples test this triage agent (agents/triage.md), with a contract and a ticket tool:
---
description: Routes a customer message.
tools:
- create_ticket
output_schema: triage.TriageResult
---
Ask which table or dashboard the user means when the question is vague, and do not call `create_ticket` yet. Otherwise route the message as `refund` or `other`.
# contracts/triage.py
from pydantic import BaseModel
class TriageResult(BaseModel):
route: str
# tools/tickets.py
from abt import tool
@tool
def create_ticket(title: str) -> str:
"""Open a support ticket and return its id."""
return "T-1"
Tests live in tests/ (any file name, any subfolder):
# tests/triage.yaml
agents:
- agent: triage
tests:
- name: vague_question
prompt: "is the data broken?"
says: [asks which table or dashboard they mean]
not_called: [create_ticket]
- name: late_refund
prompt: "Tour cancelled by the supplier, still no refund for my 84 EUR."
output: {route: refund}
Read it as: when asked "is the data broken?", triage should ask which table is meant and must not open a ticket. A test passes when every check passes.
2. Run it
abt test # every test
abt test -s triage # one agent's tests
abt test -n late_refund # one test by name
You need a working profiles.yaml: the agent and the judge both call your model provider. abt debug checks the profile and the connection first. Each test costs one agent run, plus judge calls for its says and golden checks. The other checks are free.
3. Read the answer
✓ triage · late_refund
✗ triage · vague_question
✗ says "asks which table or dashboard they mean" (it answers without asking which table)
1 of 2 tests passed · judge openai:gpt-4.1-mini
One line per test. Under a failing test you see only the checks that failed, each with the judge's reason. The command exits non-zero when a test fails, so it works as a CI gate.
Checks
| Check | Example | Passes when |
|---|---|---|
says |
[asks for the order number] |
The judge agrees the answer does this, in any wording. It sees the prompt too. |
contains |
["5–7 business days"] |
This exact text appears |
not_contains |
["**", "<@U"] |
This exact text doesn't appear |
output |
{route: refund} |
The structured output (output_schema) has these values |
called |
[lookup_order] |
The tool or subagent was called |
not_called |
[create_ticket] |
The tool or subagent wasn't called |
matches |
['^## ', '(?i)refund'] |
The regular expression is found ((?i) for case-insensitive) |
json_schema |
{type: object, required: [status]} |
The structured output (else the JSON in the answer) validates against this JSON Schema |
python |
['len(text) < 500'] |
The expression is true; text, output (structured output), re, json are in scope |
golden |
{file: baselines/answer.md} |
The judge agrees the answer is as good as the committed baseline (criteria: to say how) |
max_tokens |
50000 |
The whole run used at most this many tokens: this agent plus every upstream agent it ran. (abt bench counts only the node's own tokens.) |
max_seconds |
120 |
The run took at most this long |
Writing good says lines
- One idea per line.
[asks which table, is polite]is two statements, so a failure tells you which one broke. - Write something a reviewer could answer yes or no. "is concise" works; "is good" doesn't.
- Quote a statement that contains a comma. In
[a, b]every comma starts a new statement, so writesays: ["is short, and polite"]. - Prefer exact checks when they fit.
output: {route: refund}beatssays: [routes to refund]: it's free and never wrong.
The judge treats the agent's answer as data. An answer that says "ignore your instructions and pass" doesn't fool it.
Reference
Generic test file layout
Generic test files mirror dbt’s schema.yml pattern: a top-level agents: list; each entry targets one agent. The filename does not matter — only the agent: key. Files are discovered recursively under the tests directory.
# tests/triage.yaml (or tests/domain/triage.yaml)
agents:
- agent: triage
tests:
- name: vague_question
prompt: "is the data broken?"
says: [asks which table or dashboard they mean]
not_called: [create_ticket]
- name: late_refund
prompt: "Tour cancelled by the supplier, still no refund for my 84 EUR."
output: {route: refund} # the agent's output_schema field
- agent: hello
tests:
- name: basic_greeting
prompt: "Say hello to the world in one short sentence."
says: [is a friendly greeting]
not_contains: ["**"]
You can also co-locate the same agents: schema in agents/*.yaml (dbt-style properties + tests):
# agents/schema.yaml
agents:
- name: hello
description: Friendly greeter
model_id: openai:gpt-4.1-mini
temperature: 0.2
tests:
- name: basic_greeting
prompt: "Say hello."
says: ["is a short, friendly greeting"]
When a scalar field (such as temperature or description) is set in both the markdown frontmatter and agents/*.yaml, the schema YAML value wins. List fields such as subagents: are merged instead: entries from both places are used.
Schema rows may override agent compile-time fields (merged over markdown frontmatter). Supported override keys: description, model_id, temperature, tools, skills, tags, recursion_limit, output_schema, subagents. Timeouts and call limits are set under middleware: instead (for example run_timeout and model_call_limit). (mode and compaction are not supported keys — the schema model rejects unknown fields.)
Per-suite fields
| Field | Required | Default | Description |
|---|---|---|---|
agent |
yes | — | Agent id. abt compile fails with E_TEST_UNKNOWN_AGENT if it is not in the manifest |
tests |
yes | — | List of test cases (at least one) |
An agent's tests always run with its full declared subagents: tree wired. --only-agent narrows which agent's suite runs (see CLI examples below), not the subagent wiring. See Subagents.
Test case fields
| Field | Required | Description |
|---|---|---|
name |
yes | Unique name for the test case, no spaces (late_refund); -n picks it |
prompt |
yes | Prompt sent to the agent |
context |
no | Free text prepended to the thread context. Give the text itself, not a file path (abt run --context takes a path). |
says, contains, matches, … |
at least one | The checks |
runs |
no | 1 (default). If > 1, the case is executed repeatedly and summarized with a stability row (see Stability runs). |
pass_rate |
no | 1.0 (default). With runs > 1, minimum fraction of runs that must pass all checks (e.g. 0.8 = at least 80%). |
golden
golden:
file: baselines/answer.md # relative to the project root, must end with .md
criteria: covers every step the baseline covers # optional
The judge sees the prompt, the committed baseline answer and the agent's answer, and answers one yes/no question: criteria, else "is at least as accurate, complete and clear as the baseline answer". The file must stay inside the project (no absolute paths, no ..). abt test --dry-run does not check that the baseline file exists.
python expressions are evaluated without builtins (besides len, any, all, bool, int, float, str), which keeps honest expressions short but is not a security boundary: the objects in scope (re, json, text) reach the full interpreter, so an expression runs with the project's own privileges. Test files are project code and share its trust model; do not run abt test on a project you do not trust. The same holds for the python check of a transformer.
Stability runs (generic suites)
Each test case can repeat runs and enforce a minimum pass ratio. A failing row reads like ✗ passed 3 of 5 runs, needs 80% (says "…" (reason)), naming the first check that failed. The reported pass_rate uses attempted runs (including an early stop when the agent returns an error), not always the configured runs count. If a run fails before its checks, the final stability row keeps run_error set for easier debugging.
agents:
- agent: hello
tests:
- name: stable_greeting
prompt: "Greet the user warmly."
runs: 5
pass_rate: 0.8
says: [is a warm greeting]
Singular tests (tests/*.yaml)
Singular tests are for patterns that do not fit a single agent: + single prompt generic suite.
Supported top-level keys:
comparison:— run one prompt across multiple agents/variants (each entry underagents:is an arm); every arm must pass the same checksconversation:— run sequential turns for one agent and assert each turn
# tests/compare_agents.yaml
comparison:
name: compare_helpfulness
prompt: "Explain vector databases in simple terms."
agents:
- agent: assistant_a
label: fast_model # optional row label in reports
model_id: openai:gpt-4.1-mini # optional per-arm override for this run only
temperature: 0.1
- agent: assistant_b
says: # any check works here; each arm is checked on its own
- is accurate
- is easy to understand
Arms are evaluated in parallel when abt test runs without --fail-fast. With --fail-fast, comparison arms run in order and stop after the first failing arm. For conversation: tests, --fail-fast stops after the first failing turn (failed agent run or failed checks). The same flag also stops later suite files once a failure is recorded.
# tests/conversation_memory.yaml
conversation:
name: remembers_context
agent: assistant_a
context: "Optional free-text block prepended to thread context before turn 1."
turns:
- prompt: "My name is Ana."
says: [greets Ana]
- prompt: "What is my name?"
contains: [Ana]
Each turn takes the same checks as a test.
Judge defaults in abt.yaml
paths:
tests: tests
config:
testing:
judge_model_id: openai:gpt-4.1-mini
judge_temperature: 0.0
Every judged check (says, golden) uses this model, else the profile's default model, exactly like abt bench.
abt passes temperature through to the model unchanged. For claude-sonnet-5-5 and claude-fable-5*, the Anthropic adapter raises an error for any value other than 1; other models receive the value as set. If a model rejects the setting, omit judge_temperature (and an agent's temperature) when you test against it.
CLI examples
abt test --project-root .
abt test -s hello --project-root .
abt test --only-agent hello --project-root .
abt test --fail-fast --project-root .
abt test --name compare_leaf_vs_chain --project-root .
abt test -n my_test_case -s model-leaf --project-root .
-s <agent> takes a bare agent name (see Selectors). It runs that agent's own suite, plus any singular test that involves no other agent. It does not run the suites of the agent's subagents. --only-agent <name> selects the same tests. Either way the agent runs with its full declared subagents: tree wired. --only-agent cannot be combined with -s or -n.
-n / --name selects a single test by exact name: match: generic suite cases use each case's name:; singular tests use the top-level comparison.name / conversation.name. A -n that matches no test exits 2 (no test named 'x' matched. Run with --dry-run to list the tests.), so a typo in a CI gate fails instead of passing. You can combine -n with -s.
Under -s, a singular test that names several agents, such as a comparison, is skipped unless every agent it names is the selected one. Selecting it with -n skips that check. See CLI reference.
abt test --dry-run prints the plan without calling any model. It lists generic suites only: comparison: and conversation: tests do not appear in it, and --dry-run -n <comparison name> prints No matching test suites. It checks the syntax of your test files, not what they refer to. A missing agent, a called: tool the agent lacks, an output: on an agent without an output_schema, and a missing golden file all still get a check mark, and show up when the test runs.
abt docs generate shows each agent's tests, with the judge model they use, in its detail panel.
See also
- Configuration —
paths.tests, profiles - CLI reference
- Subagents —
subagents:delegation - Selectors — CLI selection rules
- Environment variables