Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion schema/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ type ToolCall struct {

// Extra is used to store extra information for the tool call.
Extra map[string]any `json:"extra,omitempty"`

// ThoughtSignatures is used by Gemini 3 to maintain reasoning context across API calls.
ThoughtSignature string `json:"thought_signature,omitempty"`
}

// ImageURLDetail is the detail of the image url.
Expand Down Expand Up @@ -901,7 +904,7 @@ func concatToolCalls(chunks []ToolCall) ([]ToolCall, error) {
}

args.Reset()
toolID, toolType, toolName := "", "", "" // these field will output atomically in any chunk
toolID, toolType, toolName, thoughtSignature := "", "", "", "" // these field will output atomically in any chunk

for _, n := range v {
chunk := chunks[n]
Expand Down Expand Up @@ -936,12 +939,21 @@ func concatToolCalls(chunks []ToolCall) ([]ToolCall, error) {
return nil, err
}
}

if chunk.ThoughtSignature != "" {
if thoughtSignature == "" {
thoughtSignature = chunk.ThoughtSignature
} else if thoughtSignature != chunk.ThoughtSignature {
return nil, fmt.Errorf("cannot concat ToolCalls with different thought signature: '%s' '%s'", thoughtSignature, chunk.ThoughtSignature)
}
}
}

toolCall.ID = toolID
toolCall.Type = toolType
toolCall.Function.Name = toolName
toolCall.Function.Arguments = args.String()
toolCall.ThoughtSignature = thoughtSignature

merged = append(merged, toolCall)
}
Expand Down