> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cloosphere.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Tracing

> Step-by-step LLM request processing tracking — review I/O, analyze latency, generate LLM-based reports

<Info>Admin › Evaluation › Tracing</Info>

Tracing **records every step of AI request processing**.

* What documents were searched, what tools were invoked, what prompt was sent to the LLM — every step is transparently visible.

<Frame caption="Admin > Evaluation > Tracing — search traces by Chat ID or Message ID">
  <img src="https://mintcdn.com/cloocus/Nim6rqpdwJuim_F0/images/monitoring/tracing-main.png?fit=max&auto=format&n=Nim6rqpdwJuim_F0&q=85&s=9e1577f200fc98e4bc563626ccc7f711" alt="Tracing search screen" width="2880" height="1800" data-path="images/monitoring/tracing-main.png" />
</Frame>

**Example — without tracing vs. with tracing**

> Agent answered "I can't find that information"

| State           | What's Possible                            | Result                                             |
| --------------- | ------------------------------------------ | -------------------------------------------------- |
| Without tracing | Only guessing                              | Cannot identify cause                              |
| Using tracing   | Confirmed 0 search results in the Run tree | KB document missing → resolved by adding documents |

<Note>
  Tracing is a licensed feature. Requires a license with `trace` feature enabled.
</Note>

***

## Tracing Concepts

Processing a single user message involves multiple steps.

* Tracing records all these steps in a **Trace > Run** hierarchy.

```mermaid theme={null}
flowchart TB
    A[User message] --> B[Trace start]
    B --> C[Response Chain]
    C --> D[Guardrail check]
    C --> E[RAG search]
    C --> F[LLM call]
    C --> G[Tool execution]
    F --> H[Generate response]
    H --> L[Trace complete]

    A -.-> BG[background_tasks trace]
    BG --> I[Title generation]
    BG --> J[Tag generation]
    BG --> K[Search query generation]
```

| Concept      | Description                                   |
| ------------ | --------------------------------------------- |
| **Trace**    | Full processing for a single message          |
| **Run**      | Individual processing step within a Trace     |
| **Run tree** | Run hierarchy with parent-child relationships |

***

## Tracing Entry Methods

All three paths lead to the same **Evaluation › Tracing** screen — buttons ① and ② navigate automatically when clicked, while ③ searches directly by ID.

| Method                       | Best For                                                                 | Entry Path                                                       |
| ---------------------------- | ------------------------------------------------------------------------ | ---------------------------------------------------------------- |
| **① From conversation logs** | Admin investigating a specific conversation during operations (standard) | Monitoring › Conversation Logs › select conversation › **Trace** |
| **② Directly from chat**     | Instantly checking a response you just received mid-conversation         | Chat response action bar › **View Tracing** button               |
| **③ Search by ID**           | Investigating a specific trace from a forwarded ID                       | Evaluation › Tracing › Chat ID / Message ID search               |

