Skip to content

Gemini Model not returning Usage Metadata in Streaming responses #777

@chaskyhoffmann

Description

@chaskyhoffmann

** Please make sure you read the contribution guide and file the issues in the rigth place. **
Contribution guide.

Describe the bug
When using streaming mode, the Gemini Model does not return the usageMetadata in the LlmResponse. When stream=true the usageMetadata should return in the final aggregated response.

To Reproduce
Steps to reproduce the behavior:

  1. Create an LlmAgent with the Gemini model.
  2. In the RunConfig set the streaming model to RunConfig.StreamingMode.SSE
  3. observe the LlmResponse in afterModelCallback of a plugin or agent.
  4. See that both for partial and final LLM responses, usageMetadata is Optional.Empty

Expected behavior
The final and non-partial LlmResponse should include the usageMetadata.

Desktop (please complete the following information):

  • OS: MacOS
  • Java version:
  • ADK version(see maven dependency): 0.5.0

Additional context
The python version of ADK returns the usageMetadata correctly.
The usageMetadata is returned from the Gemini API in the last chunk.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions