Skip to content

Commit 103e88e

Browse files
google-genai-botcopybara-github
authored andcommitted
test: Add evaluation for BigQuery tools
We should treat this as the first step towards building a robust eval story for BQ tools. PiperOrigin-RevId: 807247053
1 parent 7870480 commit 103e88e

File tree

5 files changed

+701
-0
lines changed

5 files changed

+701
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Instructions
2+
3+
## Run Evaluation
4+
5+
1. Set environment variables in your terminal:
6+
7+
```shell
8+
export GOOGLE_GENAI_USE_VERTEXAI=FALSE
9+
export GOOGLE_API_KEY=<your_api_key>
10+
export GOOGLE_CLOUD_PROJECT=<your_bigquery_project>
11+
```
12+
1. Change to the current directory:
13+
14+
```shell
15+
cd third_party/py/google/adk/tests/integration/fixture/bigquery_agent/
16+
```
17+
1. Customize the evaluation dataset to the environment `GOOGLE_CLOUD_PROJECT`
18+
by replacing the placeholder to the real project set in your environment:
19+
20+
```shell
21+
sed -e "s:\${GOOGLE_CLOUD_PROJECT}:${GOOGLE_CLOUD_PROJECT}:g" simple.test.json -i
22+
```
23+
1. Run the following command as per https://google.github.io/adk-docs/evaluate/#3-adk-eval-run-evaluations-via-the-cli:
24+
25+
```shell
26+
adk eval . simple.test.json --config_file_path=test_config.json
27+
```
28+
29+
If it fails, re-run with `--print_detailed_results` flag to see more details
30+
on turn-by-turn evaluation.
31+
32+
## Generate Evaluation dataset
33+
34+
1. Set environment variables in your terminal:
35+
36+
```shell
37+
export GOOGLE_GENAI_USE_VERTEXAI=FALSE
38+
export GOOGLE_API_KEY=<your_api_key>
39+
export GOOGLE_CLOUD_PROJECT=<your_bigquery_project>
40+
```
41+
1. Set up google [application default credentials](https://cloud.google.com/docs/authentication/provide-credentials-adc)
42+
on your machine.
43+
44+
```shell
45+
gcloud auth application-default login
46+
```
47+
1. Change to the directory containing agent folder:
48+
49+
```shell
50+
cd third_party/py/google/adk/tests/integration/fixture/
51+
```
52+
1. Run the following command to start the ADK web app:
53+
54+
```shell
55+
adk web
56+
```
57+
1. Open the ADK web UI in your browser http://127.0.0.1:8000/dev-ui/?app=bigquery_agent.
58+
1. Create an evaluation dataset by following [these steps](https://google.github.io/adk-docs/evaluate/#1-adk-web-run-evaluations-via-the-web-ui).
59+
This would generate file `bigquery_agent/simple.evalset.json`.
60+
1. Note that this evaluation data would be tied to the agent interaction in the
61+
`GOOGLE_CLOUD_PROJECT` set in your environment. To normalize it by replacing
62+
the real project set in your environment to a placeholder, let's run the
63+
following command:
64+
65+
```shell
66+
sed -e "s:${GOOGLE_CLOUD_PROJECT}:\${GOOGLE_CLOUD_PROJECT}:g" bigquery_agent/simple.evalset.json > bigquery_agent/simple.test.json
67+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from . import agent
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
import os
17+
18+
from google.adk.agents.llm_agent import LlmAgent
19+
from google.adk.tools.bigquery.bigquery_credentials import BigQueryCredentialsConfig
20+
from google.adk.tools.bigquery.bigquery_toolset import BigQueryToolset
21+
from google.adk.tools.bigquery.config import BigQueryToolConfig
22+
from google.adk.tools.bigquery.config import WriteMode
23+
import google.auth
24+
25+
# Check necessary environment variables
26+
if not (google_cloud_project_id := os.getenv("GOOGLE_CLOUD_PROJECT")):
27+
raise ValueError(
28+
"GOOGLE_CLOUD_PROJECT environment variable is not set. Please set it"
29+
" to the GCP project ID where your BigQuery jobs would be run."
30+
)
31+
32+
# Define an appropriate application name
33+
BIGQUERY_AGENT_NAME = "adk_eval_bigquery_agent"
34+
35+
36+
# Define BigQuery tool config with write mode set to allowed. Note that this is
37+
# only to demonstrate the full capability of the BigQuery tools. In production
38+
# you may want to change to BLOCKED (default write mode, effectively makes the
39+
# tool read-only) or PROTECTED (only allows writes in the anonymous dataset of a
40+
# BigQuery session) write mode.
41+
tool_config = BigQueryToolConfig(
42+
write_mode=WriteMode.BLOCKED,
43+
application_name=BIGQUERY_AGENT_NAME,
44+
compute_project_id=google_cloud_project_id,
45+
)
46+
47+
# Initialize the tools to use the application default credentials.
48+
# https://cloud.google.com/docs/authentication/provide-credentials-adc
49+
application_default_credentials, _ = google.auth.default()
50+
credentials_config = BigQueryCredentialsConfig(
51+
credentials=application_default_credentials
52+
)
53+
54+
bigquery_toolset = BigQueryToolset(
55+
credentials_config=credentials_config, bigquery_tool_config=tool_config
56+
)
57+
58+
# The variable name `root_agent` determines what your root agent is for the
59+
# debug CLI
60+
root_agent = LlmAgent(
61+
model="gemini-2.5-flash",
62+
name=BIGQUERY_AGENT_NAME,
63+
description=(
64+
"Agent to answer questions about BigQuery data and models and execute"
65+
" SQL queries."
66+
),
67+
instruction=f"""\
68+
You are a data science agent with access to several BigQuery tools.
69+
Make use of those tools to answer the user's questions.
70+
71+
You must use the project id {google_cloud_project_id} for running SQL
72+
queries and generating data insights
73+
""",
74+
tools=[bigquery_toolset],
75+
)

0 commit comments

Comments
 (0)