Skip to content

fix(proxy): don't mix googleSearch with functionDeclarations (v1internal 400)#3192

Open
eddieparc wants to merge 1 commit into
lbjlaq:mainfrom
eddieparc:fix/no-mix-builtin-function-tools
Open

fix(proxy): don't mix googleSearch with functionDeclarations (v1internal 400)#3192
eddieparc wants to merge 1 commit into
lbjlaq:mainfrom
eddieparc:fix/no-mix-builtin-function-tools

Conversation

@eddieparc

Copy link
Copy Markdown

Don't mix googleSearch with functionDeclarations (v1internal returns 400)

Problem

cloudcode-pa (v1internal) rejects any request that combines a built-in tool (googleSearch) with functionDeclarations:

HTTP 400 INVALID_ARGUMENT
Please enable tool_config.include_server_side_tool_invocations to use Built-in tools with Function calling.

The error text suggests setting tool_config.includeServerSideToolInvocations, but that flag does not work on this endpoint — verified end-to-end (debug-dumped the exact upstream body with the flag set; v1internal still returns the same 400). So built-in tools and function calling genuinely cannot be combined here.

This breaks real coding clients (pi, opencode) routed through the proxy: their requests always carry function tools, and as soon as web search is also active (an -online model, or a client-supplied web_search tool) the upstream 400s.

Root cause

The OpenAI mapper already avoided the mix: inject_google_search_tool() skips googleSearch when functionDeclarations are present. The Gemini-native and Claude mappers did not — they injected googleSearch alongside functionDeclarations (the Claude mapper even had supports_mixed_tools for Gemini 2.0/2.5/3, and two shipped tests asserted the mix, which were failing on main).

resolve_request_config already computed contains_non_networking_tool(...) into _has_non_networking but never used it.

Fix

  • common_utils::resolve_request_config — gate web-search mode on has_non_networking:
    let enable_networking = (is_online_suffix || has_networking_tool) && !has_non_networking;
    When real (non-networking) function tools are present, stay in agent mode: no googleSearch injection, no "search engine bot" system prompt, no search-model downgrade. Applies to all protocols.
  • claude::build_tools — never inject googleSearch when functionDeclarations are present (matches the OpenAI mapper).

Pure web-search requests (only a web_search tool, no other functions) still enable grounding.

Verification

Unit tests (cargo test --lib):

  • Repurposed the previously-failing test_mixed_tools_injection_* tests to assert the no-mix behavior.
  • Added test_networking_disabled_when_function_tools_present and test_networking_enabled_for_pure_web_search.
  • Targeted run: 8 passed / 0 failed. Remaining full-suite failures are pre-existing on main (thinking-budget global-state leakage, retry parsing, etc.) and unrelated.

Live, end-to-end against cloudcode-pa (release build):

  • functionDeclarations + -onlineHTTP 200 (was 400).
  • coding tool + web_search tool together (real pi scenario) → HTTP 200.
  • pure web search → HTTP 200 with grounded answer + sources.

…nal 400)

cloudcode-pa (v1internal) returns HTTP 400 "Please enable
tool_config.include_server_side_tool_invocations to use Built-in tools with
Function calling" whenever a request combines a built-in tool (googleSearch)
with functionDeclarations. The flag does NOT help: verified end-to-end that
v1internal still 400s even when toolConfig.includeServerSideToolInvocations is
set. The two tool kinds must never be combined.

The OpenAI mapper already avoided this (inject_google_search_tool skips
googleSearch when functions are present); the Gemini-native and Claude mappers
did not, so any agent request that also carried a web-search tool (or used an
-online model) 400'd. This broke real coding clients (pi, opencode) whose
requests always include function tools.

Fix:
- resolve_request_config: gate web-search mode on the already-computed (but
  previously unused) has_non_networking. When real function tools are present,
  stay in agent mode instead of entering web-search mode. This stops googleSearch
  injection, the search-bot system prompt, and the search-model downgrade for
  mixed requests across all protocols.
- claude build_tools: never inject googleSearch when functionDeclarations are
  present (matches the OpenAI mapper).

Pure web-search requests (only a web_search tool) still enable grounding.
Verified live against cloudcode-pa: mixed requests now return 200; pure web
search still returns grounded results.

Tests: repurpose the previously-failing mixed-tools tests to assert no-mix, and
add resolve_request_config gate tests.
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.

1 participant