fix: strip embedded thought signature from LiteLLM tool call ids - #6599
Open
benclarkeio wants to merge 1 commit into
Open
fix: strip embedded thought signature from LiteLLM tool call ids#6599benclarkeio wants to merge 1 commit into
benclarkeio wants to merge 1 commit into
Conversation
LiteLLM embeds a Gemini `thought_signature` in the tool call id, separated by `__thought__`. `_message_to_generate_content_response` already lifts that signature onto `part.thought_signature`, but then assigned the raw id to `part.function_call.id`, so every consumer of `function_call_id` saw a few hundred characters of base64 appended to the real id. - Split the separator off the id before assigning it to the function call - Leave `thought_signature` extraction unchanged, so nothing is lost The round trip is unaffected: `_content_to_message_param` re-attaches the signature to the outgoing tool call from `part.thought_signature` via `provider_specific_fields` and `extra_content.google.thought_signature`, and `_extract_thought_signature_from_tool_call` reads both of those before it falls back to the id-embedded form. Both sides of the call/response pairing are generated from ADK's own stored parts, so ids stay matched. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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.
Problem
LiteLLM embeds a Gemini
thought_signatureinside the tool call id, separated by__thought__(see_THOUGHT_SIGNATURE_SEPARATOR)._message_to_generate_content_responsealready extracts that signature ontopart.thought_signature, but then assigns the raw id topart.function_call.id:So every consumer of
function_call_idgets several hundred characters of base64 glued onto the real id. In practice this leaks into artifact filenames, logs, and any UI that displays a tool call id — for example a saved artifact named:Fix
Split the separator off before assigning the id. The signature is already preserved on the part, so nothing is lost.
Why the round trip still works
_content_to_message_paramre-attaches the signature to the outgoing tool call frompart.thought_signature, via bothprovider_specific_fieldsandextra_content.google.thought_signature._extract_thought_signature_from_tool_callchecks those two locations before falling back to the id-embedded form, which exists only for providers that drop the other channels.tool_callsentry and thetoolmessage'stool_call_id) are generated from ADK's own stored parts, so stripping consistently keeps them matched.Testing
Added
test_message_to_generate_content_response_strips_signature_from_id, asserting the id is split and the signature still lands on the part. Fulltests/unittests/models/test_litellm.pypasses (257 passed).