Fix GoogleModel thinking signature not preserved in multi-turn conversations #3647
+48
−11
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.
Summary
ThinkingPart.signaturewas never populated for Google model responses (introduced in Don't insert emptyThinkingPartwhenGoogleresponse ends in text withthought_signature#3516)thought_signatureto be sent back to maintain reasoning continuitythought_signatureon the part following the thinking content (e.g., TextPart or ToolCallPart), not on the ThinkingPart itselfThinkingPart.signatureProblem
After #3516,
ThinkingPart.signaturewas alwaysnull. The signature was being stored inprovider_detailson the TextPart/ToolCallPart, but never preserved on the ThinkingPart.This is critical because when sending message history back to Google,
_content_model_response()reads fromThinkingPart.signatureto include the signature on the next part. Without it, thinking context is lost in multi-turn conversations.Per Google's documentation:
Solution
Non-streaming path: Track
last_thinking_partand when a non-thinking part arrives withthought_signature, apply it back toThinkingPart.signature.Streaming path: When a non-thinking part with
thought_signaturearrives, emit ahandle_thinking_deltaevent with the signature to update the previous thinking part.Test plan
test_google_thought_signature_on_thinking_partverifies round-trip behaviorsignature=IsStr()on ThinkingParts