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

# fact_ai_conversations

> One row per conversation handled by an AI agent inside your flows.

# fact\_ai\_conversations

Each row is one conversation handled by an AI agent inside a conversation flow: which agent (and which version) handled it, how it was resolved, what sentiment the user showed, how many messages were exchanged, and how many tokens it consumed.

> [!WARNING]
>
> Don't confuse it with [`fact_agent_conversations`](https://help.treble.ai/en/docs/data-warehouse-v2/fact-agent-conversations): that table holds conversations handled by **human agents** in the agent workspace. The names are almost identical, but they are different products — don't mix the two tables in the same metric.

## What questions does it answer?

* How many conversations did each AI agent handle, and how many did it resolve?
* How does user sentiment change across agents or across versions of an agent?
* How many tokens does each agent consume, in total and per conversation?
* How long does the agent take to respond?
* What happened in the rest of the flow before and after the AI? (join `fact_treble_sessions` on `session_id`)

## Columns

| Column | Type | Description |
| - | - | - |
| `evaluation_id` | Int64 | Unique AI conversation identifier |
| `company_id` | Int32 | Your company (filtered automatically) |
| `session_id` | Int64 | The conversation flow it happened in (join `fact_treble_sessions`); `0` if none |
| `agent_type` | String | AI agent type: `AI_TASK_AUTOMATOR`, `AI_LEAD_QUALIFICATION`, `AI_AGENT_NODE`, `AI_OBJECTIVE_AGENT` |
| `agent_id` | String | AI agent identifier, the same across all its versions (joins `dim_poll_nodes.ai_automator_id`, converted to text) |
| `agent_version` | Int32 | Version of the agent that handled the conversation |
| `agent_name` | String | Agent name |
| `created_at` | DateTime64 | When the AI conversation was recorded |
| `resolution_status` | String | Outcome according to the conversation's evaluation: `RESOLVED`, `PARTIALLY_RESOLVED`, `UNRESOLVED`, `IN_PROGRESS`, or `PENDING` while not yet evaluated |
| `sentiment_label` | String | User sentiment according to the evaluation: `VERY_POSITIVE`, `POSITIVE`, `NEUTRAL`, `NEGATIVE`, `VERY_NEGATIVE`, or `PENDING` while not yet evaluated |
| `prompt_tokens` | UInt64 | Input (prompt) tokens consumed; `NULL` if not recorded |
| `completion_tokens` | UInt64 | Tokens generated by the model; `NULL` if not recorded |
| `total_tokens` | UInt64 | Total tokens for the conversation; `NULL` if not recorded |
| `reasoning_tokens` | UInt64 | Model reasoning tokens; `NULL` if not recorded |
| `message_count` | UInt64 | Number of messages in the conversation; `NULL` if not recorded |
| `word_count` | UInt64 | Number of words in the conversation; `NULL` if not recorded |
| `character_count` | UInt64 | Number of characters in the conversation; `NULL` if not recorded |
| `avg_response_duration_ms` | UInt64 | Average agent response time, in milliseconds; `NULL` if not recorded |
| `contact_country_code` | String | User's country code |
| `contact_phone` | String | User's phone number |
| `contact_id` | Int64 | Treble contact; `0` if none |
| `synced_at` | DateTime64 | When this row was last written/corrected |

> [!NOTE]
>
> Counts and tokens are `NULL` when the conversation didn't record them — for example, conversations from before Treble started measuring tokens. `NULL` **never means zero**: `sum()` and `avg()` already ignore `NULL`s, and `countIf(total_tokens IS NOT NULL)` tells you how many conversations have a measurement.

## Example queries

### Resolution and sentiment per agent, last 30 days

```sql theme={null}
SELECT
    agent_name,
    count()                                                      AS conversations,
    countIf(resolution_status NOT IN ('PENDING', 'IN_PROGRESS')) AS evaluated,
    countIf(resolution_status = 'RESOLVED')                      AS resolved,
    round(100.0 * resolved / nullIf(evaluated, 0), 1)            AS resolved_pct,
    countIf(sentiment_label IN ('POSITIVE', 'VERY_POSITIVE'))    AS positive
FROM fact_ai_conversations
WHERE created_at >= today() - 30
GROUP BY agent_name
ORDER BY conversations DESC
```

### Token consumption per agent and version

```sql theme={null}
SELECT
    agent_name,
    agent_version,
    count()                              AS conversations,
    countIf(total_tokens IS NOT NULL)    AS measured,
    sum(total_tokens)                    AS tokens,
    round(avg(total_tokens))             AS avg_tokens_per_conversation
FROM fact_ai_conversations
WHERE created_at >= today() - 30
GROUP BY agent_name, agent_version
ORDER BY tokens DESC
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.