# Agent evaluations

**Last updated:** 2026-11-27T14:39:27-03:00 (UTC-3)

An agent evaluation answers one question with numbers: which agent configuration or model solves your tasks most often, and at what cost per solved task. You write the tasks once, with the checks that decide whether each attempt succeeded; the runner in the Python client runs every task against every target a few times, checks each outcome on your machine, and records it in the gateway. The gateway reads the cost, tokens and model calls of each attempt from its own request log and answers a scorecard per target.

The runner executes **on the client**, in your environment. No agent code and no check runs in the gateway, and the runner never runs a command that came from the gateway: command checks come only from your own task file.

| Flag | What it turns on | Requires |
| --- | --- | --- |
| `agent_evaluations` | `POST /v1/agent-evals`, `POST /v1/agent-evals/{id}/results`, `GET /v1/agent-evals/{id}`, the console scorecard on each of the evaluation's runs, and an attempt's trace named as its experiment item | `experiment_traces` and `evals_public_api` (and `span_store` to store the traces) |

The flag is a tenant resource, off by default, with a plan right of the same name: with `feature_plan_entitlements` on, a team runs agent evaluations only when its plan includes both `agent_evaluations` and `experiment_traces`. No new permission: the key needs the scopes `evals:read` and `evals:write` (and `evaluators:read` for judge checks that use a team evaluator), and a console reader needs `evals:read` over the team.

## Turn it on

1. Turn on the flags in `features` (YAML, `PUT /api/admin/settings/features` or **Settings → Features**):

   ```yaml
   features:
     evals: true
     evals_public_api: true
     evaluation_results: true
     evaluation_tracing: true
     experiment_traces: true
     span_store: true
     agent_evaluations: true
     # Recommended when a target streams (the Claude Agent SDK always does):
     stream_usage: true
   ```

   `stream_usage` lets the gateway read the token counts a provider reports at the end of a streamed answer. Without it a streamed call is recorded with unknown tokens and unknown cost, and the scorecard says so (never zero).

2. Create a key of the team that will own the results, with the scopes `route:chat` (or `route:*`), `evals:read`, `evals:write` and, for judge checks through a team evaluator, `evaluators:read`; allow it the model aliases your targets and judges call.

3. Install the Python client (Python 3.11 or later; no dependency of its own) and, only for the targets that use them, the agent SDKs:

   ```bash
   pip install ./clients/python            # m7gtw_prompts
   pip install claude-agent-sdk==0.2.189   # targets of kind claude_agent_sdk (the version tested)
   pip install openai-agents==0.26.0      # targets of kind openai_agents_sdk (the version tested)
   ```

## Write the tasks

A task file is TOML or JSON. It names the evaluation, the dataset the tasks are kept in, the number of trials, the targets and the tasks with their checks.

```toml
name = "support agent"     # the run names start with it; --name sets the whole name
dataset = "agent-tasks"     # a dataset of the team that the runner keeps
trials = 3                  # 1-10 attempts of every task on every target
max_concurrency = 4         # trials at once (1-64)

[[targets]]
label = "small"             # 1-40 letters, digits, dot, dash, underscore
kind = "model"
model = "gpt-small"         # a model alias of the gateway
[targets.settings]
max_turns = 6

[[targets]]
label = "claude-agent"
kind = "claude_agent_sdk"
model = "claude-fast"
[targets.settings]
max_turns = 8
allowed_tools = ["Read", "Write", "Edit"]

[[tasks]]
id = "capital"
prompt = "What is the capital of France? Answer in one word."
expected = "Paris"
[[tasks.checks]]
kind = "predicate"
op = "contains"
value = "Paris"
[[tasks.checks]]
kind = "judge"
model = "judge"
criteria = "The answer names the capital and nothing else."

[[tasks]]
id = "write-file"
prompt = "Write the word done into answer.txt."
timeout_s = 120
files = { "README.md" = "Write your answer in answer.txt." }
[[tasks.checks]]
kind = "command"
argv = ["grep", "-qx", "done", "answer.txt"]
timeout_s = 10
```

### Targets

| `kind` | What runs | Settings (all optional) |
| --- | --- | --- |
| `model` | The model alias through `POST /v1/chat/completions`, with a tool loop over three workspace tools: `read_file`, `write_file`, `list_files` | `max_turns` (8), `tools` (true; false sends no tools), `instructions` (a system message), `temperature` |
| `claude_agent_sdk` | An agent of the Claude Agent SDK, its every model call through the gateway's Messages API: `ANTHROPIC_BASE_URL` is the gateway, the key goes as a bearer token, the trial's `traceparent` as a custom header; your own Claude settings and configuration directory are not loaded | `max_turns` (8), `allowed_tools` (`Read`, `Write`, `Edit`, `Glob`, `Grep`), `permission_mode` (`acceptEdits`), `instructions` (system prompt), `small_model` (the alias for the harness's own short calls; default the target's model) |
| `openai_agents_sdk` | An agent of the OpenAI Agents SDK over the gateway's chat completions, with the same three workspace tools; the SDK's own trace export is turned off | `max_turns` (8), `tools` (true), `instructions`, `api` (`chat`; `responses` uses the Responses API) |
| `custom` | Your own function, from Python only: `run(ctx)` gets the task, the workspace and `ctx.headers`, which it must send on every model call | — |

The model alias of a `claude_agent_sdk` target serves the `messages` capability; the others serve `chat`. Only the settings named in the table are sent to the gateway with the plan, for the comparison; anything else in `settings` stays on your machine.

### Checks

Every check of a task runs after the attempt, in the attempt's own workspace (a fresh directory, with the task's `files`, removed at the end unless `--keep-workspaces`).

| `kind` | Fields | Passes when |
| --- | --- | --- |
| `predicate` | `op`, `value`, `path` | `contains`, `not_contains`, `equals` (after trimming), `regex` on the final answer; `file_exists`, `file_contains`, `file_equals` on the workspace file `path`; `tool_called` (a tool of that name was called); `max_tool_calls` (at most `value` calls). From Python, `Predicate(fn=...)` takes any function of the outcome |
| `judge` | `model` and `criteria`, or `evaluator` | The judge alias answers `{"pass": true}` for the criteria (with the task and its `expected` answer), or the team's evaluator, read with `GET /v1/evaluators/{name}`, scores the answer past its pass rule. The judge calls go through the gateway in a trace of their own, so their cost stays apart |
| `command` | `argv` (a list; no shell), `timeout_s` (60), `expect_exit` (0), `stdout_contains` | The command exits with `expect_exit` (and prints `stdout_contains`) within the timeout. It runs in a process group of its own, killed whole at the timeout, with your environment minus every variable whose name looks like a credential (`API_KEY`, `..._KEY`, `KEY_ID`, `TOKEN`, `SECRET`, `PASSWORD`, `CREDENTIAL`, an `AUTH` word such as `..._AUTH_...`; `GIT_AUTHOR_*` is kept) and any whose value holds the gateway key; only the last 64 KiB of its output are read (`stdout_contains` is looked for there), and whatever it left running in its group is killed when it ends |

A check that cannot run (a judge that does not answer, a command that is not installed, a path outside the workspace) gives no verdict: the attempt is an `error` with class `check_error`, not a fail.

## Run it

```bash
export GATEWAY_URL=https://gateway.example.com
export GATEWAY_API_KEY=...            # read from the environment, never from the command line
python -m m7gtw_prompts.agent_eval run tasks.toml
```

| Option | Effect |
| --- | --- |
| `--name NAME` | The evaluation's name (default: the file's `name` and the UTC time). A name the team used before is refused |
| `--trials N`, `--concurrency N` | Override the file |
| `--target LABEL`, `--task ID` | Run only these (repeatable) |
| `--no-report` | Run locally: no plan and no results in the gateway (the model calls are still recorded as usual); the scorecard has no costs |
| `--no-details` | Do not send check details (the tail of a failing command's output, a judge's reason) |
| `--json FILE` | Write the whole report: the plan, the scorecard and every outcome |
| `--min-pass-rate R` | Exit 1 when a target's pass rate is below `R` (default 0: report only) |
| `--keep-workspaces` | Keep each attempt's directory |
| `--allow-insecure-http` | Allow plain HTTP to a gateway that is not on loopback |

Exit codes: `0` every target reached `--min-pass-rate`, `1` one did not, `2` the plan or the run was refused. The command prints one line per attempt as it ends and then the scorecard as a Markdown table. A Ctrl-C records every attempt not yet run as an `error` of class `interrupted`, so an interrupted run never looks better than it was. Attempts already running finish before the process exits, and their workspaces are kept (the path is printed).

From Python:

```python
from m7gtw_prompts.agent_eval import AgentEvalRunner, Task, Target, Predicate, Command, Judge

runner = AgentEvalRunner("https://gateway.example.com", key, max_concurrency=4)
report = runner.run(
    name="nightly-2026-11-27", dataset="agent-tasks", trials=3,
    tasks=[Task("capital", "What is the capital of France?", expected="Paris",
                checks=[Predicate("contains", "Paris"), Judge(criteria="Names Paris", model="judge")])],
    targets=[Target("small", "model", "gpt-small"), Target("agent", "openai_agents_sdk", "gpt-small")],
)
print(report["scorecard"]["recommended"])
```

`run_agent_eval(base_url, key, name=..., dataset=..., tasks=..., targets=..., trials=...)` is the same in one call. The client methods `create_agent_eval`, `record_agent_results` and `get_agent_eval` of `ObservabilityClient` call the API directly, for a runner of your own.

## What the gateway records

- **The plan.** `POST /v1/agent-evals` opens one experiment run per target, all at one instant of the dataset, named `<name> · <label>`. With `tasks` (what the runner sends) the tasks are written to the team's dataset `dataset_name`: created and kept by the runner the first time (`managed_by: agent_eval`), and afterwards only the tasks whose prompt, expected answer or metadata changed get a new version, recorded as a dataset version by the key. A dataset of that name created in the console is never rewritten by a key: the request answers `409 dataset_not_runner_kept`. To run the items of a console dataset as they are, send `task_ids` instead of `tasks` (from Python, with your own task definitions). A task's metadata keeps the kind and name of each check, never a command.
- **Each attempt is one trace.** The runner mints a W3C trace for every trial before scheduling it and sends its `traceparent` on every model call the trial makes, whatever the harness; the gateway keeps the calls in that trace, and the trial's run item records it, so the trace page names the experiment item and **Traces of this run** lists the run's attempts. Judge checks run in a second trace of their own.
- **Outcomes.** `POST /v1/agent-evals/{id}/results` takes 1–100 outcomes: target, task, trial, `pass`, `fail` or `error`, a failure class, the trial's wall-clock time, the tool calls the harness made, each check's verdict and the two trace IDs. A recorded attempt is final: sending it again with the same traces is a retried post and replaces its outcome, with other traces it is refused (`409 trial_recorded`), so an attempt's calls are never dropped and a client cannot keep the best of several. A trace that another run item of the team already holds, in any evaluation, is refused (`409 trace_claimed`), so a call is counted once.
- **Costs come from the gateway.** The scorecard reads the team's own request log rows of each trace, written since the evaluation was planned: a trace of another team's traffic adds nothing, and nothing the client says about cost or tokens is used.

### Failure classes

| Class | Outcome | When |
| --- | --- | --- |
| `wrong_answer` | fail | A predicate or judge check failed |
| `command_failed` | fail | A command check failed |
| `tool_misuse` | fail | A check failed and the harness called a tool with an error, or the same tool with the same arguments three times or more |
| `max_turns` | fail | The harness stopped at its turn limit |
| `timeout` | error | The attempt ran past the task's `timeout_s` (300 by default) |
| `provider_error` | error | A model call through the gateway was refused or failed |
| `agent_error` | error | The harness failed or reported an error |
| `harness_unavailable` | error | The SDK of the target's kind is not installed |
| `check_error` | error | No check failed but one could not run |
| `interrupted` | error | The runner was stopped (Ctrl-C) before the attempt finished; the attempt keeps its trace, so calls it made still count |

## Read the scorecard

`GET /v1/agent-evals/{id}` (key with `evals:read`) and, in the console, **Evals → Experiments**, any run of the evaluation: the **Agent evaluation scorecard** panel shows every target side by side.

| Field | Meaning |
| --- | --- |
| `planned`, `recorded`, `passed`, `failed`, `errors`, `missing` | Trials: tasks × trials, those recorded, and their outcomes |
| `pass_rate` | `passed / planned`: errors and missing trials count as not passed |
| `pass_at_k`, `pass_all_k` | Share of tasks with at least one passing trial, and with every trial passing |
| `agent_cost`, `judge_cost`, `total_cost` | The ledger's valuation of the trials' traces and of their judge traces: `known_usd` is the exact sum of the known amounts, `state` `known`, `partial` (some calls have no known price), `unknown` or `none` (no call recorded) |
| `cost_per_success_usd` | `total_cost / passed`; a lower bound when `cost_per_success_state` is `partial`; null when the cost is unknown or nothing passed. A trial with a verdict and no call in the ledger (a harness that did not send the trial's `traceparent`, a call outside the gateway) makes the cost `partial`, or `unknown` when nothing is known: never a cheaper figure |
| `input_tokens`, `output_tokens`, `model_calls` | From the ledger (model calls are distinct requests) |
| `tool_calls` | As the runner's harnesses reported them |
| `latency`, `model_latency` | Mean, p50 and p95 of the trial's wall clock (measured by the runner around the harness, its tool calls included and the checks excluded) and of the sum of its model calls' durations |
| `failure_classes` | Count per class |
| `metrics_complete` | Every trial recorded, every verdict backed by at least one ledger call, and no unknown or partial cost |
| `tasks` | Per task: recorded, passed and errors |
| `recommended` | The target with the lowest cost per success among those within five points of the best pass rate; by pass rate alone when a candidate's cost is not known exactly |

`?trials=<label>` adds that target's trials: outcome, class, latency, tool calls, checks, the two trace IDs and each trace's ledger. The console reads the same body at `GET /api/v1/admin/evals/agent-evals/{id}` (`evals:read` over the team; another team's evaluation answers 404).

The ledger row of a call is written just after its answer, so the runner waits up to five seconds (`settle_s`) for `metrics_complete` before it prints the scorecard.

### Costs of agent harnesses

A harness that marks prompt-cache breakpoints (Claude Code, under the Claude Agent SDK, does on every call) is valued only when the model's price covers cache writes: with a manual price book entry of input and output rates alone, those calls are recorded with their tokens and an unknown cost, and the scorecard reads `unknown`. Use the automatic price catalog for those models (see [automatic pricing](/docs/features/automatic-pricing/): `automatic_price_catalog`, `external_model_catalog` and a price source such as `price_source_cost_map`) or compare their targets by pass rate. Claude Code's calls are also inside the budget profile, so a target under a budget is admitted and each call settles at its measured spend (see [budget profiles](/docs/features/quota-protocols/)). Claude Code also asks for adaptive thinking on every call; thinking is billed inside the output tokens, so those calls are valued like any other (see [valuation](/docs/features/usage-valuation/)). A scorecard's `input_tokens` is the uncached input the provider reports: the cache reads and writes of such a harness are in its cost, not in that count. Harnesses also make calls of their own (Claude Code's short side calls use `small_model`): they are part of the target's real cost and are counted.

## Where the agents run

The runner, its harnesses and your checks run with your user's rights on the machine that runs them. The `model` and `openai_agents_sdk` harnesses reach files only through the three workspace tools, confined to the attempt's directory. Claude Code, under the Claude Agent SDK, has its own tools: `Read`, `Glob` and `Grep` accept absolute paths, so an agent can read files outside the workspace, and a target that allows `Bash` or sets `permission_mode` to `bypassPermissions` can run anything. The runner blanks every credential of the environment it hands to the harness (the gateway key goes only as its token), but for tasks you do not trust, run the runner in a container or a disposable machine.

The plan's `instructions` setting (a system prompt) is sent with the target for the comparison; the reported settings of a target are limited to 2 KiB.

## Limits

| Limit | Value |
| --- | --- |
| Targets | 1–10 |
| Tasks | 1–500; tasks × trials at most 2000 per target |
| Trials | 1–10 |
| Results per request | 1–100 |
| Task input and expected output | 64 KiB each; metadata 4 KiB |
| Target settings | 2 KiB |
| Outcome output | 64 KiB (the runner sends at most 8 KiB, `max_output_chars`) |
| Checks per outcome | 20, details 500 characters |
| Plan body | 4 MiB |

## Isolation

An agent evaluation belongs to the key's team and its organization. A key or a console user of another team or organization reads or writes none of it (404), and the trial traces are read through the usual trace permissions. The scorecard reads only the evaluation team's own ledger rows. See [access control](/docs/features/access-control/).

## Answers

| Status | Code | When |
| --- | --- | --- |
| 404 | `feature_disabled` | A flag is off, or the team's plan lacks `agent_evaluations` or `experiment_traces` |
| 403 | `team_required` | The key has no team |
| 400 | `invalid_request`, `invalid_result` | Bounds, unknown fields, a target, task or trial outside the plan, a failure class on a passing trial |
| 404 | `not_found`, `task_not_found` | No such evaluation or dataset of the team; a task that is not an item of the dataset |
| 409 | `duplicate` | The team already has an evaluation of this name |
| 409 | `dataset_not_runner_kept` | Tasks sent for a dataset created in the console |
| 409 | `trace_claimed` | A trace already recorded for another run item of the team |
| 409 | `trial_recorded` | The trial is already recorded with other traces |
| 409 | `tasks_changed` | The dataset's tasks changed between the runner's write and the plan (another runner of the same dataset name): plan again |

## Upgrade

Migration 310 adds the agent evaluation table, the target of each run, the outcome columns of run items and the `managed_by` mark of datasets; it is additive, and nothing is written with the flag off. A replica of an older version ignores the new columns.
