# Run an eval

Run an eval, which sends each test case to its agent or tool and scores the answers, then read its result. Run it after every change, and before you publish.

## Before you start

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

## Run an eval

**Code**

1. In your project's folder, run the eval by its ID. The file name `divide.eval.ts` makes it `divide`:

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

2. Read the result. You should now see `Result: 1/1 passed`, with each metric listed under it and a `Report:` path for the full report.

### Try it in a sandbox

```playground
step: Create the project | npm create -y veryfront@latest my-agent -- --template ai-agent --yes
step: Go into it | cd my-agent
step: Add the eval from Write an eval | 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.agent.calledTool('calculator').gate(), metrics.answer.contains({ text: '16' }).gate()]," '})' > evals/divide.eval.ts
check: npm run eval -- divide
expect: Result: 1/1 passed
```

**Studio**

1. In your project, open **Building blocks** > **Evals**.
2. Click your eval.
3. Under **Recent runs**, click **Run eval**. Once the eval has runs, **Run eval** is in the ⋯ menu.
4. When the run finishes, click **Open report**. You should now see **Passed** `1/1`.

### Troubleshooting

**If Passed shows fewer cases than the eval has**, look under **Gate failures** in the report. Each row's **Check** and **Reason** say which metric failed and why.

**API**

1. Set `PROJECT` to your project's ID ([Find your IDs](/docs/authentication/api-keys.md#find-your-ids)): `export PROJECT=<id>`.
2. List the project's evals with your [API key](/docs/authentication/api-keys.md):

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

3. Set `EVAL_ID` to your eval's `id` in the list, such as `eval:capitals`: `export EVAL_ID=<id>`.
4. Run it:

```bash
curl -X POST https://api.veryfront.com/runs \
  -H "Authorization: Bearer $VERYFRONT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "project_id": "'$PROJECT'",
    "target": { "type": "task", "id": "eval" },
    "config": { "eval_id": "'$EVAL_ID'" },
    "execution": { "runtime": { "type": "main_branch" } }
  }'
```

5. List the eval's runs until the first one's `status` is `completed`. You should now see its `summary`, such as `"records": 1, "passed": 1`:

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

### Try it in a sandbox

```playground
step: Set PROJECT | export PROJECT=$VERYFRONT_PROJECT_ID
step: Add the support agent | curl -fsS -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: Add the eval from Write an eval | curl -fsS -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: List the evals | curl https://api.veryfront.com/projects/$PROJECT/evals -H "Authorization: Bearer $VERYFRONT_API_KEY"
step: Set EVAL_ID | export EVAL_ID=eval:capitals
step: Run it | curl -X POST https://api.veryfront.com/runs -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d '{ "project_id": "'$PROJECT'", "target": { "type": "task", "id": "eval" }, "config": { "eval_id": "'$EVAL_ID'" }, "execution": { "runtime": { "type": "main_branch" } } }'
step: Wait until it completes | for i in $(seq 60); do curl -s https://api.veryfront.com/projects/$PROJECT/evals/$EVAL_ID/runs -H "Authorization: Bearer $VERYFRONT_API_KEY" | grep -q '"status":"completed"' && break; sleep 3; done
check: curl https://api.veryfront.com/projects/$PROJECT/evals/$EVAL_ID/runs -H "Authorization: Bearer $VERYFRONT_API_KEY"
expect: "passed":1
```

## With MCP

1. Call `veryfront__list_evals` with `"project_reference": "my-project"` (your project's slug or ID), and take your eval's `id`, such as `eval:capitals`.
2. Call `veryfront__run_eval` with `"project_reference": "my-project"` and `"eval_id": "eval:capitals"`. Keep the `run_id` it returns.
3. Call `veryfront__list_eval_runs` with `"project_reference": "my-project"` and `"eval_id": "eval:capitals"` until the first run's `status` is `completed`.
4. Call `veryfront__get_eval_run` with the same `project_reference` and `eval_id`, and the `run_id` from step 2. It worked when its `summary` shows `"records": 1, "passed": 1`.

## Next steps

* [Publish](/docs/deployment/publish.md)
* [Debug a run](/docs/observability/debug.md)
