Skip to content

feat: handle usageUpdate events and populate UsageMetadata in AgentResponse - #2

Merged
glaforge merged 1 commit into
mainfrom
print_usage_metadata
Sep 23, 2026
Merged

glaforge merged 1 commit into
mainfrom
print_usage_metadata

Conversation

@glaforge

Copy link
Copy Markdown
Owner

Improvements & Bug Fixes

  • Handle usageUpdate events: Process dedicated usageUpdate and top-level usageMetadata OutputEvents sent by localharness, ensuring UsageMetadata is populated in AgentResponse.
  • Session & Turn Accounting: Track cumulative token usage across the session and compute per-turn delta via subtract(). Expose agent.getTotalUsage() and agent.getTrajectoryUsages().
  • Wire Compatibility: Parse both camelCase and snake_case field variants (e.g. promptTokenCount / prompt_token_count) for token metrics and modality breakdown.
  • Ergonomic Aliases: Add response.usage() convenience alias matching SDK documentation.
  • UsageMetadata Arithmetic: Enhance add() and subtract() identity handling for zero token counts to preserve modality details.
  • Testing: Add fast unit tests (UsageMetadataParsingTest) and strengthen ObservabilityTest assertions against live localharness.

@glaforge
glaforge merged commit 3b5eb44 into main Sep 23, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant