# agent trace read

Read trace files from an agent preview session.

## Description for agent trace read

When you run an agent preview conversation (either interactive or programmatic), trace files are automatically recorded and saved in your local DX project. Each turn (utterance or response) of a conversation creates trace data. Use this command to view trace data for a specific preview session, so you can then analyze the trace data to observe, monitor, investigate, and troubleshoot agent events and behavior.

Use the --format flag to specify one of these formats of the outputted trace data:

<ul><li>summary (Default): A per-turn narrative showing topic routing, actions executed, and the agent's response. Use this to quickly understand what happened in a preview session.</li><li>detail: Diagnostic drill-down into a specific dimension. Filters output to only the trace steps relevant to that dimension, minimizing noise.</li><li>raw: Unprocessed trace JSON. Use this as a fallback when the trace schema has changed or you need to perform custom analysis.</li></ul>

If you specify "--format detail", you must also specify a dimension with the --dimension flag. Dimensions are a way to slice and analyze the agent execution trace from a specific angle or concern. Instead of looking at the raw sequence of everything that happened, each dimension filters and organizes the trace data to answer a specific type of question. These are the available dimensions and the information they provide:

<ul><li>actions: The actions the agent executed. Includes action name, input parameters, output, and latency. Use this dimension to understand what the agent actually did when answering an utterance in the preview session.</li><li>grounding: The reasoning steps used by the LLM. Use this dimension to see how the agent "thought" about the problem - the AI reasoning that determined which actions to take.</li><li>routing: How the agent navigated between subagents. Use this dimension to understand conversation flow - when and why the agent switched between different subagents or contexts during the conversation.</li><li>errors: Aggregates all errors during the session. Use this dimension to quickly identify and debug issues across all steps.</li></ul>

## Flags

| Flag Name (Long) | Flag Name (Short) | Description                                                                                                                                                                                                                     |
| ---------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--dimension`    | `-d`              | **Type:** Value<br>**Valid Values:** `actions`, `grounding`, `routing`, `errors`<br><br>Dimension to drill into when using "--format detail"; used to filter and organize the trace data to answer a specific type of question. |
| `--flags-dir`    | N/A               | **Type:** Value<br><br>Import flag values from a directory.                                                                                                                                                                     |
| `--format`       | `-f`              | **Type:** Value<br>**Valid Values:** `summary`, `detail`, `raw`<br>**Default value:** `summary`<br><br>Output format of the trace data; specifies the level of detail you want in the trace files.                              |
| `--json`         | N/A               | **Type:** Boolean<br><br>Format output as json.                                                                                                                                                                                 |
| `--session-id`   | `-s`              | **Type:** Value<br>**Required**<br><br>Session ID to read traces for. Use the "agent preview sessions" CLI command to list all known agent preview sessions along with their session IDs                                        |
| `--turn`         | `-t`              | **Type:** Value<br><br>Turn number for which you want trace data. A turn is a single utterance or response in a conversation, starting with 1.                                                                                  |

## Examples for agent trace read

Show a session trace summary for all turns in the session with the specified ID:

```shell
sf agent trace read --session-id <SESSION_ID>
```

Show a trace summary for the second turn (utterance or response) of the conversation:

```shell
sf agent trace read --session-id <SESSION_ID> --turn 2
```

Drill into action execution across all turns:

```shell
sf agent trace read --session-id <SESSION_ID> --format detail --dimension actions
```

Drill into routing decisions for the first turn of the conversation:

```shell
sf agent trace read --session-id <SESSION_ID> --format detail --dimension routing --turn 1
```

Show all errors across the session:

```shell
sf agent trace read --session-id <SESSION_ID> --format detail --dimension errors
```

Output raw trace JSON for custom parsing:

```shell
sf agent trace read --session-id <SESSION_ID> --format raw
```

Return results as JSON:

```shell
sf agent trace read --session-id <SESSION_ID> --json
```
