feat: Support Gemini 3 built-in and custom tool combinations (tool context circulation)#12086
Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
Draft
feat: Support Gemini 3 built-in and custom tool combinations (tool context circulation)#12086roomote-v0[bot] wants to merge 1 commit intomainfrom
roomote-v0[bot] wants to merge 1 commit intomainfrom
Conversation
…ntext circulation) Enable combining server-side built-in tools (Google Search, Code Execution) with client-side function declarations for Gemini 3+ models. This enables "tool context circulation" where the model can invoke its built-in tools server-side and seamlessly pass that context into Roo Code local tools. Changes: - Add isGemini3Model helper to detect Gemini 3+ models - Include googleSearch as a built-in tool alongside function declarations for Gemini 3 models - Handle executableCode and codeExecutionResult parts in streaming response - Store server-side tool parts on handler for conversation history round-tripping via getServerSideToolParts() - Update gemini-format.ts to convert server-side tool content blocks back to Gemini Part format - Update Task.ts addToApiConversationHistory to persist server-side tool parts in the conversation history - Add comprehensive tests for all new functionality Closes #11966
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related GitHub Issue
Closes: #11966
Description
This PR attempts to address Issue #11966 by enabling "tool context circulation" for Gemini 3+ models. Feedback and guidance are welcome.
Key changes:
src/api/providers/gemini.ts: AddedisGemini3Model()helper to detect Gemini 3+ models. For these models, Google Search is included as a built-in tool alongside custom function declarations in the tools config. The streaming handler now processesexecutableCodeandcodeExecutionResultparts from server-side tool invocations, surfacing them as text to the user and storing them for history round-tripping via a newgetServerSideToolParts()method.src/api/transform/gemini-format.ts: AddedServerSideToolContentBlocktype andisServerSideToolContentBlock()guard. The converter now recognizesexecutableCodeandcodeExecutionResultcontent blocks in conversation history and converts them back to proper GeminiPartformat for round-tripping.src/core/task/Task.ts: UpdatedaddToApiConversationHistory()to retrieve server-side tool parts from the handler and persist them as content blocks in the conversation history, enabling context circulation across turns.Design decisions:
isGemini3Model()check -- older Gemini models and other providers are completely unaffected.ServerSideToolParttype uses a genericdata: Record<string, unknown>payload to preserve all API fields verbatim for future-proofing.Test Procedure
gemini.spec.tsverifying: googleSearch is included for Gemini 3 models; not included for pre-Gemini 3 models; executableCode/codeExecutionResult parts are handled in streaming and stored; parts are reset between requests.gemini-format.spec.tsverifying: executableCode and codeExecutionResult content blocks are round-tripped correctly; mixed function calls and server-side tool parts work together.gemini-handler.spec.tstest to reflect the new combined tools behavior for the default Gemini 3 model.Run:
cd src && npx vitest run api/providers/__tests__/gemini.spec.ts api/providers/__tests__/gemini-handler.spec.ts api/transform/__tests__/gemini-format.spec.tsPre-Submission Checklist
Documentation Updates
Additional Notes
@google/genaiSDK v1.29.1 does not expose an explicitincludeServerSideToolInvocationsflag in its TypeScript types. Instead, Gemini 3 natively supports combininggoogleSearchandfunctionDeclarationsin the same tools array without additional flags.-customtoolsmodel variant (gemini-3.1-pro-preview-customtools) is unrelated to this feature per the issue discussion -- it is for prioritizing custom tool use over basic shell commands.Interactively review PR in Roo Code Cloud