> ## 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_agent_messages

> One row per message in an agent conversation.

# fact\_agent\_messages

Each row represents an individual message within an agent conversation. Includes the content, who sent it, and the delivery and read statuses.

## What questions does it answer?

* What messages were sent in each conversation?
* Who sent each message (agent or user)?
* How many messages does each agent send per day?
* What was the agent's response time?
* Were the messages read?

## Columns

| Column                  | Type       | Description                                                                  |
| ----------------------- | ---------- | ---------------------------------------------------------------------------- |
| `message_id`            | Int32      | Unique message identifier                                                    |
| `company_id`            | Int32      | Company identifier (filtered automatically)                                  |
| `conversation_id`       | Int32      | Conversation the message belongs to                                          |
| `survey_user_id`        | Int64      | Identifier of the associated conversation flow. `0` if none                  |
| `created_at`            | DateTime64 | Message date and time                                                        |
| `sender`                | String     | Who sent the message: `AGENT`, `USER`, `SYSTEM`                              |
| `category`              | String     | Content type: `text`, `image`, `video`, `audio`, `document`, `hsm`           |
| `content`               | String     | Message content in JSON format                                               |
| `agent_id`              | Int32      | Identifier of the sending agent (if `sender = AGENT`). `0` if not applicable |
| `agent_name`            | String     | Agent name                                                                   |
| `team_name`             | String     | Agent team                                                                   |
| `read_at`               | DateTime64 | Read date. `NULL` if not read                                                |
| `delivered_at`          | DateTime64 | Delivery date. `NULL` if not delivered                                       |
| `reply_provider_msg_id` | String     | ID of the message replied to (if it is a reply)                              |
| `reaction`              | String     | Reaction to the message (emoji)                                              |

## Example queries

### Messages per agent in the last 7 days

```sql theme={null}
SELECT
    agent_name,
    count() AS messages_sent,
    countIf(category = 'hsm') AS templates_sent
FROM client_analytics.fact_agent_messages
WHERE created_at >= now() - INTERVAL 7 DAY
  AND sender = 'AGENT'
GROUP BY agent_name
ORDER BY messages_sent DESC
```

### First response time per conversation

```sql theme={null}
SELECT
    conversation_id,
    min(created_at) AS first_agent_response
FROM client_analytics.fact_agent_messages
WHERE sender = 'AGENT'
  AND created_at >= now() - INTERVAL 7 DAY
GROUP BY conversation_id
```

### Message content of a specific conversation

```sql theme={null}
SELECT
    created_at,
    sender,
    agent_name,
    category,
    content
FROM client_analytics.fact_agent_messages
WHERE conversation_id = 12345
ORDER BY created_at
```
