Skip to content

Commit 4ff4949

Browse files
committed
fix(antigravity): strip built-in tools when functionDeclarations present
Gemini v1internal API rejects requests that mix built-in tools (google_search) with functionDeclarations, returning 400 INVALID_ARGUMENT. Strip google_search/web_search/search_web from functionDeclarations before sending to Antigravity in both Gemini and Claude paths. toolConfig is only added when custom functionDeclarations remain. Ref: lbjlaq/Antigravity-Manager#2331, PR#2356
1 parent 15153e6 commit 4ff4949

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

open-sse/translator/request/openai-to-gemini.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,15 @@ function wrapInCloudCodeEnvelope(model, geminiCLI, credentials = null, isAntigra
303303
}
304304

305305
// Add toolConfig for Antigravity
306-
if (geminiCLI.tools?.length > 0) {
306+
// Strip built-in tools (google_search etc.) — v1internal rejects mixing them with functionDeclarations
307+
if (envelope.request.tools?.length > 0) {
308+
const GEMINI_BUILTIN_TOOLS = new Set(["google_search", "web_search", "search_web", "googleSearch"]);
309+
const allDecls = envelope.request.tools.flatMap(t => t.functionDeclarations || []);
310+
const customDecls = allDecls.filter(fn => !GEMINI_BUILTIN_TOOLS.has(fn.name));
311+
envelope.request.tools = customDecls.length > 0 ? [{ functionDeclarations: customDecls }] : undefined;
312+
}
313+
const hasCustomTools = envelope.request.tools?.some(t => t.functionDeclarations?.length > 0);
314+
if (hasCustomTools) {
307315
envelope.request.toolConfig = {
308316
functionCallingConfig: { mode: "VALIDATED" }
309317
};
@@ -400,9 +408,11 @@ function wrapInCloudCodeEnvelopeForClaude(model, claudeRequest, credentials = nu
400408

401409
// Convert Claude tools to Gemini functionDeclarations
402410
if (claudeRequest.tools && Array.isArray(claudeRequest.tools)) {
411+
const GEMINI_BUILTIN_TOOLS = new Set(["google_search", "web_search", "search_web", "googleSearch"]);
403412
const functionDeclarations = [];
404413
for (const tool of claudeRequest.tools) {
405414
if (tool.name && tool.input_schema) {
415+
if (GEMINI_BUILTIN_TOOLS.has(tool.name)) continue; // v1internal rejects mixing built-in with functionDeclarations
406416
const cleanedSchema = cleanJSONSchemaForAntigravity(tool.input_schema);
407417
functionDeclarations.push({
408418
name: sanitizeGeminiFunctionName(tool.name),

0 commit comments

Comments
 (0)