Skip to content

fix(core): override toolRegistry property for sub-agent schedulers#21766

Merged
gsquared94 merged 1 commit intogoogle-gemini:mainfrom
gsquared94:fix/browser-agent-tool-registry
Mar 10, 2026
Merged

fix(core): override toolRegistry property for sub-agent schedulers#21766
gsquared94 merged 1 commit intogoogle-gemini:mainfrom
gsquared94:fix/browser-agent-tool-registry

Conversation

@gsquared94
Copy link
Copy Markdown
Contributor

Summary

Sub-agent tool scheduling is broken: the Scheduler looks up tools from the main agent's registry instead of the sub-agent's isolated registry. This causes the browser agent to fail with Tool "new_page" not found for all MCP tools.

Details

PR #21198 (Introduce AgentLoopContext) changed the Scheduler to read this.context.toolRegistry (a property getter) instead of this.config.getToolRegistry() (a method). But agent-scheduler.ts creates the agent config via Object.create(config) and only overrides the getToolRegistry() method, not the toolRegistry getter. The getter resolves through the prototype to the original Config, returning the main registry.

Fix: add Object.defineProperty to shadow the inherited getter with the agent-specific registry.

Related Issues

Fixes #21765

How to Validate

  1. Run npm test -w @google/gemini-cli-core -- src/agents/agent-scheduler.test.ts src/agents/browser/browserAgentFactory.test.ts - all 16 tests should pass
  2. Enable the browser agent and ask it to open a page - new_page and navigate_page should work

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@gsquared94 gsquared94 requested a review from a team as a code owner March 9, 2026 20:24
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 toolRegistry property. The fix ensures that sub-agents correctly utilize their isolated tool registries, thereby restoring full functionality to agents like the browser agent and preventing tool lookup failures. The changes include a targeted code modification and new tests to verify the solution's effectiveness.

Highlights

  • Fix Sub-Agent Tool Scheduling: Resolved an issue where sub-agent schedulers incorrectly looked up tools from the main agent's registry instead of their own isolated registry, leading to 'Tool not found' errors for browser agent tools like 'new_page'.
  • Override toolRegistry Getter: Implemented Object.defineProperty to explicitly override the toolRegistry getter for sub-agent configurations. This ensures that when AgentLoopContext accesses this.context.toolRegistry, it retrieves the agent-specific registry rather than inheriting the main agent's registry through the prototype chain.
  • Enhanced Test Coverage: Added new test cases to agent-scheduler.test.ts to specifically validate the toolRegistry getter override and to browserAgentFactory.test.ts to confirm that all expected MCP navigation tools are correctly included in the browser agent definition.
Changelog
  • packages/core/src/agents/agent-scheduler.test.ts
    • Refactored mock configuration setup for agent scheduler tests.
    • Added a new test case to validate the toolRegistry getter override in sub-agent configurations.
  • packages/core/src/agents/agent-scheduler.ts
    • Applied Object.defineProperty to ensure sub-agent configurations correctly inherit their specific toolRegistry.
  • packages/core/src/agents/browser/browserAgentFactory.test.ts
    • Introduced a new test to verify that the browser agent definition correctly includes all required MCP navigation tools.
Activity
  • The author, gsquared94, has added/updated tests to cover the changes.
  • The author has validated the changes on MacOS using npm run.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@gsquared94 gsquared94 force-pushed the fix/browser-agent-tool-registry branch from 5fffc30 to 52b9d4a Compare March 9, 2026 20:28
@gemini-cli gemini-cli bot added the area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality label Mar 9, 2026
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
@gsquared94 gsquared94 force-pushed the fix/browser-agent-tool-registry branch from 52b9d4a to af0e5d3 Compare March 9, 2026 20:35
@gsquared94 gsquared94 enabled auto-merge March 9, 2026 20:40
Object.defineProperty(agentConfig, 'toolRegistry', {
get: () => toolRegistry,
configurable: true,
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, if we're doing this for the AgentLoopContext interface, do we also need to override the messageBus in a similar way?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need to replace this Object.create hack with an explicit AgentLoopContext to avoid fragile prototype getter overrides altogether.

Copy link
Copy Markdown
Contributor

@abhipatel12 abhipatel12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gsquared94 gsquared94 added this pull request to the merge queue Mar 9, 2026
@abhipatel12 abhipatel12 removed this pull request from the merge queue due to a manual request Mar 9, 2026
@gsquared94 gsquared94 added this pull request to the merge queue Mar 10, 2026
Merged via the queue into google-gemini:main with commit 02d4451 Mar 10, 2026
27 checks passed
@gsquared94 gsquared94 deleted the fix/browser-agent-tool-registry branch March 10, 2026 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(core): Browser agent fails with "Tool not found" for all MCP tools (new_page, navigate_page, etc.)

2 participants