Skip to main content

Overview

Every chat session exposes a single read-only chat.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

Read chat.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.stream adds entries under the chat’s scope. Reading chat.usage re-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.usage automatically.
  • 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 same session_id re-hydrates the registry, so chat.usage continues 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: