Skip to content

fix: MessageConverter.toLlmResponse does not map ChatResponse Usage to LlmResponse#1161

Open
hemasekhar-p wants to merge 1 commit intogoogle:mainfrom
hemasekhar-p:springai-metadata-missing-fix
Open

fix: MessageConverter.toLlmResponse does not map ChatResponse Usage to LlmResponse#1161
hemasekhar-p wants to merge 1 commit intogoogle:mainfrom
hemasekhar-p:springai-metadata-missing-fix

Conversation

@hemasekhar-p
Copy link
Copy Markdown

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

Problem:
When using the adk-java-springai module, token consumption statistics are completely lost. The adapter's MessageConverter successfully parses text content but drops the metadata payload.

Solution:
Updated MessageConverter.toLlmResponse to intercept the Spring AI Usage metadata and map promptTokens, completionTokens, and totalTokens to the ADK's native GenerateContentResponseUsageMetadata.

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Added three new targeted test cases to MessageConverterTest which all pass successfully:

  1. usageMetadataShouldBeEmptyWhenSpringAiMetadataIsNull
  2. usageMetadataShouldBeEmptyWhenSpringAiUsageIsNull
  3. usageMetadataShouldDefaultToZeroWhenSpringAiTokensAreNull

@hemasekhar-p hemasekhar-p reopened this Apr 29, 2026
@hemasekhar-p hemasekhar-p self-assigned this Apr 29, 2026
@ddobrin ddobrin self-requested a review April 29, 2026 13:58
@ddobrin
Copy link
Copy Markdown
Contributor

ddobrin commented Apr 29, 2026

LGTM

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.

[google-adk-spring-ai] MessageConverter.toLlmResponse does not map ChatResponse Usage to LlmResponse

2 participants