# Set what an eval checks

An eval's metrics are its checks. Each has a severity: a gate fails the eval, soft only reports, and budget fails it when a case goes over a usage threshold such as time, without stopping the case. Runs per case repeats every test case, to see how steady the answer is.

## Before you start

You need an eval. See [Write an eval](/docs/agents/write-eval.md).

## Edit the metrics

**Code**

1. In your eval's file, replace `metrics` with these three and add `repetitions`:

```ts title="evals/divide.eval.ts" {7-12}
import { datasets, evalAgent, metrics } from 'veryfront/eval'

export default evalAgent({
  name: 'Divide',
  target: 'agent:assistant',
  dataset: datasets.inline([{ id: 'divide', input: 'What is 128 divided by 8?' }]),
  metrics: [
    metrics.answer.contains({ text: '16' }).gate(),
    metrics.agent.noFailedTools().soft(),
    metrics.ops.latency({ maxMs: 20000 }).budget(),
  ],
  repetitions: 3,
})
```

2. Run it:

```bash
npm run eval -- divide
```

3. Read the result. You should now see `Result: 3/3 passed`, with the three metrics under it: `Answer contained "16"`, `Agent had no failed tool calls` and `Latency stayed under 20000ms`.

### Try it in a sandbox

```playground
step: Create a project | npm create -y veryfront@latest support-desk -- --template ai-agent --yes
step: Set the metrics | cd support-desk && mkdir -p evals && printf '%s\n' "import { datasets, evalAgent, metrics } from 'veryfront/eval'" '' 'export default evalAgent({' "  name: 'Divide'," "  target: 'agent:assistant'," "  dataset: datasets.inline([{ id: 'divide', input: 'What is 128 divided by 8?' }])," '  metrics: [' "    metrics.answer.contains({ text: '16' }).gate()," '    metrics.agent.noFailedTools().soft(),' '    metrics.ops.latency({ maxMs: 20000 }).budget(),' '  ],' '  repetitions: 3,' '})' > evals/divide.eval.ts
check: npm run eval -- divide
expect: Result: 3/3 passed
```

**Studio**

1. In your project, open **Building blocks** > **Evals**.
2. Click your eval, here Capitals.
3. Click **Edit eval**.
4. Under **Metrics**, replace the JSON with these three metrics: the answer contains "Paris" and must pass, no tool call may fail and it only reports, and the answer must come within 20 seconds.

```json
[
  {
    "name": "answer.contains",
    "family": "answer",
    "severity": "gate",
    "config": { "text": "Paris" },
    "editable": true,
    "dynamic": false
  },
  {
    "name": "agent.noFailedTools",
    "family": "agent",
    "severity": "soft",
    "editable": true,
    "dynamic": false
  },
  {
    "name": "ops.latency",
    "family": "ops",
    "severity": "budget",
    "config": { "maxMs": 20000 },
    "editable": true,
    "dynamic": false
  }
]
```

5. Under **Runs per case**, enter 3.
6. Click **Save eval**. You should now see the three metrics on the eval's page, under **Metrics**.

**API**

The calls below change the eval on the main branch. On a preview branch, add `?source_target_kind=preview_branch&target_branch_id=$BRANCH_ID` to both URLs, where `$BRANCH_ID` is the branch's `id` from `GET /projects/$PROJECT/branches`.

1. Set `PROJECT` to your project's ID ([Find your IDs](/docs/authentication/api-keys.md#find-your-ids)): `export PROJECT=<id>`.
2. Set `EVAL_ID` to your eval's `id`, here `eval:capitals`: `export EVAL_ID=eval:capitals`.
3. Replace the eval's metrics and set the runs per case, with your [API key](/docs/authentication/api-keys.md). Only the fields you send change:

```bash
curl -X PATCH https://api.veryfront.com/projects/$PROJECT/evals/$EVAL_ID \
  -H "Authorization: Bearer $VERYFRONT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "metrics": [
      { "name": "answer.contains", "family": "answer", "severity": "gate",
        "config": { "text": "Paris" }, "editable": true, "dynamic": false },
      { "name": "agent.noFailedTools", "family": "agent", "severity": "soft",
        "editable": true, "dynamic": false },
      { "name": "ops.latency", "family": "ops", "severity": "budget",
        "config": { "maxMs": 20000 }, "editable": true, "dynamic": false }
    ],
    "repetitions": 3
  }'
```

4. Get the eval. You should now see the three `metrics` and `"repetitions": 3`:

```bash
curl https://api.veryfront.com/projects/$PROJECT/evals/$EVAL_ID \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

### Try it in a sandbox

```playground
step: Set PROJECT | export PROJECT=$VERYFRONT_PROJECT_ID
step: Before you start: an agent | curl -X POST https://api.veryfront.com/projects/$PROJECT/agents -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d '{"id": "support", "name": "Support assistant", "system_prompt": "Answer questions in one short sentence."}'
step: Before you start: an eval | curl -X POST https://api.veryfront.com/projects/$PROJECT/evals -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d '{"name": "Capitals", "target": "agent:support", "dataset": {"kind": "inline", "editable": true, "dynamic": false, "examples": [{"id": "q1", "input": "Capital of France?", "reference": "Paris"}]}, "metrics": [{"name": "answer.contains", "family": "answer", "severity": "gate", "config": {"text": "Paris"}, "editable": true, "dynamic": false}]}'
step: Set EVAL_ID | export EVAL_ID=eval:capitals
step: Replace the metrics | curl -X PATCH https://api.veryfront.com/projects/$PROJECT/evals/$EVAL_ID -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d '{"metrics": [{"name": "answer.contains", "family": "answer", "severity": "gate", "config": {"text": "Paris"}, "editable": true, "dynamic": false}, {"name": "agent.noFailedTools", "family": "agent", "severity": "soft", "editable": true, "dynamic": false}, {"name": "ops.latency", "family": "ops", "severity": "budget", "config": {"maxMs": 20000}, "editable": true, "dynamic": false}], "repetitions": 3}'
check: curl https://api.veryfront.com/projects/$PROJECT/evals/$EVAL_ID -H "Authorization: Bearer $VERYFRONT_API_KEY"
expect: "repetitions":3
```

## With MCP

1. Call `veryfront__update_eval` with `"project_reference": "my-project"`, your eval's `eval_id` (here `eval:capitals`; `veryfront__list_evals` lists them), `"repetitions": 3` and the same three `metrics` as the API tab. The project reference is its slug or its ID. On a preview branch, also pass `"source_target_kind": "preview_branch"` and the branch's ID as `target_branch_id` (`veryfront__list_branches` lists them).
2. It worked when the answer lists `answer.contains` as `gate`, `agent.noFailedTools` as `soft` and `ops.latency` as `budget`, with `repetitions` 3.

## Next steps

* [Run an eval](/docs/agents/run-eval.md)
* [Debug a run](/docs/observability/debug.md)
