Skip to content

Feat: Google Search Agent Tool#316

Closed
AmaadMartin wants to merge 10 commits into
google:mainfrom
AmaadMartin:feat/google-search-agent-tool
Closed

Feat: Google Search Agent Tool#316
AmaadMartin wants to merge 10 commits into
google:mainfrom
AmaadMartin:feat/google-search-agent-tool

Conversation

@AmaadMartin

Copy link
Copy Markdown
Collaborator

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

Problem: The built-in GoogleSearchTool cannot be used together with other tools in the same agent due to model limitations in Gemini 1.x. In adk-python, a workaround was implemented to automatically wrap the GoogleSearchTool in a specialized sub-agent (GoogleSearchAgentTool) when multiple tools are present, allowing it to function alongside others. This capability was missing in adk-js.

Solution: Ported the GoogleSearchAgentTool feature from adk-python to adk-js. This includes:

  • Automatic wrapping of GoogleSearchTool in GoogleSearchAgentTool when bypassMultiToolsLimit is true and multiple tools are present.
  • Propagation of grounding metadata from the sub-agent to the parent agent's session state.
  • Proper integration with the model override configuration.

Testing Plan

Please describe the tests that you ran to verify your changes. This is required for all PRs that are not small documentation or typo fixes.

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

I ran the specific test file core/test/tools/google_search_agent_tool_test.ts and all 13 tests passed.
Coverage for core/src/tools/google_search_agent_tool.ts and core/src/tools/google_search_tool.ts achieved 100%.

Integration Tests (Serving as Manual E2E):
An integration test was created at tests/integration/tools/google_search_agent_tool_test.ts to simulate the full flow of automatic wrapping and grounding metadata propagation using mocked responses. This test serves as the verification for the end-to-end behavior, as manual testing with live models was not performed.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.

@AmaadMartin AmaadMartin force-pushed the feat/google-search-agent-tool branch from 0166981 to 72d74e5 Compare April 29, 2026 20:27
Comment thread core/src/agents/llm_agent.ts Outdated
const searchTool = toolUnion as unknown as GoogleSearchTool;
if (searchTool.bypassMultiToolsLimit) {
const {createGoogleSearchAgent, GoogleSearchAgentTool} =
await import('../tools/google_search_agent_tool.js');

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

please do not use inline imports

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

removed the inline import

Amaad Martin added 6 commits May 12, 2026 09:28
- Implement GoogleSearchAgentTool to wrap search sub-agent.

- Implement automatic wrapping of GoogleSearchTool in LlmAgent when used with other tools.

- Add propagateGroundingMetadata support to AgentTool.

- Add comprehensive unit tests with 100% coverage for new code.
@AmaadMartin AmaadMartin force-pushed the feat/google-search-agent-tool branch from 1337815 to 50ac619 Compare May 12, 2026 16:34

@ScottMansfield ScottMansfield left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A couple comments otherwise LGTM

/**
* A tool that wraps a sub-agent that only uses google_search tool.
*
* This is a workaround to support using google_search tool with other tools.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

let's add specifically when this is needed and the bug to remove this when it's no longer needed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done. I've updated the JSDoc for GoogleSearchAgentTool to clarify that it's used as a workaround when bypassMultiToolsLimit is enabled and multiple tools are configured, due to Gemini models not supporting built-in search tools alongside custom tools. I also added a reference to the tracking bug b/448114567 to remove it when no longer needed.

} as unknown as BaseLlm;

it('should wrap GoogleSearchTool when bypassMultiToolsLimit is true and there are multiple tools', async () => {
const searchTool = new GoogleSearchTool({bypassMultiToolsLimit: true});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this the expected API based on the Python implementation? How obvious is it to users if they misconfigure this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this matches the Python implementation. In Python, GoogleSearchTool accepts bypass_multi_tools_limit: bool = False.
If users misconfigure this (i.e., they have multiple tools but don't set bypassMultiToolsLimit: true):

  • TypeScript users will get a compile-time error if they misspell the option name, thanks to static typing.
  • At runtime (both JS and TS):
    • If they are using a Gemini 1.x model, ADK will throw an explicit, local error before making the API call: "Google search tool can not be used with other
      tools in Gemini 1.x.".
    • If they are using a Gemini >=2.x model, ADK will pass both tools to the platform (since Gemini 2.x often supports this natively). However, if they hit a platform-side limitation (e.g., in certain enterprise configurations or stateful APIs), the Gemini API will return a standard 400 Bad Request error,typically stating: "Builtin tool 'google_search' cannot be combined with other tools." So it should be very obvious to users via compile-time checks, local ADK validation errors (for 1.x), or explicit API platform errors (for 2.x).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants