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

> The availability history of every agent.

# fact\_agent\_status\_changes

Each row is one change of an agent's availability: going online (available to receive conversations) or offline. Reconstructing the sequence gives you each agent's connected time and availability patterns.

## What questions does it answer?

* How many hours was each agent available per day?
* When do agents connect and disconnect?
* How does team availability align with conversation demand?

## Columns

| Column             | Type       | Description                                                               |
| ------------------ | ---------- | ------------------------------------------------------------------------- |
| `status_change_id` | Int32      | Unique identifier of the change                                           |
| `company_id`       | Int32      | Your company (filtered automatically)                                     |
| `agent_id`         | Int32      | The agent                                                                 |
| `agent_name`       | String     | The agent's name                                                          |
| `created_at`       | DateTime64 | When the status changed                                                   |
| `old_status`       | Bool       | Availability before the change: `true` = available, `false` = unavailable |
| `new_status`       | Bool       | Availability after the change: `true` = available, `false` = unavailable  |
| `synced_at`        | DateTime64 | When this row was last written/corrected                                  |

## Example queries

### Daily available minutes per agent (interval reconstruction)

```sql theme={null}
SELECT
    agent_name,
    toDate(created_at) AS day,
    round(sum(
        dateDiff('second', created_at,
                 leadInFrame(created_at) OVER (
                     PARTITION BY agent_id, toDate(created_at)
                     ORDER BY created_at
                     ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING))
        * if(new_status = true, 1, 0)
    ) / 60, 1) AS available_minutes
FROM fact_agent_status_changes
WHERE created_at >= today() - 7
GROUP BY agent_name, day
ORDER BY day, agent_name
```

<Note>
  For most reporting you don't need to reconstruct intervals yourself — [`fact_agent_daily`](/en/docs/data-warehouse-v2/fact-agent-daily) already exposes `available_minutes` per agent per day.
</Note>
