fix(gemini): Implement Gemini 3 thought_signature handling for stateful reasoning#307
fix(gemini): Implement Gemini 3 thought_signature handling for stateful reasoning#307Andyi955 wants to merge 1 commit intosipeed:mainfrom
Conversation
| ExtraContent: extraContent, | ||
| // We also set internal ThoughtSignature, but ExtraContent is what matters for serialization | ||
| ThoughtSignature: tc.ThoughtSignature, |
There was a problem hiding this comment.
ThoughtSignture should be included in ExtraContent. Why are we pulling it out to its own field?
Have you tested this with non Google LLMs?
| // Extract thought_signature from Gemini/Google-specific extra content | ||
| thoughtSignature := "" | ||
| if tc.ExtraContent != nil && tc.ExtraContent.Google != nil { | ||
| thoughtSignature = tc.ExtraContent.Google.ThoughtSignature | ||
| } |
There was a problem hiding this comment.
seems like extra lines of code when tc.ExtraContent can just be passed to ToolCall struct
| ID: tc.ID, | ||
| Name: name, | ||
| Arguments: arguments, | ||
| ThoughtSignature: thoughtSignature, // Populating internal field for convenience |
There was a problem hiding this comment.
Whats this for? Seems to be the wrong structure of a tool call, Thought Signature is an ExtraContent field based by google.
Since this is the HTTP Provider other services other than google will use it.
| if thoughtSignature != "" { | ||
| toolCall.ExtraContent = &ExtraContent{ | ||
| Google: &GoogleExtra{ | ||
| ThoughtSignature: thoughtSignature, | ||
| }, | ||
| } | ||
| } |
There was a problem hiding this comment.
Extra assignment when line 194 set tool call fields
| Function *FunctionCall `json:"function,omitempty"` | ||
| Name string `json:"name,omitempty"` | ||
| Arguments map[string]interface{} `json:"arguments,omitempty"` | ||
| ThoughtSignature string `json:"-"` // Internal use only |
| Name string `json:"name,omitempty"` | ||
| Arguments map[string]interface{} `json:"arguments,omitempty"` | ||
| ThoughtSignature string `json:"-"` // Internal use only | ||
| ExtraContent *ExtraContent `json:"extra_content,omitempty"` |
| WORKDIR /src | ||
|
|
||
| # Cache dependencies | ||
| # Cache dependencies for faster subsequent builds |
|
@Zepan Implements Recommendation: Merge. +67/-21, needed for Gemini 3 compatibility. Without this, Gemini 3's reasoning feature doesn't work in multi-turn conversations. |
Description
This PR addresses a critical compatibility issue with Gemini 3 models (specifically
gemini-3-flash-previewandgemini-3-pro-preview) where tool calls would fail with a 400INVALID_ARGUMENTerror due to missingthought_signature.According to Google's Stateful Reasoning documentation, Gemini 3 generates encrypted
thought_signaturetokens during reasoning steps involving tools. These signatures must be persisted and returned in the subsequent conversation turn'sextra_contentfield to maintain the reasoning chain. Failure to include them causes the API to reject the request.Changes
extra_contentJSON field.thought_signaturefrom theextra_content.googlefield in the API response.Verification
gemini-3-flash-preview.list_dir).Function call is missing a thought_signature.Related Issues
Fixes 400 error with Gemini 3 models.