# Trace an agent’s tool calls

See which tools an agent called in a [run](/docs/concepts/runs.md): its page lays out every model call and tool call in order and as a graph.

## Before you start

You need an agent run that called a tool, such as the chat at the end of [Add a tool](/docs/agents/tools.md).

## See the tool calls

**Studio**

1. In your project, open **Orchestration** > **Runs**.
2. Click **Open** on the agent's run.
3. Scroll to **Timeline**. It lists the run's steps in order, with their durations.
4. Click the arrow beside Step 1. You should now see the `get-time` tool call inside it.
5. Click `get-time`. You should now see the call's **Arguments** and its **Result**.
6. Scroll to **Graph**. It shows the run, its model calls and tool calls as boxes.
7. Click the `get-time` box. You should now see the same **Arguments** and **Result**.

**Code**

1. [Sign in](/docs/start/authentication.md) to the CLI.
2. Set `RUN_ID` to the run's ID ([Find your IDs](/docs/authentication/api-keys.md#find-your-ids)): `export RUN_ID=<id>`.
3. List the run's tool-call events. You should now see `TOOL_CALL_START` for `get-time`, `TOOL_CALL_ARGS` whose `delta` pieces, joined per `toolCallId`, read `{"timeZone":"Asia/Tokyo"}`, then `TOOL_CALL_RESULT`:

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

4. If `page_info.next` is not `null`, run it again with that value as `"cursor"` in `--query`. You should now see the next events.

### Try it in a sandbox

```playground
step: Before you start: the tool's source | printf '%s\n' 'import { tool } from "veryfront/tool";' '' 'export default tool({' '  id: "get-time",' '  description: "Get the current time in a time zone, such as Asia/Tokyo.",' '  inputSchema: {' '    type: "object",' '    properties: {' '      timeZone: { type: "string", description: "An IANA time zone, such as Asia/Tokyo" },' '    },' '    required: ["timeZone"],' '    additionalProperties: false,' '  },' '  execute: async ({ timeZone }) => ({' '    time: new Date().toLocaleString("en-GB", { timeZone, dateStyle: "full", timeStyle: "short" }),' '  }),' '});' > get-time.ts
step: Before you start: the tool | jq -n --rawfile source get-time.ts '{id: "get-time", source: $source}' | curl -fsS -X POST https://api.veryfront.com/projects/$VERYFRONT_PROJECT_ID/tools -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" --data-binary @-
step: Before you start: an agent with the tool | curl -fsS -X POST https://api.veryfront.com/projects/$VERYFRONT_PROJECT_ID/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. Keep replies to two sentences.", "tool_ids": ["get-time"]}'
step: Before you start: ask it the time in Tokyo | 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": "'$VERYFRONT_PROJECT_ID'", "type": "chat", "title": "Tokyo time", "initial_message": { "role": "user", "parts": [{ "type": "text", "text": "What time is it in Tokyo?" }] } }') && export CONVERSATION_ID=$(printf '%s' "$CONVERSATION" | jq -r .id) MESSAGE_ID=$(printf '%s' "$CONVERSATION" | jq -r .initial_message_id)
step: Before you start: 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": "'$VERYFRONT_PROJECT_ID'", "conversation_id": "'$CONVERSATION_ID'", "target": { "type": "agent", "id": "support" }, "input": { "agent_id": "support", "messages": [{ "id": "'$MESSAGE_ID'", "role": "user", "parts": [{ "type": "text", "text": "What time is it in Tokyo?" }] }], "tools": [], "context": [] }, "config": { "agent_admission": { "mode": "project", "input_message_id": "'$MESSAGE_ID'" } }, "execution": { "runtime": { "type": "main_branch" } } }' | tee run.json
step: Set RUN_ID | export RUN_ID=$(jq -r .id run.json)
step: Before you start: wait until the run is completed | for i in $(seq 40); do curl -s https://api.veryfront.com/runs/$RUN_ID -H "Authorization: Bearer $VERYFRONT_API_KEY" | jq -r .status | grep -qE 'completed|failed|cancelled' && break; sleep 3; done
step: List the run's tool-call events | npx veryfront project runs events --run-id $RUN_ID --query '{"event_type":["TOOL_CALL_START","TOOL_CALL_ARGS","TOOL_CALL_RESULT"],"limit":100}'
check: npx veryfront project runs events --run-id $RUN_ID --query '{"event_type":["TOOL_CALL_START","TOOL_CALL_ARGS","TOOL_CALL_RESULT"],"limit":100}' | jq -r '[.data[] | select(.event_type == "TOOL_CALL_ARGS") | .payload.delta] | join("")'
expect: {"timeZone":"Asia/Tokyo"}
```

**API**

