AI agent usage logs
One row per LLM call a Chatwoot/iframe/specialist agent turn made —
README_AIAGENTUSAGE_TOKENS.md. `bots/engine.py::run_bot_turn` already
computes `usage` (token buckets) and `cost_usd` (real cost under the
provider's pricing) for every turn, but until this model existed that
number only ever reached a `logger.info` line ("bots.cost: ...") and was
discarded — there was no way to answer "how much did agent X spend last
week" without grepping raw server logs with no `agent_key` in the line.
Written best-effort right after each `run_bot_turn` call (see
`bots/usage_tracking.py::record`) — a failure saving this row must never
break the reply the customer is waiting for.
| Field | Description |
|---|---|
| AI agent | Null only for a turn where bot_config carried no agent_id — should not happen on the DB-backed path, kept nullable defensively so a bad turn never loses the whole row. |
| Company | |
| Conversation | Channel-qualified conversation id, e.g. chatwoot:536 — empty for synthetic test turns with no real conversation behind them. |
| Channel | Options:
|
| LLM model | |
| LLM calls in this turn | A turn may loop through several API calls (tool-use round-trips) — this is the count actually accumulated, not always 1. |
| Input tokens | |
| Output tokens | |
| Cache read tokens | |
| Cache creation tokens | |
| Cost (USD) | Real cost of this turn under the provider's per-token pricing (bots/engine.py::usage_cost_usd) — not a raw token count, an output token costs several times an input one. |
AI agent usage logs It has the following related modules and may be of interest to you: