feat: Provide location config for BigQuery tools

Right now the tolls are always running against multi-region US by default. With this change the agent builder can scope the tools to data and compute in a particular BigQuery location.

PiperOrigin-RevId: 806473857
This commit is contained in:
Google Team Member
2025-09-12 16:52:16 -07:00
committed by Copybara-Service
parent b3b31a9ffb
commit 4c00b86e33
7 changed files with 52 additions and 9 deletions
+16 -2
View File
@@ -29,16 +29,30 @@ def get_bigquery_client(
*,
project: Optional[str],
credentials: Credentials,
location: Optional[str] = None,
user_agent: Optional[str] = None,
) -> bigquery.Client:
"""Get a BigQuery client."""
"""Get a BigQuery client.
Args:
project: The GCP project ID.
credentials: The credentials to use for the request.
location: The location of the BigQuery client.
user_agent: The user agent to use for the request.
Returns:
A BigQuery client.
"""
user_agent = f"{USER_AGENT} {user_agent}" if user_agent else USER_AGENT
client_info = google.api_core.client_info.ClientInfo(user_agent=user_agent)
bigquery_client = bigquery.Client(
project=project, credentials=credentials, client_info=client_info
project=project,
credentials=credentials,
location=location,
client_info=client_info,
)
return bigquery_client
+9
View File
@@ -82,6 +82,15 @@ class BigQueryToolConfig(BaseModel):
operations (such as query execution) in a specific project.
"""
location: Optional[str] = None
"""BigQuery location to use for the data and compute.
This can be set if the BigQuery tools are expected to process data in a
particular BigQuery location. If not set, then location would be automatically
determined based on the data location in the query. For all supported
locations, see https://cloud.google.com/bigquery/docs/locations.
"""
@field_validator('application_name')
@classmethod
def validate_application_name(cls, v):
@@ -50,6 +50,7 @@ def list_dataset_ids(
bq_client = client.get_bigquery_client(
project=project_id,
credentials=credentials,
location=settings.location,
user_agent=settings.application_name,
)
@@ -121,6 +122,7 @@ def get_dataset_info(
bq_client = client.get_bigquery_client(
project=project_id,
credentials=credentials,
location=settings.location,
user_agent=settings.application_name,
)
dataset = bq_client.get_dataset(
@@ -159,6 +161,7 @@ def list_table_ids(
bq_client = client.get_bigquery_client(
project=project_id,
credentials=credentials,
location=settings.location,
user_agent=settings.application_name,
)
@@ -281,6 +284,7 @@ def get_table_info(
bq_client = client.get_bigquery_client(
project=project_id,
credentials=credentials,
location=settings.location,
user_agent=settings.application_name,
)
return bq_client.get_table(
@@ -97,6 +97,7 @@ def execute_sql(
bq_client = client.get_bigquery_client(
project=project_id,
credentials=credentials,
location=settings.location,
user_agent=settings.application_name,
)