Skip to content

Gemini: opt-in server-side google_search, default-on - #158

Merged
FMXExpress merged 2 commits into
mainfrom
claude/nice-dirac-sBwXK
Jun 6, 2026
Merged

FMXExpress merged 2 commits into
mainfrom
claude/nice-dirac-sBwXK

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

Summary

Adds the same opt-in server-tools pattern Anthropic (web_search/web_fetch) and OpenAI (web_search) already have, for Gemini's native Google search grounding. Default is on, matching OpenAI's web_search posture — most operators picking Gemini want grounding, and the catalog default model (gemini-3.5-flash) accepts the field.

Wire shape

A tools[] entry whose only key is google_search with an empty config object as its value. Coexists with the existing functionDeclarations entry on the same request — both are emitted side-by-side when the operator has local tools registered. Gemini 2.5+ / 3.x accept the combination.

Compatibility note

Gemini 1.5 used the older googleSearchRetrieval shape we don't emit; pointing the toggle at a 1.5 model yields a 400 from generateContent. Operators on 1.5 should set "google_search": false in config.json or move to a 2.x+ model. Catalog default (gemini-3.5-flash) works out of the box.

Mechanics

  • PasClaw.Config — new TGeminiServerToolsConfig record with GoogleSearch: Boolean, JSON round-trip via gemini_server_tools.google_search. Always emitted on save so false sticks across reloads.
  • PasClaw.Providers.Gemini — TGeminiServerTools record local to the unit (same posture as Anthropic), 4th constructor arg, BuildRequest overloaded so every existing 4-arg call (tests + embedders that predate the field) keeps compiling unchanged. SupportsNativeSearch now reports the toggle value.
  • PasClaw.Providers.Factory — pfGemini branch translates Cfg.GeminiServerTools into the provider's local record.

Test plan

  • make test-gemini-schema-strip — 3 new cases prove the wire shape: emitted when on, omitted when off (with no empty tools[] either), coexists with functionDeclarations when both are present. All 10 cases pass.
  • make test-anthropic-server-tools test-openai-server-tools test-markdown-render — neighbouring server-tool / render suites still green.
  • make — full pasclaw binary builds clean.
  • make smoke — every command surface still passes.
  • Manual config round-trip: TConfig.Create defaults to True; serialise + reparse with false round-trips to false; serialise + reparse with true round-trips to true.
  • Live pasclaw agent against a Gemini API key with a grounded prompt ("what is the weather in Tokyo today") to confirm citations come back. (Requires a real Gemini API key — not runnable in CI.)

Generated by Claude Code

Adds the same toggle pattern Anthropic (web_search/web_fetch) and
OpenAI (web_search) already have. Default is True for parity with
OpenAI's web_search: most operators picking Gemini want grounding,
the catalog default model (gemini-3.5-flash) accepts the field, and
flipping the toggle to False round-trips through config.json.