1. Set `RUN_ID` to the run's ID ([Find your IDs](/docs/authentication/api-keys.md#find-your-ids)): `export RUN_ID=<id>`.
2. List the run's tool-call events with your [API key](/docs/authentication/api-keys.md). You should now see `TOOL_CALL_START` for `get-time`, `TOOL_CALL_ARGS` whose `delta` pieces, joined per `toolCallId`, read `{"timeZone":"Asia/Tokyo"}`, then `TOOL_CALL_RESULT`:

```bash
curl "https://api.veryfront.com/runs/$RUN_ID/events?event_type=TOOL_CALL_START&event_type=TOOL_CALL_ARGS&event_type=TOOL_CALL_RESULT&limit=100" \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

3. If `page_info.next` is not `null`, run it again with `&cursor=` and that value. You should now see the next events.

### Try it in a sandbox

```playground
step: Before you start: the tool's source | printf '%s\n' 'import { tool } from "veryfront/tool";' '' 'export default tool({' '  id: "get-time",' '  description: "Get the current time in a time zone, such as Asia/Tokyo.",' '  inputSchema: {' '    type: "object",' '    properties: {' '      timeZone: { type: "string", description: "An IANA time zone, such as Asia/Tokyo" },' '    },' '    required: ["timeZone"],' '    additionalProperties: false,' '  },' '  execute: async ({ timeZone }) => ({' '    time: new Date().toLocaleString("en-GB", { timeZone, dateStyle: "full", timeStyle: "short" }),' '  }),' '});' > get-time.ts
step: Before you start: the tool | jq -n --rawfile source get-time.ts '{id: "get-time", source: $source}' | curl -fsS -X POST https://api.veryfront.com/projects/$VERYFRONT_PROJECT_ID/tools -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" --data-binary @-
step: Before you start: an agent with the tool | curl -fsS -X POST https://api.veryfront.com/projects/$VERYFRONT_PROJECT_ID/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. Keep replies to two sentences.", "tool_ids": ["get-time"]}'
step: Before you start: ask it the time in Tokyo | 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": "'$VERYFRONT_PROJECT_ID'", "type": "chat", "title": "Tokyo time", "initial_message": { "role": "user", "parts": [{ "type": "text", "text": "What time is it in Tokyo?" }] } }') && export CONVERSATION_ID=$(printf '%s' "$CONVERSATION" | jq -r .id) MESSAGE_ID=$(printf '%s' "$CONVERSATION" | jq -r .initial_message_id)
step: Before you start: 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": "'$VERYFRONT_PROJECT_ID'", "conversation_id": "'$CONVERSATION_ID'", "target": { "type": "agent", "id": "support" }, "input": { "agent_id": "support", "messages": [{ "id": "'$MESSAGE_ID'", "role": "user", "parts": [{ "type": "text", "text": "What time is it in Tokyo?" }] }], "tools": [], "context": [] }, "config": { "agent_admission": { "mode": "project", "input_message_id": "'$MESSAGE_ID'" } }, "execution": { "runtime": { "type": "main_branch" } } }' | tee run.json
step: Set RUN_ID | export RUN_ID=$(jq -r .id run.json)
step: Before you start: wait until the run is completed | for i in $(seq 40); do curl -s https://api.veryfront.com/runs/$RUN_ID -H "Authorization: Bearer $VERYFRONT_API_KEY" | jq -r .status | grep -qE 'completed|failed|cancelled' && break; sleep 3; done
step: List the run's tool-call events | curl "https://api.veryfront.com/runs/$RUN_ID/events?event_type=TOOL_CALL_START&event_type=TOOL_CALL_ARGS&event_type=TOOL_CALL_RESULT&limit=100" -H "Authorization: Bearer $VERYFRONT_API_KEY"
check: curl -s "https://api.veryfront.com/runs/$RUN_ID/events?event_type=TOOL_CALL_START&event_type=TOOL_CALL_ARGS&event_type=TOOL_CALL_RESULT&limit=100" -H "Authorization: Bearer $VERYFRONT_API_KEY" | jq -r '[.data[] | select(.event_type == "TOOL_CALL_ARGS") | .payload.delta] | join("")'
expect: {"timeZone":"Asia/Tokyo"}
```

## With MCP

1. Find the agent's run: call `veryfront__list_project_runs` with `{ "project_reference": "my-project", "target_type": ["agent"] }`.
2. Call `veryfront__list_run_events` with the run's `id`, `"event_type": ["TOOL_CALL_START", "TOOL_CALL_ARGS", "TOOL_CALL_RESULT"]` and `"limit": 100`.
3. While `page_info.next` is not `null`, call it again with that value as `cursor`.
4. Group the events by `payload.toolCallId`: a run with several tool calls mixes their events. It worked when each call holds a `TOOL_CALL_START` with the tool's `toolCallName`, its `TOOL_CALL_ARGS` (the input: join that call's `delta` pieces in order), then its `TOOL_CALL_RESULT`.

## Next steps

* [Debug a run](/docs/observability/debug.md)
* [Search logs](/docs/observability/logs.md)
