feat: add support for Gemini thought_signature in tool calls

Gemini 3.x models require a thought_signature to be returned in subsequent
conversation turns when using tool calls. This patch adds the necessary
fields to ToolCall protocol types and updates the OpenAI-compatible provider
and agent loop to capture and preserve these signatures.
This commit is contained in:
Talha Munawar 2026-02-20 02:02:56 +05:00
parent 394d1d1197
commit 021dc69015
3 changed files with 34 additions and 9 deletions

View file

@ -603,7 +603,8 @@ func (al *AgentLoop) runLLMIteration(ctx context.Context, agent *AgentInstance,
Name: tc.Name, Name: tc.Name,
Arguments: string(argumentsJSON), Arguments: string(argumentsJSON),
}, },
Name: tc.Name, Name: tc.Name,
ExtraContent: tc.ExtraContent,
}) })
} }
messages = append(messages, assistantMsg) messages = append(messages, assistantMsg)

View file

@ -133,6 +133,11 @@ func parseResponse(body []byte) (*LLMResponse, error) {
Name string `json:"name"` Name string `json:"name"`
Arguments string `json:"arguments"` Arguments string `json:"arguments"`
} `json:"function"` } `json:"function"`
ExtraContent *struct {
Google *struct {
ThoughtSignature string `json:"thought_signature"`
} `json:"google"`
} `json:"extra_content"`
} `json:"tool_calls"` } `json:"tool_calls"`
} `json:"message"` } `json:"message"`
FinishReason string `json:"finish_reason"` FinishReason string `json:"finish_reason"`
@ -167,10 +172,20 @@ func parseResponse(body []byte) (*LLMResponse, error) {
} }
} }
var extra *protocoltypes.ToolCallExtraContent
if tc.ExtraContent != nil && tc.ExtraContent.Google != nil {
extra = &protocoltypes.ToolCallExtraContent{
Google: &protocoltypes.GoogleExtraContent{
ThoughtSignature: tc.ExtraContent.Google.ThoughtSignature,
},
}
}
toolCalls = append(toolCalls, ToolCall{ toolCalls = append(toolCalls, ToolCall{
ID: tc.ID, ID: tc.ID,
Name: name, Name: name,
Arguments: arguments, Arguments: arguments,
ExtraContent: extra,
}) })
} }

View file

@ -1,11 +1,20 @@
package protocoltypes package protocoltypes
type ToolCall struct { type ToolCall struct {
ID string `json:"id"` ID string `json:"id"`
Type string `json:"type,omitempty"` Type string `json:"type,omitempty"`
Function *FunctionCall `json:"function,omitempty"` Function *FunctionCall `json:"function,omitempty"`
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
Arguments map[string]interface{} `json:"arguments,omitempty"` Arguments map[string]interface{} `json:"arguments,omitempty"`
ExtraContent *ToolCallExtraContent `json:"extra_content,omitempty"`
}
type ToolCallExtraContent struct {
Google *GoogleExtraContent `json:"google,omitempty"`
}
type GoogleExtraContent struct {
ThoughtSignature string `json:"thought_signature,omitempty"`
} }
type FunctionCall struct { type FunctionCall struct {