fix(models): populate LlmResponse.model_version in AnthropicLlm - #6851
Open
feiiiiii5 wants to merge 1 commit into
Open
fix(models): populate LlmResponse.model_version in AnthropicLlm#6851feiiiiii5 wants to merge 1 commit into
feiiiiii5 wants to merge 1 commit into
Conversation
AnthropicLlm never set model_version on either path, so the resolved snapshot id (model aliases resolve server-side, e.g. claude-sonnet-5 -> a dated snapshot) was lost for every direct-API response. Every other first-party wrapper already records it: google_llm from the Gemini response, lite_llm from response.model, apigee_llm from the payload. Downstream consumers rely on it — event telemetry, persisted Event rows, and the gen_ai.response.model span attribute. - message_to_generate_content_response: model_version=message.model - streaming: capture event.message.model at message_start, yield it on the final aggregated response (guarded on str so partial/mock streams that omit the field cannot poison the field) Fixes google#6847 Signed-off-by: fei <204683769+feiiiiii5@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
AnthropicLlmnever setLlmResponse.model_versionon either path, so the model id Anthropic actually served was lost for every direct-API response. Model aliases (e.g.claude-sonnet-5) resolve to a dated snapshot server-side, andmodel_versionis ADK's existing mechanism for recording which snapshot served a response — event telemetry,DatabaseSessionService-persistedEventrows, and thegen_ai.response.modelspan attribute all read it. Every other first-party wrapper already populates it:google_llm.py(Gemini response),lite_llm.py(response.model),apigee_llm.py(response.get('model')).Changes
message_to_generate_content_response):model_version=message.model.event.message.modelin themessage_starthandler (alongside the existing usage accounting reads) and carry it on the final aggregatedLlmResponse. The capture is guarded onisinstance(..., str)so streams that omit the field cannot poison a typed field.partial=Truechunks are unchanged — the aggregated final response is the authoritative record, matching how usage metadata is handled.Fixes #6847
Tests
test_message_to_generate_content_response_sets_model_version— non-streaming: the builder propagatesmessage.model.test_streaming_final_response_carries_model_version— streaming:message_start's resolved id reaches the final yield (partial=False).main(model_version isNone); fulltests/unittests/models/test_anthropic_llm.pysuite: 138 passed with the change.CLA
Google CLA signed.