Feat: Google Search Agent Tool#316
Conversation
0166981 to
72d74e5
Compare
| const searchTool = toolUnion as unknown as GoogleSearchTool; | ||
| if (searchTool.bypassMultiToolsLimit) { | ||
| const {createGoogleSearchAgent, GoogleSearchAgentTool} = | ||
| await import('../tools/google_search_agent_tool.js'); |
There was a problem hiding this comment.
please do not use inline imports
There was a problem hiding this comment.
removed the inline import
- 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.
…tadata propagation
1337815 to
50ac619
Compare
ScottMansfield
left a comment
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
let's add specifically when this is needed and the bug to remove this when it's no longer needed.
There was a problem hiding this comment.
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}); |
There was a problem hiding this comment.
Is this the expected API based on the Python implementation? How obvious is it to users if they misconfigure this?
There was a problem hiding this comment.
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).
- 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
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
Problem: The built-in
GoogleSearchToolcannot be used together with other tools in the same agent due to model limitations in Gemini 1.x. Inadk-python, a workaround was implemented to automatically wrap theGoogleSearchToolin a specialized sub-agent (GoogleSearchAgentTool) when multiple tools are present, allowing it to function alongside others. This capability was missing inadk-js.Solution: Ported the
GoogleSearchAgentToolfeature fromadk-pythontoadk-js. This includes:GoogleSearchToolinGoogleSearchAgentToolwhenbypassMultiToolsLimitis true and multiple tools are present.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 ran the specific test file
core/test/tools/google_search_agent_tool_test.tsand all 13 tests passed.Coverage for
core/src/tools/google_search_agent_tool.tsandcore/src/tools/google_search_tool.tsachieved 100%.Integration Tests (Serving as Manual E2E):
An integration test was created at
tests/integration/tools/google_search_agent_tool_test.tsto 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