Skip to content

adk align Google usage metadata token metrics #638

Description

Problem

The Python ADK integration currently maps Google UsageMetadata as:

  • prompt_tokens = prompt_token_count
  • completion_tokens = candidates_token_count
  • completion_reasoning_tokens = thoughts_token_count
  • tokens = total_token_count

This leaves thoughts_token_count out of the completion total and ignores tool_use_prompt_token_count. For reasoning or tool-using calls, the emitted prompt/completion breakdown can therefore disagree with the provider total and with Braintrust instrumentation semantics.

Current implementation: py/src/braintrust/integrations/adk/tracing.py

Provider reference: Google GenerateContent UsageMetadata

Expected behavior

Align ADK usage extraction with the Python Google GenAI integration:

  • prompt_tokens = prompt_token_count + (tool_use_prompt_token_count or 0)
  • completion_tokens = candidates_token_count + (thoughts_token_count or 0)
  • retain completion_reasoning_tokens = thoughts_token_count as the reasoning breakdown
  • retain tokens = total_token_count when Google reports it
  • preserve any useful provider-specific modality/detail breakdowns as metadata rather than adding nonstandard metrics
  • preserve zero values and omit values Google did not report

Acceptance criteria

  • Add VCR-backed ADK coverage using real Google response shapes for reasoning and tool-use prompt usage.
  • Assert the aggregate prompt/completion metrics and the reasoning detail metric.
  • Assert tokens == prompt_tokens + completion_tokens when all components are reported.
  • Validate every configured google-adk version in the Python provider matrix, accounting for version-specific field availability.

This is a Python ADK integration change; no instrumentation-spec update should be needed because all emitted metric keys are already standard.

Metadata

Metadata

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions