fix: raise clear ImportError when VertexAiSearchTool bypass needs google-adk[gcp] - #7101
Closed
chelsealong wants to merge 1 commit into
Closed
chelsealong wants to merge 1 commit into
chelsealong wants to merge 1 commit into
Conversation
…gle-adk[gcp] Setting bypass_multi_tools_limit=True on VertexAiSearchTool swaps it for DiscoveryEngineSearchTool, which requires the google-cloud-discoveryengine package. Previously the missing dependency surfaced as a raw ModuleNotFoundError from deep inside the package with no hint at what to install. Now the import failure is caught and re-raised with a message pointing to `pip install google-adk[gcp]`. Fixes google#7100 (partially: the dependency-error portion of the report).
1 task
musi22
added a commit
to musi22/adk-python
that referenced
this pull request
Sep 15, 2026
…ypass path to DiscoveryEngineSearchTool When bypass_multi_tools_limit=True converts VertexAiSearchTool to a client-side DiscoveryEngineSearchTool, the resulting tool was always named 'discovery_engine_search' — an internal implementation name. Developers had no way to express a domain-specific tool name, forcing them to leak GCP internals into agent instructions or accept runtime ValueError: Tool 'search' not found crashes. DiscoveryEngineSearchTool already accepted name/description params but they were unreachable through the conversion path. - Add optional name/description kwargs to VertexAiSearchTool.__init__ stored as _bypass_tool_name/_bypass_tool_description to never shadow the base-class 'vertex_ai_search' name used in the grounding path - Forward them in llm_agent.py during the bypass conversion - Add 5 unit tests for the agent conversion path - Add 4 unit tests for DiscoveryEngineSearchTool constructor Fixes: google#7100 (partial — addresses problem 3, hardcoded tool naming) Related: google#7101
copybara-service Bot
pushed a commit
that referenced
this pull request
Sep 15, 2026
Merge #7101 Wrap the lazy DiscoveryEngineSearchTool import in a try/except ImportError, raising an actionable error message when google-adk[gcp] is not installed. PiperOrigin-RevId: 981968910
Collaborator
|
Thank you @chelsealong for your contribution! 🎉 Your changes have been successfully imported and merged via Copybara in commit 4e73b7d. Closing this PR as the changes are now in the main branch. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
bypass_multi_tools_limitonVertexAiSearchToolis a leaky abstraction: unexpected dependencies, silent shift from inbuilt RAG to tool calling, and prompt fragility #71002. Or, if no issue exists, describe the change:
Problem:
Issue #7100 reports several problems with
VertexAiSearchTool(bypass_multi_tools_limit=True). This PR addresses one specific, well-scoped part of it: point 4 in the issue's "Suggested Improvements" ("Fail Fast with Clear Dependency Errors"). Settingbypass_multi_tools_limit=Truesilently swapsVertexAiSearchToolforDiscoveryEngineSearchTool, which requires thegoogle-cloud-discoveryenginepackage (thegoogle-adk[gcp]extra). When that package isn't installed, the failure previously surfaced as a bareModuleNotFoundErrorfrom deep insidediscovery_engine_search_tool.py, with no indication of what to install.The other points raised in the issue (allowing a custom tool name/description, aliasing/fuzzy tool-name resolution, and whether to deprecate
bypass_multi_tools_limitin favor of a different pattern) are API-shape/design decisions for maintainers to weigh in on, so this PR does not attempt them.Solution:
Wrap the lazy
DiscoveryEngineSearchToolimport in_convert_tool_union_to_tools(src/google/adk/agents/llm_agent.py) in atry/except ImportError, re-raising with a message that names the missing dependency and the exact install command (pip install google-adk[gcp]).Testing Plan
Unit Tests:
Added
test_handle_vais_with_other_tools_missing_gcp_extratotests/unittests/agents/test_llm_agent_fields.py, which simulates the missing dependency viasys.modulespatching and asserts the new, actionableImportErrormessage is raised.Confirmed the new test fails without the fix (reverting
llm_agent.pytoHEAD~1and re-running):With the fix applied:
Full unit test suite, unaffected:
pyink --checkon the changed files reports no formatting issues.Manual End-to-End (E2E) Tests:
Not applicable — this is a small, targeted error-message change exercised entirely by the added unit test; no live GCP/Discovery Engine access is needed to observe the behavior.
Checklist
Additional context
This PR intentionally does not attempt the other suggestions in #7100 (custom tool naming/description, tool-name alias resolution, deprecating
bypass_multi_tools_limit), since those involve API-shape decisions that should be made by maintainers rather than assumed by a contributor.🤖 Generated with Claude Code