fix(core): override toolRegistry property for sub-agent schedulers#21766
Conversation
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 in sub-agent tool scheduling where sub-agents were failing to locate their specific tools due to an inheritance issue with the 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 fixes a bug where sub-agent schedulers were using the main agent's tool registry instead of their own. The fix properly overrides the toolRegistry getter on the sub-agent's configuration object using Object.defineProperty, which is the correct approach to handle the prototypal inheritance pattern in use. The changes are well-tested, with a new test in agent-scheduler.test.ts that specifically validates the fix for the getter override, and another in browserAgentFactory.test.ts that adds valuable regression coverage for the browser agent's tool definitions. The implementation is clear, targeted, and effectively resolves the issue.
5fffc30 to
52b9d4a
Compare
The AgentLoopContext introduction (google-gemini#21198) caused the Scheduler to read toolRegistry via a property getter instead of the getToolRegistry() method. Object.create(config) inherits the getter from the prototype chain, so the agent-scoped config always returned the main registry. Add Object.defineProperty to shadow the inherited getter with the agent-specific registry. Add regression tests. Fixes google-gemini#21765
52b9d4a to
af0e5d3
Compare
| Object.defineProperty(agentConfig, 'toolRegistry', { | ||
| get: () => toolRegistry, | ||
| configurable: true, | ||
| }); |
There was a problem hiding this comment.
Just curious, if we're doing this for the AgentLoopContext interface, do we also need to override the messageBus in a similar way?
There was a problem hiding this comment.
We will need to replace this Object.create hack with an explicit AgentLoopContext to avoid fragile prototype getter overrides altogether.
Summary
Sub-agent tool scheduling is broken: the
Schedulerlooks up tools from the main agent's registry instead of the sub-agent's isolated registry. This causes the browser agent to fail withTool "new_page" not foundfor all MCP tools.Details
PR #21198 (
Introduce AgentLoopContext) changed theSchedulerto readthis.context.toolRegistry(a property getter) instead ofthis.config.getToolRegistry()(a method). Butagent-scheduler.tscreates the agent config viaObject.create(config)and only overrides thegetToolRegistry()method, not thetoolRegistrygetter. The getter resolves through the prototype to the original Config, returning the main registry.Fix: add
Object.definePropertyto shadow the inherited getter with the agent-specific registry.Related Issues
Fixes #21765
How to Validate
npm test -w @google/gemini-cli-core -- src/agents/agent-scheduler.test.ts src/agents/browser/browserAgentFactory.test.ts- all 16 tests should passnew_pageandnavigate_pageshould workPre-Merge Checklist