fix(openai): round-trip Gemini 3 thought_signature on tool calls - #338
Open
OtavioTavares wants to merge 1 commit into
Open
fix(openai): round-trip Gemini 3 thought_signature on tool calls#338OtavioTavares wants to merge 1 commit into
OtavioTavares wants to merge 1 commit into
Conversation
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
With Gemini 3 models (e.g.
gemini-3.1-flash-lite,gemini-3.5-flash) via the OpenAI-compatible endpoint, multi-turn tool calling fails on the follow-up request:Gemini 3 is a thinking model: each tool call carries a
thought_signaturethat MUST be echoed back on the next request. In the OpenAI-compat protocol it is surfaced astool_calls[].extra_content({"google": {"thought_signature": "..."}}).openai_client.pydropped this field when parsing tool calls and never resent it, so the 2nd turn 400s.Fix
Mirror the existing
reasoning_content/_reasoninground-trip pattern forextra_content:extra_contentoff each tool call (streaming and non-streaming). In streaming, Gemini sends it on a trailing index-less delta, so it is attached to the current tool call._tool_extra_content(keyed by tool-call id)._convert_assistant_messageon the assistanttool_calls.Gated on presence: providers that do not set
extra_content(OpenAI, DashScope, GitHub Models, Kimi, ...) are unaffected.Tests
TestThoughtSignatureRoundTrip(capture from attr / model_extra, replay, and omission when absent).tests/test_api/test_openai_client.pypasses (46 tests).