fix(ai): avoid unsigned Gemini 3 tool calls (#741)

This commit is contained in:
Roshan Singh 2026-01-15 17:42:39 +05:30 committed by GitHub
parent 2c10cc6da9
commit b18f401d9e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 90 additions and 10 deletions

View file

@ -131,18 +131,29 @@ export function convertMessages<T extends GoogleApiType>(model: Model<T>, contex
});
}
} else if (block.type === "toolCall") {
const part: Part = {
functionCall: {
name: block.name,
args: block.arguments,
...(requiresToolCallId(model.id) ? { id: block.id } : {}),
},
};
const thoughtSignature = resolveThoughtSignature(isSameProviderAndModel, block.thoughtSignature);
if (thoughtSignature) {
part.thoughtSignature = thoughtSignature;
// Gemini 3 requires thoughtSignature on all function calls when thinking mode is enabled.
// When replaying history from providers without thought signatures (e.g. Claude via Antigravity),
// convert unsigned function calls to text to avoid API validation errors.
const isGemini3 = model.id.toLowerCase().includes("gemini-3");
if (isGemini3 && !thoughtSignature) {
const argsStr = JSON.stringify(block.arguments, null, 2);
parts.push({
text: `[Tool Call: ${block.name}]\nArguments: ${argsStr}`,
});
} else {
const part: Part = {
functionCall: {
name: block.name,
args: block.arguments,
...(requiresToolCallId(model.id) ? { id: block.id } : {}),
},
};
if (thoughtSignature) {
part.thoughtSignature = thoughtSignature;
}
parts.push(part);
}
parts.push(part);
}
}