Skip to content

Conversation

@ranand12
Copy link

@ranand12 ranand12 commented Dec 30, 2025

PR Title
feat: support regional endpoints in DiscoveryEngineSearchTool


PR Description

  1. Link to an existing issue:

Problem:
DiscoveryEngineSearchTool was defaulting to the global Discovery Engine API endpoint. This caused failures (400 Incorrect API endpoint used. The current endpoint can only serve traffic from "global" region, but got "us" region from the API request. Please follow https://cloud.google.com/generative-ai-app-builder/docs/locations to use the correct regional API endpoint) when attempting to access Data Stores or Search Engines located in specific regions like us or eu.

Solution:
Updated the tool to dynamically detect the region from the resource ID:

  1. Parses the location from data_store_id or search_engine_id (e.g., projects/.../locations/us/...).
  2. Configures the SearchServiceClient with regional ClientOptions (e.g., us-discoveryengine.googleapis.com) when a
    specific region is detected.
  3. Falls back to the global endpoint if no region is specified or if it is explicitly global.

Testing Plan

Unit Tests:

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

Summary of passed pytest results:
1 $ uv run pytest tests/unittests/tools/test_discovery_engine_search_tool.py
2 ============================= 9 passed in 3.90s ==============================
(Verified against the full suite of 3680 tests, all passed.)

Manual End-to-End (E2E) Tests:
To verify, initialize the tool using a regional Data Store ID and observe the client configuration:

1 from google.adk.tools.discovery_engine_search_tool import DiscoveryEngineSearchTool
2
3 # Regional ID
4 ds_id = "projects/my-project/locations/us/collections/default_collection/dataStores/my-ds"
5 tool = DiscoveryEngineSearchTool(data_store_id=ds_id)
6
7 # The internal client now uses the 'us-discoveryengine.googleapis.com' endpoint.

Checklist

  • I have read the [CONTRIBUTING.md (https://github.com/google/adk-python/blob/main/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
The implementation ensures that regional Data Stores work out-of-the-box without requiring users to manually configure API endpoints, while maintaining full backward compatibility for global stores.

@google-cla
Copy link

google-cla bot commented Dec 30, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ranand12, 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 enhances the DiscoveryEngineSearchTool to intelligently handle regional Google Cloud Discovery Engine instances. Previously, the tool would default to a global API endpoint, leading to errors when interacting with regionally deployed Data Stores or Search Engines. The updated implementation automatically parses the region from resource IDs and configures the underlying client to use the correct regional API endpoint, ensuring seamless operation across different geographical deployments while maintaining compatibility with global instances.

Highlights

  • Regional Endpoint Support: The DiscoveryEngineSearchTool now dynamically detects and utilizes regional API endpoints for Google Cloud Discovery Engine, resolving issues with accessing regional Data Stores or Search Engines.
  • Location Extraction: The tool extracts the location (e.g., 'us', 'eu') from the data_store_id or search_engine_id provided during initialization.
  • Dynamic Client Configuration: Based on the extracted location, the SearchServiceClient is configured with a specific regional API endpoint (e.g., us-discoveryengine.googleapis.com) using ClientOptions.
  • Global Endpoint Fallback: The tool maintains backward compatibility by falling back to the global Discovery Engine API endpoint if no specific region is identified or if 'global' is explicitly specified.
  • New Unit Test: A new unit test, test_init_with_location, has been added to verify that the SearchServiceClient is correctly initialized with the appropriate regional API endpoint.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.

@adk-bot adk-bot added the tools [Component] This issue is related to tools label Dec 30, 2025
@adk-bot
Copy link
Collaborator

adk-bot commented Dec 30, 2025

Response from ADK Triaging Agent

Hello @ranand12, thank you for your contribution!

Before we can merge this pull request, you'll need to sign the Contributor License Agreement (CLA). You can do so by following the instructions in the "cla/google" check at the bottom of the pull request.

Thanks!

Copy link
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 effectively adds support for regional endpoints in DiscoveryEngineSearchTool by dynamically detecting the location from the resource ID. The change is well-implemented and includes a corresponding unit test to ensure correctness. I have one suggestion to simplify the location parsing logic for improved code clarity and maintainability.

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

Labels

tools [Component] This issue is related to tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

discovery engine not working for non-global endpoints (400 error)

2 participants