Overview
Every chat session exposes a single read-onlychat.usage property. It returns an AggregatedUsage view derived from the centralized usage registry on each access, scoped to this chat’s chat_usage_id.
The session’s own agent calls, sub-agents, memory summarization, reliability passes, culture, and policy checks all inherit the chat scope and roll into chat.usage automatically.
For wall-clock session length, use chat.duration (or chat.end_time - chat.start_time for an explicit window).
Accessing Chat Metrics
Readchat.usage on any Chat instance. It always returns an AggregatedUsage — zero-valued before the first message, populated thereafter.
Token Metrics
Request & Tool Metrics
Timing Metrics
Cost Metrics
Aggregation Metadata
Session Wall-Clock & Messages
Example
JSON-Friendly Output
Scope & Propagation
- Across invocations — Every
chat.invoke/chat.streamadds entries under the chat’s scope. Readingchat.usagere-aggregates them, so the figures always reflect the latest state. - Sub-pipeline rollup — Memory summarization, reliability validator/editor, culture, policy, and sub-agent calls inherit the chat scope via context variables and roll into
chat.usageautomatically. - Retry idempotency — The registry is keyed by
entry_id. Retried requests replace their prior entry instead of double-counting. - Persistence — When you configure storage on
Chat, recorded entries persist alongside the conversation. Re-opening the samesession_idre-hydrates the registry, sochat.usagecontinues from where it left off across processes and restarts.
Legacy Migration
Legacy chat-level properties and helpers have been removed in favour of
chat.usage:Related Documentation
- Usage Registry — Architecture, scope tags, persistence
- Agent Metrics — Accumulated agent-level view
- Task Metrics — Per-task scoped view
- Team Metrics — Per-team scoped view
- Storage Backends — Persisting usage across processes

