improve agent usage metrics
Merged
TK
10mo ago+16+16+01234567890123456789-11-11-01234567890123456789
Why
The agent handler was using usage from generateText() which only reflects the token usage of the last step. For multi-step agent executions, this results in underreported token counts.
What Changed
Updated v3AgentHandler.ts to use totalUsage instead of usage. The totalUsage field from the AI SDK represents the sum of token usage across all steps, providing accurate totals for:
- Input tokens
- Output tokens
- Reasoning tokens
- Cached input tokens
Test Plan
- Verify token metrics are correctly reported for multi-step agent executions
Summary by cubic
Fix underreported agent token metrics by using totalUsage for multi-step executions. Token totals now reflect all steps.
- Bug Fixes
- Use totalUsage from the AI SDK in v3AgentHandler to compute metrics.
- Response payload includes accurate totals for input, output, reasoning, and cached input tokens, plus inference_time_ms.