Wire shape: tools[] entry whose only key is "google_search" with an
empty config object as its value. Coexists with the existing
functionDeclarations entry — both can be emitted in the same
request on Gemini 2.5+ / 3.x. On Gemini 1.5 the API returns 400
(1.5 used the older google_search_retrieval shape we don't emit) —
operator flips google_search: false in config.json or moves to a
2.x+ model.

Mechanically:
  PasClaw.Config             new TGeminiServerToolsConfig record
                             with GoogleSearch: Boolean, JSON
                             round-trip via gemini_server_tools.
                             Always emitted on save so a false
                             value sticks across reloads.
  PasClaw.Providers.Gemini   TGeminiServerTools record local to the
                             unit (same posture as Anthropic), 4th
                             ctor arg, BuildRequest overloaded so
                             every existing 4-arg call (tests +
                             embedders that predate the field)
                             stays compiling unchanged.
                             SupportsNativeSearch now reports the
                             toggle value.
  PasClaw.Providers.Factory  pfGemini branch translates
                             Cfg.GeminiServerTools into the
                             provider's local record.

Tests: 3 new cases in gemini_schema_strip_tests prove the wire
shape — emitted when on, omitted when off (with no empty tools[]
either), coexists with functionDeclarations when both are present.
All 10 tests pass.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e9efd3e68b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +556 to +565
if ServerTools.GoogleSearch then
begin
(* Wire shape: a tools-array entry whose only key is
"google_search" with an empty config object as its value.
The empty value opts into Gemini's default grounding
behaviour; extra keys here are rejected by the API. *)
GoogleSearchEntry := TJsonObject.Create;
GoogleSearchObj := TJsonObject.Create;
GoogleSearchEntry.PutObject('google_search', GoogleSearchObj);
ToolsArr.AddObject(GoogleSearchEntry);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Gate google_search when local tools target pre-Gemini 3

When google_search is enabled and the agent has local tools registered, this appends both functionDeclarations and google_search to the same generateContent request. That is only supported out-of-the-box for Gemini 3 models; Google's current function-calling docs say for models before Gemini 3 to use the Live API instead (https://ai.google.dev/gemini-api/docs/function-calling#multi-tool-use-combine-built-in-tools-with-function-calling). For users configured on Gemini 2.0/2.5 with the new default-on setting, normal tool-using chats will start returning 400s, so the provider should gate this combination by model or suppress google_search when local tools are present on pre-3 models.

Useful? React with 👍 / 👎.

Codex P2 on PR #158. The default-on toggle would silently 400 every
tool-using chat on Gemini 2.x: combining google_search with
functionDeclarations in the same generateContent request is only
supported on Gemini 3.x — Google's function-calling docs route the
mixed-tool flow on pre-3 models through the Live API instead.

Fix at the BuildRequest boundary:

  IsGemini3OrLater(Model) — cheap prefix check on the digit
  immediately after `gemini-`. Treats anything not matching the
  pattern (gemini-pro, gemini-1.5, gemini-2.5, vendor-prefixed
  unknowns) as "cannot combine", so default-on never lights a 400
  on a user's tool-using chat.

  EmitGoogleSearch := toggle and ((no local tools) or 3.x+).
  When the toggle is on, local tools are registered, and the model
  is pre-3, we suppress google_search this turn and keep the user's
  explicit functionDeclarations. Logs a debug line explaining the
  suppression so the operator sees why grounding didn't appear.

  Bare google_search (no local tools) still ships on 2.x — that
  shape is accepted, so default-on grounding still works for
  non-tool-loop conversations on 2.x.

Two new test cases prove the gating:

  TestGoogleSearchSuppressedOnPreGemini3WithLocalTools — 2.x +
  fs_list → functionDeclarations present, google_search absent.

  TestGoogleSearchEmittedOnPreGemini3WithoutLocalTools — 2.x +
  no local tools → google_search present, functionDeclarations
  absent (confirms we only suppress the combo, not bare search).

Existing 3.x coexistence test renamed/clarified. All 12 tests pass.
The TGeminiServerToolsConfig doc-comment now documents the full
model matrix (3.x always, 2.x conditional, 1.x unsupported).
@FMXExpress
FMXExpress merged commit 398f955 into main Jun 6, 2026
FMXExpress pushed a commit that referenced this pull request Jun 6, 2026
Live trace: a tool-using chat on gemini-3.5-flash with google_search
on returned 400 "Please enable tool_config.include_server_side_tool_invocations
to use Built-in tools with Function calling." PR #158's combo-gating
guarantees the request only ships when the model is Gemini 3.x+, but
the 3.x API additionally requires this top-level field to be true
before it accepts functionDeclarations and google_search in the same
generateContent call.

Emit tool_config.include_server_side_tool_invocations: true only
when both tool categories are on the wire (functionDeclarations
non-empty AND google_search emission gated through). Bare
google_search and bare functionDeclarations requests stay unchanged.

Extends the existing TestGoogleSearchCoexistsWithFunctionDeclarations
test to assert both the tool_config block and the
include_server_side_tool_invocations field appear; extends
TestGoogleSearchOmittedWhenDisabled to assert tool_config is absent
when there is no combo to gate. All 12 tests pass.
FMXExpress pushed a commit that referenced this pull request Jun 6, 2026
Live trace: a tool-using chat on gemini-3.5-flash with google_search
on returned 400 "Please enable tool_config.include_server_side_tool_invocations
to use Built-in tools with Function calling." PR #158's combo-gating
guarantees the request only ships when the model is Gemini 3.x+, but
the 3.x API additionally requires this top-level field to be true
before it accepts functionDeclarations and google_search in the same
generateContent call.

Emit tool_config.include_server_side_tool_invocations: true only
when both tool categories are on the wire (functionDeclarations
non-empty AND google_search emission gated through). Bare
google_search and bare functionDeclarations requests stay unchanged.

Extends the existing TestGoogleSearchCoexistsWithFunctionDeclarations
test to assert both the tool_config block and the
include_server_side_tool_invocations field appear; extends
TestGoogleSearchOmittedWhenDisabled to assert tool_config is absent
when there is no combo to gate. All 12 tests pass.
khongten001 pushed a commit to khongten001/PasClaw that referenced this pull request Jul 13, 2026
Two dcc64 errors against the just-merged PR FMXExpress#167:

  PasClaw.Memory.Index.pas(622): H2443
    Inline function 'TFDParam.SetAsInteger' has not been expanded
    because unit 'FireDAC.Stan.Param' is not specified in USES list

  LocalVector.VectorStore.FireDAC.pas(31): E2029
    'INTERFACE' expected but identifier 'guard' found
  LocalVector.VectorStore.FireDAC.pas(32): E2052
    Unterminated string
  LocalVector.VectorStore.FireDAC.pas(39): E2038
    Illegal character in input file: '}' (#$7D)
  LocalVector.VectorStore.pas(103): F2063
    Could not compile used unit 'LocalVector.VectorStore.FireDAC.pas'

The H2443 hint was always present but never surfaced as an error
before; the four E20xx errors are a regression my PR FMXExpress#167 stub
introduced. Both addressed here.

PasClaw.Memory.Index.pas:
  Added FireDAC.Stan.Param to the {$ELSE} branch of the FireDAC uses
  list (alongside the existing FireDAC.Comp.Client / Stan.Def /
  Stan.Async / DApt entries). The TFDParam.SetAsInteger call at
  line 622 ends up inlined now instead of dispatched through the
  vtable, and dcc64's H2443 hint goes away. No FPC behaviour change.

LocalVector.VectorStore.FireDAC.pas:
  My PR FMXExpress#167 stub-block comment used curly-brace delimiters and
  literally spelled out a {$IFNDEF LINUX} directive inside the
  comment text:

    { PasClaw modification: stub on Delphi Linux64.
      ... PasClaw.dpr already routes around this constraint
      (PR FMXExpress#135 added the {$IFNDEF LINUX}
      guard there); we extend ...
    }

  Curly-brace comments DO NOT NEST in Pascal, so dcc64 parses the
  inner {$IFNDEF LINUX} as a real compiler directive, then chokes
  on the closing `}` that was meant for the outer comment. PR FMXExpress#158
  hit the exact same trap in PasClaw.Providers.Gemini and switched
  to (* ... *) delimiters; same fix here. The comment text also no
  longer spells the directive verbatim — it references the
  source-level platform guard by its bare name — so a future
  reader doesn't accidentally re-introduce the trap by reformatting
  the comment back to curly braces.

  The actual stub directive

    {$IF DEFINED(LINUX) AND NOT DEFINED(FPC)}
    interface
    implementation
    end.
    {$IFEND}

  is unchanged. Behaviour matrix from PR FMXExpress#167 still holds:
    Delphi Windows / macOS / mobile  → FireDAC backend (unchanged)
    Delphi Linux64                   → portable Sqlite backend
                                       (LV_PORTABLE_SQLITE forced on
                                        by LocalVector.VectorStore)
    FPC any-OS                       → portable Sqlite backend

Verified: FPC build still clean. Full test suite green: smoke +
hashline + toolview + anthropic-server-tools + openai-server-tools +
println-helper + utf8-codepage-tag + gemini-schema-strip +
markdown-render + json-utf8-roundtrip.

Delphi-side verification needs a real dcc64 compiler — not available
here, but the comment-trap fix mirrors PR FMXExpress#158's exactly and the
FireDAC.Stan.Param edit is mechanical.
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