fix(core): prevent duplicate tool schemas for instantiated tools#22204
fix(core): prevent duplicate tool schemas for instantiated tools#22204abhipatel12 merged 1 commit intomainfrom
Conversation
This commit fixes an issue where LocalAgentExecutor would push the schema of an instantiated tool twice during agent invocation, leading to 'Duplicate function declaration' API errors.
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical bug that caused duplicate tool schemas when agents were configured with instantiated tool objects. The fix centralizes the process of gathering tool schemas, ensuring that each tool's schema is declared only once, thereby preventing runtime errors and improving the robustness of tool execution. This change enhances the reliability of agents that directly instantiate tools. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly addresses a bug that caused duplicate tool schemas when tools were provided as instantiated objects. The fix simplifies the logic in prepareToolsList to rely on the toolRegistry as the single source of truth for schemas, which is the right approach. The addition of a regression test in local-executor.test.ts is excellent for preventing this issue from recurring. The other minor changes to test files to improve stability are also good practice. The changes are well-implemented and I have no further feedback.
Note: Security Review did not run due to the size of the PR.
|
Size Change: -122 B (0%) Total Size: 26.6 MB ℹ️ View Unchanged
|
Add 6 tests for the DeclarativeTool instance pattern used by the browser agent (no duplicate declarations, registry registration, mixed patterns, tool execution, complete_task injection, and browser-agent-scale coverage). These serve as regression guards for the fix in google-gemini#22204.
Summary
Fixes a bug where tools passed as object instances duplicate their schemas to the LLM.
Details
In
LocalAgentExecutor.prepareToolsList, schemas were being pushed directly intotoolsListfrom explicit tool instances intoolConfig.tools, and thenthis.toolRegistry.getFunctionDeclarations()was pushing all of them again. This caused a duplicate function declaration error when running thecli_helpagent, which embeds its tool directly vianew GetInternalDocsTool.The logic was updated to rely completely on
this.toolRegistry.getFunctionDeclarations()for all schemas to ensure deduplication.Added a new regression test to
local-executor.test.tsto catch duplicate schemas for instantiated tools in the future. Also addressed some miscellaneous type checking warnings within the test file, and added an environment variable stub toconfig.test.tsto improve test stability.Related Issues
None.
How to Validate
npm test -w @google/gemini-cli-core -- src/agents/local-executor.test.tsand ensure all tests continue to pass.cli_helpagent locally or any context where an agent directly instantiates a tool. Verify it does not crash with a "Duplicate function declaration found" error.Pre-Merge Checklist