Merge Gemini tool mode into caller-supplied ToolConfig instead of replacing it - #738
Merge Gemini tool mode into caller-supplied ToolConfig instead of replacing it#738PratikDhanave wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes how the Gemini provider applies tool-mode selection so it no longer overwrites a caller-supplied genai.ToolConfig, preserving other ToolConfig fields (e.g., RetrievalConfig for Vertex grounding) while still enforcing the requested function-calling mode.
Changes:
- Update
buildParamsto merge tool-mode settings into an existingToolConfiginstead of replacing the whole struct. - Add a regression test ensuring
RetrievalConfigis preserved whenWithToolMode(required)is applied.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| provider/geminiprovider/agent.go | Merges tool-mode function-calling config into existing ToolConfig instead of clobbering it. |
| provider/geminiprovider/agent_test.go | Adds a test to verify caller-supplied RetrievalConfig is preserved when tool mode is set. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if cfg.ToolConfig == nil { | ||
| cfg.ToolConfig = &genai.ToolConfig{} | ||
| } | ||
| cfg.ToolConfig.FunctionCallingConfig = fc |
There was a problem hiding this comment.
Good catch — fixed in 61f3eef: I now shallow-clone the caller-supplied ToolConfig struct before overriding FunctionCallingConfig, so we no longer mutate the caller's aliased pointer (from the shallow *cfg = p copy) while still preserving their other fields like RetrievalConfig.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
buildParams replaced cfg.ToolConfig wholesale when a tool mode was set, dropping any RetrievalConfig or IncludeServerSideToolInvocations the caller passed through GenerateContentConfig. Mutate the existing ToolConfig so only FunctionCallingConfig is overridden.
61f3eef to
d8c9bc9
Compare
Parity Review: ✅ No Issues FoundThis PR fixes a bug in the unexported What changed: When a tool mode is set, the code now merges Cross-repo consistency: This change mirrors the behavior of the .NET and Python providers, where tool-mode selection sets the function-calling mode without discarding other tool-config settings a caller supplied for grounding/retrieval. The Go provider was diverging from upstream; this PR corrects that divergence. Scope: Only unexported implementation code is touched ( Conclusion: The Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
|
What
When a tool mode is set,
buildParamsinprovider/geminiprovider/agent.goassigned a brand-newgenai.ToolConfigholding only theFunctionCallingConfig, replacing anyToolConfigthe caller had already supplied through theGenerateContentConfigescape hatch.genai.ToolConfigalso carriesRetrievalConfig(Vertex grounding) andIncludeServerSideToolInvocations; those were silently dropped.This mutates the existing
ToolConfigin place instead: it only overridesFunctionCallingConfig, preserving the other caller-set fields.Why
GenerateContentConfigis documented as the pass-through for custom genai parameters, and the config is already copied wholesale intocfgvia*cfg = p. Overriding a single sub-field rather than clobbering the whole pointer matches how the rest ofbuildParamsmerges options (e.g. it appends tocfg.Toolsrather than replacing it). It also mirrors the .NET/Python providers, where tool-mode selection sets the function-calling mode without discarding other tool-config settings a caller supplied for grounding/retrieval.Testing
Added
TestToolModeMergesCallerToolConfigto the canonicalagent_test.go. It drives a run with a callerToolConfig{RetrievalConfig: ...}, a function tool, andWithToolMode(required), then inspects the outgoing request:functionCallingConfig.mode == ANYis applied andretrievalConfig.languageCodeis preserved. The test fails before this change (retrievalConfig dropped) and passes after.go build ./...,go vet, andgo test ./provider/geminiprovider/...are green.