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

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

View file

@ -133,6 +133,11 @@ func parseResponse(body []byte) (*LLMResponse, error) {
Name string `json:"name"`
Arguments string `json:"arguments"`
} `json:"function"`
ExtraContent *struct {
Google *struct {
ThoughtSignature string `json:"thought_signature"`
} `json:"google"`
} `json:"extra_content"`
} `json:"tool_calls"`
} `json:"message"`
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{
ID: tc.ID,
Name: name,
Arguments: arguments,
ExtraContent: extra,
})
}

View file

@ -6,6 +6,15 @@ type ToolCall struct {
Function *FunctionCall `json:"function,omitempty"`
Name string `json:"name,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 {