Skip to content

Conversation

@surenkov
Copy link
Contributor

@surenkov surenkov commented Nov 24, 2025

This PR updates the Gemini backend to preserve thoughtSignature fields, which is mandatory for Gemini 3 Pro and recommended for Gemini 2.5.

Gemini reasoning models return an encrypted thoughtSignature alongside text or function calls to maintain reasoning context in their stateless API. Per Gemini API specifications:

When using Gemini 3 Pro, you must pass back thought signatures during function calling, otherwise you will get a validation error (4xx status code).

Previously, gptel-gemini discarded this signature. This change ensures the signature is retained and sent back in the conversation history for subsequent turns, preventing API errors with reasoning models.

Changes:

  • Response Parsing:
    • The thoughtSignature is extracted and attached to the tool-use plist if a functionCall is present.
    • For text responses, the thoughtSignature is stored as a 'gptel-gemini-thought-signature text property on the response content in the buffer.
  • History Extraction:
    • The signature is retrieved from the text property for model text responses and from the tool call plist for model function calls.
    • The retrieved thoughtSignature is then included in the message structure sent back to the Gemini API.

Closes #1146

@surenkov surenkov force-pushed the master branch 2 times, most recently from d8732c3 to 385fc46 Compare November 27, 2025 11:28
@surenkov surenkov marked this pull request as draft November 27, 2025 20:55
@surenkov surenkov closed this Nov 29, 2025
@surenkov surenkov reopened this Nov 29, 2025
@surenkov surenkov force-pushed the master branch 3 times, most recently from b18c8cb to 2b930c2 Compare November 29, 2025 15:49
@surenkov surenkov marked this pull request as ready for review December 1, 2025 08:59
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.

support gemini thought_signature

1 participant