Add thought signature support for Google Gemini OpenAI compatibility#588
Open
ericproulx wants to merge 1 commit intocrmne:mainfrom
Open
Add thought signature support for Google Gemini OpenAI compatibility#588ericproulx wants to merge 1 commit intocrmne:mainfrom
ericproulx wants to merge 1 commit intocrmne:mainfrom
Conversation
This change enables RubyLLM to preserve and transmit thought signatures when using Google Gemini models through the OpenAI-compatible API. Thought signatures are part of Gemini's extended reasoning capabilities and need to be preserved in the extra_content field when working with tool calls. Changes: - Extract thought signatures from extra_content.google.thought_signature in incoming tool calls - Include thought signatures in outgoing tool calls when present - Add comprehensive test coverage for thought signature handling
This was referenced Jan 29, 2026
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.
Summary
This PR adds support for preserving and transmitting thought signatures when using Google Gemini models through the OpenAI-compatible API. This enables seamless integration with Gemini's extended reasoning capabilities while maintaining compatibility with the OpenAI API format.
Background
Google Gemini models support extended reasoning through "thinking" modes, which generate thought signatures that need to be preserved when working with tool calls. When using Gemini models through an OpenAI-compatible endpoint, these thought signatures are transmitted in the
extra_content.google.thought_signaturefield, following the OpenAI Realtime API's extension pattern.Changes
Provider Implementation
lib/ruby_llm/providers/openai/tools.rb:extract_tool_call_thought_signaturemethod to extract signatures from incoming tool callsparse_tool_callsto preserve thought signatures inToolCallobjectsformat_tool_callsto includeextra_content.google.thought_signaturewhen presentTesting
spec/ruby_llm/providers/open_ai/tools_spec.rb(new file):Technical Details
Incoming Tool Calls (Parsing)
When receiving tool calls from Gemini through the OpenAI-compatible API:
The signature is now extracted and stored in the
ToolCallobject.Outgoing Tool Calls (Formatting)
When sending tool calls back to the API, thought signatures are preserved:
Why This Matters
extra_contentextension patternBackward Compatibility
✅ Fully backward compatible:
Testing
Related Documentation
This change aligns with:
extra_contentpattern