<Tabs>
  <Tab title="① From Conversation Logs (Admin)">
    The standard path where an admin picks a specific conversation from the operations screen and enters tracing.

    <Steps>
      <Step title="Open conversation logs">
        Go to **Monitoring › Conversation Logs**.
      </Step>

      <Step title="Select a conversation">
        Click the conversation (request) row you want to investigate to open its detail.

        <Frame caption="Expanding a conversation shows a 'Trace' button on the right">
          <img src="https://mintcdn.com/cloocus/ZXRqlJ18bFKKL0k-/images/monitoring/tracing-entry-conversation-logs.png?fit=max&auto=format&n=ZXRqlJ18bFKKL0k-&q=85&s=5898f366de1cb54b95f70c0f73825347" alt="Entering tracing via the Trace button in conversation logs" width="1369" height="981" data-path="images/monitoring/tracing-entry-conversation-logs.png" />
        </Frame>
      </Step>

      <Step icon="location-dot" title="Arrive at Evaluation › Tracing">
        Clicking the **Trace** button in the detail automatically opens the [**Evaluation › Tracing**](#eval-trace-arrival) screen.
      </Step>
    </Steps>
  </Tab>

  <Tab title="② Directly from Chat">
    The path for tracing a response you just received right from the chat, on the spot.

    <Steps>
      <Step title="Click 'View Tracing' on the response">
        Press the **View Tracing** button in the action bar below the response message you want to trace.

        <Frame caption="The 'View Tracing' button in the action bar below a response">
          <img src="https://mintcdn.com/cloocus/ZXRqlJ18bFKKL0k-/images/monitoring/tracing-entry-chat.png?fit=max&auto=format&n=ZXRqlJ18bFKKL0k-&q=85&s=b0801a7b188b23ebe8edf230fb3cd9f5" alt="View Tracing button on a chat response" width="1369" height="983" data-path="images/monitoring/tracing-entry-chat.png" />
        </Frame>

        The button shown depends on your permissions.

        | Permission                                | Button Shown                                                       |
        | ----------------------------------------- | ------------------------------------------------------------------ |
        | Admin or evaluation read/write permission | **View Tracing** → navigate to Evaluation › Tracing                |
        | Other users                               | **Copy Message ID** → forward to an admin to request investigation |
      </Step>

      <Step icon="location-dot" title="Arrive at Evaluation › Tracing">
        Pressing **View Tracing** automatically opens the [**Evaluation › Tracing**](#eval-trace-arrival) screen.
      </Step>
    </Steps>
  </Tab>

  <Tab title="③ Search by ID">
    Find a trace by directly entering a Chat ID or Message ID. Mainly used when an admin investigates an ID that a regular user copied and forwarded.

    <Steps>
      <Step title="Obtain the Chat ID">
        A chat URL has the form `https://<domain>/c/{Chat ID}`. In the address bar, the UUID after `/c/` (the blue selection below) is that chat's Chat ID — copy this value. (Or obtain the Message ID that a user forwarded.)

        <Frame caption="Chat URL address bar — the blue selection after /c/ is the Chat ID">
          <img src="https://mintcdn.com/cloocus/Jjr6o_i720oXQtQO/images/monitoring/tracing-entry-id-search.png?fit=max&auto=format&n=Jjr6o_i720oXQtQO&q=85&s=c246d44f78a60cc392d53f0f4edd2a71" alt="Chat ID highlighted in blue in the chat URL address bar" width="952" height="680" data-path="images/monitoring/tracing-entry-id-search.png" />
        </Frame>
      </Step>

      <Step icon="location-dot" title="Look up in Evaluation › Tracing">
        Paste it into the search box in Admin panel › [**Evaluation › Tracing**](#eval-trace-arrival) to look it up.
      </Step>
    </Steps>

    <Note>
      The Chat ID in a chat URL is held by the channel owner/user. Admins should ask the user for the URL (or a **Copy Message ID**) and investigate after receiving it.
    </Note>
  </Tab>
</Tabs>

<div id="eval-trace-arrival" />

<Card title="Destination · Evaluation › Tracing" icon="location-dot">
  No matter which of the three paths you enter through, the destination is a single screen: **Evaluation › Tracing** below.

  <Frame caption="Evaluation › Tracing arrival screen — search list (message cards)">
    <img src="https://mintcdn.com/cloocus/ZXRqlJ18bFKKL0k-/images/monitoring/tracing-arrival-search.png?fit=max&auto=format&n=ZXRqlJ18bFKKL0k-&q=85&s=d42aa6b9b654766cbb9c7b853b524f58" alt="Evaluation › Tracing — list of message cards" width="1125" height="980" data-path="images/monitoring/tracing-arrival-search.png" />
  </Frame>
</Card>

Once you arrive, pick a trace from the [search list (message cards)](#searching-traces) and open the [detail view](#how-to-read-the-trace-detail-view).

***

## Searching Traces

Searching by **Chat ID or Message ID** on the Evaluation › Tracing screen produces a **list of message cards** like the screen above.

* Each card is a summary of one user message's trace, and **clicking a card opens the [detail view](#how-to-read-the-trace-detail-view).**

The search-criteria and card-item tables are collapsed below.

<AccordionGroup>
  <Accordion title="Search criteria — Chat ID vs. Message ID" icon="magnifying-glass">
    | Search Criteria | Scope                             | Where to Get It                                           |
    | --------------- | --------------------------------- | --------------------------------------------------------- |
    | **Chat ID**     | All message traces in that chat   | The part after `/c/` in the chat URL                      |
    | **Message ID**  | The trace of one specific message | User selects **Copy Message ID** from the message options |

    <Note>
      Search retrieves all traces matching the entered ID with no time limit. (There are no separate filters such as date or status.)
    </Note>
  </Accordion>

  <Accordion title="Message card items" icon="address-card">
    | Card Item        | Description                                               |
    | ---------------- | --------------------------------------------------------- |
    | **User message** | Original input (max 2 lines)                              |
    | **Trace ID**     | Abbreviated identifier (e.g., `3fb13ae9…`)                |
    | **Time**         | Request time (`MM/DD HH:MM:SS`)                           |
    | **Latency**      | Total processing time (seconds)                           |
    | **Type badges**  | Types of included steps — `Agent` · `LLM` · `Embed`, etc. |
    | **Run count**    | Number of steps (e.g., `3 runs`)                          |
  </Accordion>
</AccordionGroup>

***

## How to Read the Trace Detail View

This is the heart of tracing.

* Here you see **what steps a message went through** and **what went into and came out of** each step.

(Detailed notations such as badges and symbols are collapsed inside each tab — expand them when you encounter an unfamiliar marker.)

<Frame caption="Trace detail — pick a step in the left Run tree and its inputs/outputs appear on the right">
  <img src="https://mintcdn.com/cloocus/KEDVv5ut_6sqAaDJ/images/monitoring/tracing-detail-modal.png?fit=max&auto=format&n=KEDVv5ut_6sqAaDJ&q=85&s=57c9aa30cebf2ddeb95b076c8a9bfe9b" alt="Trace detail modal — Run tree on the left, detail panel on the right" width="2832" height="1748" data-path="images/monitoring/tracing-detail-modal.png" />
</Frame>

The screen is split into the **left Run tree** (lists processing steps in order and hierarchy, with total latency and total tokens at the top) and the **right detail panel** (inputs, outputs, and tokens of the selected step).

A single message typically goes like this — the agent (`CH`) repeats `LM` reasoning and tool calls to gather data, and finally `final_answer` (`LM`) writes the answer.

<Tabs>
  <Tab title="Left — Run Tree">
    Each line (Run) is shown as **colored badge + name + ● status + latency**. Knowing just the frequently seen badges is enough to read the tree. (For the full list including colors, expand the legend below.)

    |  Badge  | What It Does                                                                                          |
    | :-----: | ----------------------------------------------------------------------------------------------------- |
    |  **CH** | Agent run — the step wrapping the entire message processing (name is the agent name, e.g., `dv_test`) |
    |  **LM** | LLM call — reasoning or writing the final answer (`final_answer`)                                     |
    |  **TL** | Tool execution — SQL queries, function calls (`run_sql_read`, etc.)                                   |
    |  **EM** | Embedding — generating vectors for search                                                             |
    | **ACT** | Action group — tool + sub-steps bundle (expand with the arrow)                                        |

    * **● Status** — green means OK, red means an error at that step.
    * **Adjacent time** — that step's latency. The step with the largest value is the bottleneck.

    <Note>
      Auxiliary tasks such as auto-generating the title, tags, and search query are recorded separately from the response in the `background_tasks` trace.
    </Note>

    <AccordionGroup>
      <Accordion title="All Run types (color legend)" icon="table-cells">
        The detail tree distinguishes step types by colored badges. (On search-result cards, they are grouped under labels like `Agent` · `LLM` · `Embed`.)

        |  Badge  | Type       |  Color | Description                                          |
        | :-----: | ---------- | :----: | ---------------------------------------------------- |
        |  **CH** | Chain      | Purple | Composite work — full message processing / agent run |
        |  **LM** | LLM        |  Blue  | LLM call (reasoning, final answer)                   |
        |  **TL** | Tool       |  Green | Tool execution (SQL, functions, etc.)                |
        |  **RG** | Retrieval  | Orange | Knowledge Base document search                       |
        |  **WB** | Web Search |  Cyan  | Web search                                           |
        |  **GD** | Guardrail  |   Red  | Guardrail check                                      |
        |  **EM** | Embedding  | Yellow | Embedding (vector) generation                        |
        |  **FL** | Filter     |  Pink  | Filter function execution                            |
        |  **PP** | Pipeline   |  Navy  | Pipeline processing                                  |
        |  **TK** | Task       |  Gray  | Background task                                      |
        |  **IM** | Image      |  Gray  | Image generation (no dedicated color, gray)          |
        | **ACT** | Action     | Purple | Tool + sub-step group (expandable, synthetic badge)  |
      </Accordion>

      <Accordion title="Status display (● symbol / color)" icon="circle-dot">
        | Status      | Symbol |  Color |
        | ----------- | :----: | :----: |
        | **Success** |    ●   |  Green |
        | **Error**   |    ●   |   Red  |
        | **Running** |    ◐   | Yellow |
        | **Pending** |    ○   |  Gray  |

        <Note>
          The trace's overall status is **Error if any included Run is Error**; if there's no Error but a Running exists, it shows as Running.
        </Note>
      </Accordion>
    </AccordionGroup>
  </Tab>

  <Tab title="Right — Detail Panel">
    Clicking a step in the tree shows that step's details on the right.

    | Section         | Content                                                                          |
    | --------------- | -------------------------------------------------------------------------------- |
    | **Top summary** | Status · latency · model used                                                    |
    | **Inputs**      | Input (system prompt, normalized question, etc.)                                 |
    | **Outputs**     | Output (response, retrieved source count `sources_count` · `source_names`, etc.) |
    | **Token Usage** | **Input · Output · Total** tokens                                                |

    * The **Tree · JSON · Text** toggle switches inputs/outputs between tree, raw JSON, and plain text.
    * The **Search…** box in Outputs lets you find text within long output.

    <Accordion title="Input/output view modes · text search" icon="code">
      | View Mode | Description                 |
      | --------- | --------------------------- |
      | **Tree**  | Hierarchical tree (default) |
      | **JSON**  | Raw JSON                    |
      | **Text**  | Plain text                  |

      Text search works in the Outputs area. Entering a query highlights matches; **Enter** moves to the next match and **Shift+Enter** to the previous one, and the match count is shown next to the search box like `1/5`.
    </Accordion>
  </Tab>
</Tabs>

### Reading in Two Phases

Reading the agent's response in **two phases** helps you find the cause quickly.

```mermaid theme={null}
flowchart TD
    A["CH agent run — Phase 1: data collection"] --> B["LM reasoning — decide which tool to use"]
    B --> C["TL run_sql_read — DB query"]
    B --> D["TL get_table_details — check schema"]
    B --> E["LM reasoning — decide next step"]
    A --> F["LM final_answer — Phase 2: write final answer"]
```

|    Phase    | What                                                                  | What to Look At                                               |
| :---------: | --------------------------------------------------------------------- | ------------------------------------------------------------- |
| **Phase 1** | The agent (`CH`) calls tools (`TL`) via `LM` reasoning to gather data | Which tools were used, whether results were non-empty         |
| **Phase 2** | `final_answer` (`LM`) writes the answer from the gathered data        | Whether the gathered data is properly reflected in the answer |

### Debugging Points

<AccordionGroup>
  <Accordion title="Agent didn't use a tool (Knowledge Base / DB)?" icon="magnifying-glass">
    Check `active_capabilities` (tools/features available at that moment) in the Inputs of Phase 1's **LM reasoning Run**.

    * **Desired tool not in the list** → that feature (Knowledge Base, DB, etc.) isn't connected to the agent
    * **Tool present but not called** → the model judged low relevance between the question and the tool. Make the tool/feature description more specific
  </Accordion>

  <Accordion title="Search ran but the answer is inaccurate?" icon="file-circle-question">
    Check `sources_count` and `source_names` in the Outputs of the `final_answer` (**LM**) Run. (Search results are contained in this output, not in a separate Run.)

    * **`sources_count` is 0** → zero search results. A KB document is missing, or search settings (Top K, Reranker, etc.) need review
    * **Sources exist but the answer is off** → check what was passed in the same Run's Inputs and adjust the answer prompt
  </Accordion>

  <Accordion title="Tool execution failed?" icon="circle-exclamation">
    Click the **TL (Tool) Run** marked with a red ● and check both the error content in Outputs and the parameters passed in Inputs.
  </Accordion>

  <Accordion title="Response too slow?" icon="clock">
    Compare the <strong>latency</strong> next to each step in the Run tree. The longest step is the bottleneck.

    * **LM** slow → consider switching to a faster model
    * **TL/EM** slow → check tool/search settings or external services
    * **GD** (guardrail) slow → disable LLM judgment or switch to a faster model
  </Accordion>
</AccordionGroup>

## Trace Analysis Report

A feature that analyzes trace data with an LLM to **automatically identify the root cause of a problem**.

<Steps>
  <Step title="Start analysis">
    Click the **Trace Analysis** (Analyze Trace) button at the top of the trace detail modal.

    | Input                   | Description                         | Required |
    | ----------------------- | ----------------------------------- | :------: |
    | **Analysis model**      | LLM model used for analysis         | Required |
    | **Problem description** | Description of the observed problem | Optional |

    <Note>
      The analysis model list excludes models with base\_model\_id (custom models), preset models, and arena models. Only base models are selectable.
    </Note>
  </Step>

  <Step title="Review analysis result">
    The LLM comprehensively analyzes trace data + agent settings + conversation history + KB/DB/guardrail settings to generate a structured report.

    | Report Section                  | Content                                                                 |
    | ------------------------------- | ----------------------------------------------------------------------- |
    | **Summary**                     | 2\~3 sentence core summary of the analysis                              |
    | **Trace overview**              | ID, status, latency, tokens, Run count, error count                     |
    | **Root cause analysis**         | Primary cause + contributing factors                                    |
    | **Phase 1 analysis**            | Whether tool selection was appropriate, available vs. actual tool calls |
    | **Phase 2 analysis**            | Appropriateness of the final answer relative to collected data          |
    | **Prompt/setting issues**       | System prompt, model selection issues                                   |
    | **KB/RAG issues**               | Search settings, document quality, filter issues                        |
    | **DB/SQL issues**               | NL-to-SQL conversion, schema issues                                     |
    | **Guardrail issues**            | Excessive blocking, false positives                                     |
    | **Error analysis**              | Error Run detailed diagnosis                                            |
    | **Improvement recommendations** | Immediate actions, setting changes, data improvements                   |

    <Tip>
      Entering a problem description enables analysis focused on that context. Example: "KB found documents but they weren't reflected in the answer"
    </Tip>
  </Step>

  <Step title="Save/share report">
    | Feature      | Description                     |
    | ------------ | ------------------------------- |
    | **Copy**     | Copy full text to clipboard     |
    | **Download** | Download as markdown file (.md) |
  </Step>
</Steps>

<Note>
  When a previously analyzed report exists, the **"View Report"** button shows it directly without re-analysis.
</Note>

***

## Trace Management

### Permissions

| Role             | Permission                          |
| ---------------- | ----------------------------------- |
| **Regular user** | Can only view own traces            |
| **Admin**        | View and manage traces of all users |

### Data Cleanup

Old traces are cleaned up via the `/api/traces/cleanup` **developer API**.

* Bulk-delete traces before a specific timestamp (in milliseconds, ms).

<Warning>
  Trace deletion is irreversible. Download necessary analysis reports before deleting.
</Warning>

***

## Use Cases

<AccordionGroup>
  <Accordion title="Response Quality Debugging" icon="magnifying-glass-chart">
    1. Click the **View Tracing** button on a chat message
    2. Select the `final_answer` (**LM**) step in the left Run tree
    3. In **Outputs**, check `sources_count` · `source_names` to see whether search results were reflected
    4. In **Inputs**, check what was passed to the model
    5. Generate a **Trace Analysis Report** to auto-identify the root cause
  </Accordion>

  <Accordion title="Latency Analysis" icon="clock">
    1. Open the trace of a slow response
    2. Compare the <strong>latency</strong> next to each step in the Run tree
    3. Identify the longest step (e.g., tool 0.8s, LLM 3.2s)
    4. Optimize that step (adjust search settings, change the model, etc.)
  </Accordion>

  <Accordion title="Tool Execution Error Tracking" icon="circle-exclamation">
    1. Open the suspected trace
    2. Select the **TL (Tool) Run** marked with a red ●
    3. Check the error content in **Outputs**
    4. Verify the passed parameters in **Inputs**
  </Accordion>

  <Accordion title="Token Usage Analysis" icon="coins">
    1. Check overall trace usage via **total tokens** at the top of the detail view
    2. Compare per-LM Run **Token Usage** (Input/Output/Total) in the Run tree
    3. Check the token ratio of Phase 1 (agent run) vs. Phase 2 (`final_answer`)
    4. Identify unnecessarily large prompts or repeated calls
  </Accordion>
</AccordionGroup>

***

## FAQ

<AccordionGroup>
  <Accordion title="Is tracing recorded automatically?" icon="circle-question">
    Yes — when message tracing is enabled (default: enabled), all AI requests are auto-recorded. No additional setup needed.
  </Accordion>

  <Accordion title="How long is trace data retained?" icon="circle-question">
    Default retention is **30 days**. Admins can change settings or manually clean up.
  </Accordion>

  <Accordion title="Does tracing affect response speed?" icon="circle-question">
    Trace recording is asynchronously processed in the background, so it has nearly no impact on response speed.
  </Accordion>

  <Accordion title="Do analysis reports also consume tokens?" icon="circle-question">
    Yes — trace analysis is a separate LLM call, tracked in usage as `trace_analysis`. Analysis only runs when manually triggered.
  </Accordion>
</AccordionGroup>

***

## Related Pages

<Columns cols={3}>
  <Card title="Guardrail Logs" icon="shield-check" href="/en/monitoring/guardrail-logs">
    Dedicated log for guardrail detection events
  </Card>

  <Card title="Auto-Evaluations" icon="chart-line" href="/en/monitoring/auto-evaluations">
    Automatic evaluation results for agent response quality
  </Card>

  <Card title="Usage" icon="coins" href="/en/monitoring/usage">
    Token usage and cost analysis
  </Card>
</Columns>
