-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(gemini): add allowedFunctionNames support to prevent mode switch errors #10708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… errors When switching modes, Gemini needs to see all tool definitions to understand conversation history, but should only be allowed to call tools permitted in the current mode. This implements the allowedFunctionNames feature: - Add allowedFunctionNames to ApiHandlerCreateMessageMetadata interface - Implement toolConfig.functionCallingConfig.allowedFunctionNames in Gemini provider - Add buildNativeToolsArrayWithRestrictions to return all tools with restrictions - Only apply to Gemini provider (other providers continue using filtered tools) - Add comprehensive tests for the new functionality
Re-review complete. No new issues found since the alias/canonical consistency fix.
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
Fixed the reported issue by resolving alias names to canonical names in |
…nNames When tools are renamed via aliasRenames (e.g., write_to_file -> write_file), the allowedFunctionNames array would contain alias names that do not exist in functionDeclarations (which uses canonical names). This caused Gemini to error because names in allowedFunctionNames must exist in functionDeclarations. Fixed by applying resolveToolAlias when extracting allowedFunctionNames to ensure alias names are resolved back to their canonical names, maintaining consistency with functionDeclarations. Added tests for resolveToolAlias function to verify alias resolution behavior.
Closes #10711
Summary
When switching modes, Gemini needs to see all tool definitions to understand conversation history, but should only be allowed to call tools permitted in the current mode. This PR implements the
allowedFunctionNamesfeature for the Gemini provider to prevent model errors when switching modes.Problem
When a user switches from one mode (e.g., "code") to another (e.g., "architect"), the conversation history may contain tool calls from the previous mode. Gemini requires the tool definitions to be present to understand the history, but the current mode may not have access to those tools. This causes errors in the Gemini API.
Solution
allowedFunctionNamessupport to the Gemini provider viatoolConfig.functionCallingConfig.allowedFunctionNamesChanges
src/api/index.ts: AddedallowedFunctionNames?: string[]toApiHandlerCreateMessageMetadatainterfacesrc/api/providers/gemini.ts: ImplementedtoolConfig.functionCallingConfig.allowedFunctionNameswhen providedsrc/core/task/build-tools.ts: AddedbuildNativeToolsArrayWithRestrictionsfunction withincludeAllToolsWithRestrictionsoptionsrc/core/task/Task.ts: Added provider check (apiProvider === "gemini") to only use the new behavior for Geminisrc/api/providers/__tests__/gemini-handler.spec.ts: Added 5 comprehensive tests for the new functionalityProvider Support Research
allowedFunctionNamesviatoolConfig.functionCallingConfigallowed_toolsviatool_choice.type = "allowed_tools"(not yet implemented)auto,any,tool(single),noneTest Results
All 5231 tests pass across 376 test files.
Important
Adds
allowedFunctionNamesto Gemini provider to restrict tool usage based on mode while maintaining historical context.allowedFunctionNamesinsrc/api/providers/gemini.tsto restrict tool usage based on mode.allowedFunctionNames?: string[]toApiHandlerCreateMessageMetadatainsrc/api/index.ts.buildNativeToolsArrayWithRestrictionsinsrc/core/task/build-tools.tsto support tool restrictions.src/api/providers/__tests__/gemini-handler.spec.tsforallowedFunctionNamesfunctionality.This description was created by
for f53e096. You can customize this summary. It will automatically update as commits are pushed.