Skip to main content

Overview

Every agent exposes a single read-only agent.usage property. It returns an AggregatedUsage view derived from the centralized usage registry on each access, scoped to this agent’s agent_usage_id. Sub-pipeline model calls — memory summarization, reliability validator/editor, culture, policy, and sub-agents invoked as tools — automatically inherit the agent’s scope and roll into agent.usage without any manual propagation. When printing is enabled (print_do / print_do_async), an Agent Metrics panel is displayed after each task so you can see the updated totals.

Accessing Agent Metrics

Read agent.usage on any Agent instance. It always returns an AggregatedUsage — zero-valued before the first run, populated thereafter.

Token Metrics

Request & Tool Metrics

Timing Metrics

Cost Metrics

Aggregation Metadata

Example

Printed Panel

When you use print_do or print_do_async, the Agent Metrics panel displays after each task:

Scope & Propagation

  • Across tasks — Every call to do / print_do / do_async / print_do_async records entries against the agent’s scope. Reading agent.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 parent’s scope via context variables and roll into agent.usage automatically.
  • Retry idempotency — The registry is keyed by entry_id. Retried requests replace their prior entry instead of double-counting.
  • Independent agents — Each Agent instance has its own agent_usage_id. Two different agents never share usage.
  • JSON snapshot — Call agent.usage.to_dict() for a flat dict suitable for logs and dashboards.

Legacy Migration

Legacy surfaces have been removed in favour of agent.usage: