Skip to content

fix: raise clear ImportError when VertexAiSearchTool bypass needs google-adk[gcp] - #7101

Closed
chelsealong wants to merge 1 commit into
google:mainfrom
chelsealong:fix-vais-bypass-discoveryengine-import-error
Closed

chelsealong wants to merge 1 commit into
google:mainfrom
chelsealong:fix-vais-bypass-discoveryengine-import-error

Conversation

@chelsealong

Copy link
Copy Markdown
Contributor

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):

2. 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"). Setting bypass_multi_tools_limit=True silently swaps VertexAiSearchTool for DiscoveryEngineSearchTool, which requires the google-cloud-discoveryengine package (the google-adk[gcp] extra). When that package isn't installed, the failure previously surfaced as a bare ModuleNotFoundError from deep inside discovery_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_limit in 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 DiscoveryEngineSearchTool import in _convert_tool_union_to_tools (src/google/adk/agents/llm_agent.py) in a try/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:

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

Added test_handle_vais_with_other_tools_missing_gcp_extra to tests/unittests/agents/test_llm_agent_fields.py, which simulates the missing dependency via sys.modules patching and asserts the new, actionable ImportError message is raised.

Confirmed the new test fails without the fix (reverting llm_agent.py to HEAD~1 and re-running):

$ python -m pytest tests/unittests/agents/test_llm_agent_fields.py -k vais -q
...
FAILED ...test_handle_vais_with_other_tools_missing_gcp_extra - AssertionError: Regex pattern did not match.
  Expected regex: 'google-adk\\[gcp\\]'
  Actual message: 'import of google.adk.tools.discovery_engine_search_tool halted; None in sys.modules'
1 failed, 5 passed, 89 deselected in 5.55s

With the fix applied:

$ python -m pytest tests/unittests/agents/test_llm_agent_fields.py -k vais -q
......                                                                   [100%]
6 passed, 89 deselected in 2.49s

Full unit test suite, unaffected:

$ python -m pytest tests/unittests -q
14670 passed, 82 skipped, 27 xfailed, 2 xpassed, 2009 warnings, 28 subtests passed in 405.19s

pyink --check on 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

  • 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.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

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

…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).
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
@adk-bot

adk-bot commented Sep 15, 2026

Copy link
Copy Markdown
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.

@adk-bot adk-bot added the merged [Status] This PR is merged label Sep 15, 2026
@adk-bot adk-bot closed this Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged [Status] This PR is merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants