# Debug a run

Find why a [run](/docs/concepts/runs.md) failed or is waiting from its page, which shows its input, model calls, events and errors.

## Before you start

You need a run. See [Start a run](/docs/orchestration/start-run.md).

## Read a run

**Studio**

1. In your project, open **Orchestration** > **Runs**.
2. Click **Open** on the run. It shows its **Input**, **Output** and cost. A **Failed** run shows its **Error** under **Execution**.
3. Scroll to **Calls by model**. Each call shows its **Model**, **Tokens**, **Credits** and **Duration**.
4. Below, **Event history** lists every event. You should now see **Run queued** as the first event.
5. Open the **⋯** menu at the top. You should now see **Analyze this run**, **Create report** and **Export JSON**.

**Code**

1. [Sign in](/docs/start/authentication.md) to the CLI.
2. Set `PROJECT` to your project's ID ([Find your IDs](/docs/authentication/api-keys.md#find-your-ids)): `export PROJECT=<id>`.
3. List the project's runs, newest first:

```bash
npx veryfront project runs project-list --project-reference $PROJECT
```

4. Set `RUN_ID` to the `id` of the run you want, from the list above: `export RUN_ID=<id>`.
5. Get the run. It shows its `status`, `input`, `output` and `usage`. A `failed` run has an `error` with its `code` and `message`:

```bash
npx veryfront project runs get --run-id $RUN_ID
```

6. List its request and model-call events, oldest first. You should now see `AGENT_RUN_REQUEST_ENQUEUED` first for an agent's run, and a `MODEL_CALL_COMPLETED` for each model call:

```bash
npx veryfront project runs events --run-id $RUN_ID --query '{"event_type":["AGENT_RUN_REQUEST_ENQUEUED","MODEL_CALL_COMPLETED"],"limit":100}'
```

### 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 customer questions about orders and refunds. Refunds take 5 business days. Keep replies to two sentences." }'
step: Ask it a question | export CONVERSATION=$(curl -fsS -X POST https://api.veryfront.com/conversations -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d '{ "project_reference": "'$PROJECT'", "type": "chat", "title": "Refund question", "initial_message": { "role": "user", "parts": [{ "type": "text", "text": "How long does a refund take?" }] } }') && export CONVERSATION_ID=$(printf '%s' "$CONVERSATION" | jq -r .id) MESSAGE_ID=$(printf '%s' "$CONVERSATION" | jq -r .initial_message_id)
step: Let the agent answer | curl -fsS -X POST https://api.veryfront.com/runs -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d '{ "project_id": "'$PROJECT'", "conversation_id": "'$CONVERSATION_ID'", "target": { "type": "agent", "id": "support" }, "input": { "agent_id": "support", "messages": [{ "id": "'$MESSAGE_ID'", "role": "user", "parts": [{ "type": "text", "text": "How long does a refund take?" }] }], "tools": [], "context": [] }, "config": { "agent_admission": { "mode": "project", "input_message_id": "'$MESSAGE_ID'" } }, "execution": { "runtime": { "type": "main_branch" } } }'
step: Wait for the answer | for i in $(seq 60); do curl -s https://api.veryfront.com/projects/$PROJECT/runs -H "Authorization: Bearer $VERYFRONT_API_KEY" | grep -q '"status":"completed"' && break; sleep 3; done
step: List the runs | npx veryfront project runs project-list --project-reference $PROJECT
step: Set RUN_ID | export RUN_ID=$(npx veryfront project runs project-list --project-reference $PROJECT | jq -r '.data[0].id')
step: Get the run | npx veryfront project runs get --run-id $RUN_ID
check: npx veryfront project runs events --run-id $RUN_ID --query '{"event_type":["AGENT_RUN_REQUEST_ENQUEUED","MODEL_CALL_COMPLETED"],"limit":100}' | jq -r '.data[].event_type'
expect: MODEL_CALL_COMPLETED
```

**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 runs, newest first, with your [API key](/docs/authentication/api-keys.md):

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

3. Set `RUN_ID` to the `id` of the run you want, from the list above: `export RUN_ID=<id>`.
4. Get the run: its `status`, `input`, `output`, `usage`, and a failed run's `error`:

```bash
curl https://api.veryfront.com/runs/$RUN_ID \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

5. List its request and model-call events, oldest first. You should now see `AGENT_RUN_REQUEST_ENQUEUED` first, and a `MODEL_CALL_COMPLETED` per model call:

```bash
curl "https://api.veryfront.com/runs/$RUN_ID/events?event_type=AGENT_RUN_REQUEST_ENQUEUED&event_type=MODEL_CALL_COMPLETED&limit=100" \
  -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 customer questions about orders and refunds. Refunds take 5 business days. Keep replies to two sentences." }'
step: Ask it a question | export CONVERSATION=$(curl -fsS -X POST https://api.veryfront.com/conversations -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d '{ "project_reference": "'$PROJECT'", "type": "chat", "title": "Refund question", "initial_message": { "role": "user", "parts": [{ "type": "text", "text": "How long does a refund take?" }] } }') && export CONVERSATION_ID=$(printf '%s' "$CONVERSATION" | jq -r .id) MESSAGE_ID=$(printf '%s' "$CONVERSATION" | jq -r .initial_message_id)
step: Let the agent answer | curl -fsS -X POST https://api.veryfront.com/runs -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d '{ "project_id": "'$PROJECT'", "conversation_id": "'$CONVERSATION_ID'", "target": { "type": "agent", "id": "support" }, "input": { "agent_id": "support", "messages": [{ "id": "'$MESSAGE_ID'", "role": "user", "parts": [{ "type": "text", "text": "How long does a refund take?" }] }], "tools": [], "context": [] }, "config": { "agent_admission": { "mode": "project", "input_message_id": "'$MESSAGE_ID'" } }, "execution": { "runtime": { "type": "main_branch" } } }'
step: Wait for the answer | for i in $(seq 60); do curl -s https://api.veryfront.com/projects/$PROJECT/runs -H "Authorization: Bearer $VERYFRONT_API_KEY" | grep -q '"status":"completed"' && break; sleep 3; done
step: List the runs | curl https://api.veryfront.com/projects/$PROJECT/runs -H "Authorization: Bearer $VERYFRONT_API_KEY"
step: Set RUN_ID | export RUN_ID=$(curl -s https://api.veryfront.com/projects/$PROJECT/runs -H "Authorization: Bearer $VERYFRONT_API_KEY" | jq -r '.data[0].id')
step: Get the run | curl https://api.veryfront.com/runs/$RUN_ID -H "Authorization: Bearer $VERYFRONT_API_KEY"
check: curl -s "https://api.veryfront.com/runs/$RUN_ID/events?event_type=AGENT_RUN_REQUEST_ENQUEUED&event_type=MODEL_CALL_COMPLETED&limit=100" -H "Authorization: Bearer $VERYFRONT_API_KEY" | jq -r '.data[].event_type'
expect: MODEL_CALL_COMPLETED
```

## With MCP

1. Call `veryfront__list_project_runs` with `"project_reference": "my-project"`, your project's slug or ID. The newest run is first.
2. Call `veryfront__get_run` with `"run_id"` set to the `id` of the run you want, from the list. It shows its `status`, input, output and usage. A failed run has its error.
3. Call `veryfront__list_run_events` with the same `id` as `"run_id"`, `"event_type": ["AGENT_RUN_REQUEST_ENQUEUED", "MODEL_CALL_COMPLETED"]` and `"limit": 100`. It worked when `AGENT_RUN_REQUEST_ENQUEUED` comes first for an agent's run, with a `MODEL_CALL_COMPLETED` for each model call.

## Next steps

* [Search logs](/docs/observability/logs.md)
* [Write an eval](/docs/agents/write-eval.md)
