Skip to content

Commit 7c9b0a2

Browse files
google-genai-botcopybara-github
authored andcommitted
feat: add chat first-party tool
This tool answers questions about structured data in BigQuery using natural language. PiperOrigin-RevId: 789000987
1 parent 0c6086c commit 7c9b0a2

File tree

12 files changed

+1008
-8
lines changed

12 files changed

+1008
-8
lines changed

contributing/samples/bigquery/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ distributed via the `google.adk.tools.bigquery` module. These tools include:
2525

2626
Runs a SQL query in BigQuery.
2727

28+
1. `ask_data_insights`
29+
30+
Natural language-in, natural language-out tool that answers questions
31+
about structured data in BigQuery. Provides a one-stop solution for generating
32+
insights from data.
33+
34+
**Note**: This tool requires additional setup in your project. Please refer to
35+
the official [Conversational Analytics API documentation](https://cloud.google.com/gemini/docs/conversational-analytics-api/overview)
36+
for instructions.
37+
2838
## How to use
2939

3040
Set up environment variables in your `.env` file for using

src/google/adk/tools/bigquery/bigquery_tool.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ def __init__(
6565
if credentials_config
6666
else None
6767
)
68-
self._tool_config = bigquery_tool_config
68+
self._tool_config = (
69+
bigquery_tool_config if bigquery_tool_config else BigQueryToolConfig()
70+
)
6971

7072
@override
7173
async def run_async(

src/google/adk/tools/bigquery/bigquery_toolset.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from google.adk.agents.readonly_context import ReadonlyContext
2222
from typing_extensions import override
2323

24+
from . import data_insights_tool
2425
from . import metadata_tool
2526
from . import query_tool
2627
from ...tools.base_tool import BaseTool
@@ -78,6 +79,7 @@ async def get_tools(
7879
metadata_tool.list_dataset_ids,
7980
metadata_tool.list_table_ids,
8081
query_tool.get_execute_sql(self._tool_config),
82+
data_insights_tool.ask_data_insights,
8183
]
8284
]
8385

src/google/adk/tools/bigquery/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
from __future__ import annotations
1616

17+
from typing import Optional
18+
1719
import google.api_core.client_info
1820
from google.auth.credentials import Credentials
1921
from google.cloud import bigquery
@@ -24,7 +26,7 @@
2426

2527

2628
def get_bigquery_client(
27-
*, project: str, credentials: Credentials
29+
*, project: Optional[str], credentials: Credentials
2830
) -> bigquery.Client:
2931
"""Get a BigQuery client."""
3032

src/google/adk/tools/bigquery/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,8 @@ class BigQueryToolConfig(BaseModel):
5454
By default, the tool will allow only read operations. This behaviour may
5555
change in future versions.
5656
"""
57+
58+
max_query_result_rows: int = 50
59+
"""Maximum number of rows to return from a query.
60+
61+
By default, the query result will be limited to 50 rows."""

0 commit comments

Comments
 (0)