Skip to content

fix(antigravity): strip built-in tools when functionDeclarations present to avoid 400 - #1095

Closed
Vanszs wants to merge 1 commit into
decolua:masterfrom
Vanszs:fix/antigravity-builtin-tools-400
Closed

Vanszs wants to merge 1 commit into
decolua:masterfrom
Vanszs:fix/antigravity-builtin-tools-400

Conversation

@Vanszs

@Vanszs Vanszs commented May 13, 2026

Copy link
Copy Markdown

Problem

Antigravity v1internal API (cloudcode-pa.googleapis.com) rejects requests that mix built-in tools (google_search) with functionDeclarations, returning 400 INVALID_ARGUMENT:

{"error": {"code": 400, "message": "Request contains an invalid argument.", "status": "INVALID_ARGUMENT"}}

This affects all clients (OpenClaw, Claude Code, Cline, etc.) that send google_search as a function tool alongside other tools — which is the default behavior for many AI agent frameworks.

Root Cause

When a client sends google_search as a function tool in the tools array, 9router forwards it as a functionDeclarations entry to Antigravity. The v1internal protocol does not support tool_config.include_server_side_tool_invocations, so any mix of built-in tools and custom function declarations is rejected.

Reference: lbjlaq/Antigravity-Manager#2331, PR#2356

Fix

Strip google_search, web_search, search_web from functionDeclarations before sending to Antigravity in both paths:

  • wrapInCloudCodeEnvelope (Gemini model path)
  • wrapInCloudCodeEnvelopeForClaude (Claude model path)

toolConfig is only added when custom functionDeclarations remain after stripping.

Behavior

  • With google_search + custom tools: google_search is stripped, custom tools forwarded normally ✅
  • With only google_search: tools removed entirely, plain chat request ✅
  • With only custom tools: unchanged behavior ✅

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
Copilot AI review requested due to automatic review settings May 13, 2026 14:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Antigravity (v1internal) request wrapper logic to avoid 400 INVALID_ARGUMENT by removing built-in search tools from functionDeclarations before forwarding requests, ensuring Antigravity only receives valid custom tool declarations.

Changes:

  • Strip google_search / web_search / search_web-style tools out of functionDeclarations for the Gemini CLI → Antigravity envelope path.
  • Skip built-in search tools when converting Claude tools into Gemini functionDeclarations, and only attach toolConfig when custom tools remain.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +415 to 418
if (GEMINI_BUILTIN_TOOLS.has(tool.name)) continue; // v1internal rejects mixing built-in with functionDeclarations
const cleanedSchema = cleanJSONSchemaForAntigravity(tool.input_schema);
functionDeclarations.push({
name: sanitizeGeminiFunctionName(tool.name),
Comment on lines +306 to 315
// Strip built-in tools (google_search etc.) — v1internal rejects mixing them with functionDeclarations
if (envelope.request.tools?.length > 0) {
const GEMINI_BUILTIN_TOOLS = new Set(["google_search", "web_search", "search_web", "googleSearch"]);
const allDecls = envelope.request.tools.flatMap(t => t.functionDeclarations || []);
const customDecls = allDecls.filter(fn => !GEMINI_BUILTIN_TOOLS.has(fn.name));
envelope.request.tools = customDecls.length > 0 ? [{ functionDeclarations: customDecls }] : undefined;
}
const hasCustomTools = envelope.request.tools?.some(t => t.functionDeclarations?.length > 0);
if (hasCustomTools) {
envelope.request.toolConfig = {
diegosouzapw pushed a commit to cheaper-inference/OmniRoute that referenced this pull request Jun 26, 2026
…nt in Antigravity envelope

Antigravity's Cloud Code v1internal endpoint returns 400 when a Gemini
built-in tool (google_search / web_search / search_web / googleSearch) is
sent in the same request as custom functionDeclarations. wrapInCloudCodeEnvelope
now filters those built-in names out of the envelope's functionDeclarations,
drops a declarations entry that becomes empty, and only forces the VALIDATED
functionCallingConfig when custom declarations remain. Native grounding
entries (`{ googleSearch: {} }`) are preserved untouched.

Co-authored-by: Vanszs <vanszs@users.noreply.github.com>
Inspired-by: decolua/9router#1095
@Vanszs Vanszs closed this Jun 29, 2026
@Vanszs
Vanszs deleted the fix/antigravity-builtin-tools-400 branch June 29, 2026 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants