Overview
Your Agent keeps a singleusage object (AgentUsage) that accumulates metrics over every run. Use it to monitor total tokens, requests, tool calls, cost, and detailed timing breakdowns for that agent.
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
On anyAgent instance, use agent.usage. It returns an AgentUsage object (or None before the first run).
Token Metrics
| Property | Type | Description |
|---|---|---|
input_tokens | int | Total prompt/input tokens across all runs |
output_tokens | int | Total completion/output tokens across all runs |
total_tokens | int | Sum of input_tokens + output_tokens |
cache_write_tokens | int | Total tokens written to the cache |
cache_read_tokens | int | Total tokens read from the cache |
reasoning_tokens | int | Total tokens used for reasoning (e.g. chain-of-thought) |
Request & Tool Metrics
| Property | Type | Description |
|---|---|---|
requests | int | Total number of LLM API requests made |
tool_calls | int | Total number of tool calls executed |
Timing Metrics
| Property | Type | Description |
|---|---|---|
duration | float | None | Total execution time across all runs (seconds) |
model_execution_time | float | None | Total time spent inside LLM API calls (seconds) |
tool_execution_time | float | None | Total time spent executing tools across all runs (seconds) |
upsonic_execution_time | float | None | Framework overhead = duration - model_execution_time - tool_execution_time (seconds) |
Cost Metrics
| Property | Type | Description |
|---|---|---|
cost | float | None | Estimated total cost across all runs (provider-specific) |
Example
Printed Panel
When you useprint_do or print_do_async, the Agent Metrics panel displays after each task:
Accumulation Behavior
- Across tasks: Every call to
do/print_do/do_async/print_do_asyncadds to the sameagent.usage. TheAgentUsageobject accumulates each task’sTaskUsagevia itsincr()method. - Sub-agent propagation: When an agent uses another agent as a tool, the sub-agent’s usage (tokens, requests, tool calls, cost, timing) is propagated into the parent agent’s
usage. - Independent agents: Each
Agentinstance has its own independentAgentUsage. Two different agents never share usage.

