Skip to content

Conversation

@jerry-heygen
Copy link
Contributor

Summary

  • Fix regression where ThinkingPart.signature was never populated for Google model responses (introduced in Don't insert empty ThinkingPart when Google response ends in text with thought_signature #3516)
  • This caused thinking context to be lost in follow-up requests, as Google requires the thought_signature to be sent back to maintain reasoning continuity
  • Google's API returns thought_signature on the part following the thinking content (e.g., TextPart or ToolCallPart), not on the ThinkingPart itself
  • The fix applies the signature from the following part back to the preceding ThinkingPart.signature

Problem

After #3516, ThinkingPart.signature was always null. The signature was being stored in provider_details on the TextPart/ToolCallPart, but never preserved on the ThinkingPart.

This is critical because when sending message history back to Google, _content_model_response() reads from ThinkingPart.signature to include the signature on the next part. Without it, thinking context is lost in multi-turn conversations.

Per Google's documentation:

"Signatures are returned from the model within other parts in the response, for example function calling or text parts."
"Always send the thought_signature back to the model inside its original Part."

Solution

Non-streaming path: Track last_thinking_part and when a non-thinking part arrives with thought_signature, apply it back to ThinkingPart.signature.

Streaming path: When a non-thinking part with thought_signature arrives, emit a handle_thinking_delta event with the signature to update the previous thinking part.

Test plan

  • All existing Google model tests pass (88 passed, 14 skipped)
  • test_google_thought_signature_on_thinking_part verifies round-trip behavior
  • Updated snapshots to include signature=IsStr() on ThinkingParts

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.

1 participant