Skip to content

Commit 2490a4b

Browse files
authored
feat(bigquery): add conversational analytics tools for Data Agents (googleapis#2517)
Implements new tools to interact with BigQuery Data Agents and aligns BigQuery source method names with other sources for future cross-source compatibility. - Add three new tools: 'ask_data_agent', 'get_data_agent_info', and 'list_accessible_data_agents' under 'conversationalanalytics'. - Rename BigQuery source methods to 'GoogleCloudProject' and 'GoogleCloudLocation' to unify interface with other source types. - Update 'GoogleCloudTokenSourceWithScope' to support flexible scope parameterization. - Update existing BigQuery tools to use consistent source method names. - Add 'bigquery-conversational-analytics-with-data-agent' prebuilt config. - Include comprehensive integration tests for Data Agent tools. - Update documentation for the new prebuilt toolset. ## Description > Should include a concise description of the changes (bug or feature), it's > impact, along with a summary of the solution ## PR Checklist > Thank you for opening a Pull Request! Before submitting your PR, there are a > few things you can do to make sure it goes smoothly: - [ ] Make sure you reviewed [CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md) - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) - [ ] Make sure to add `!` if this involve a breaking change 🛠️ Fixes #<issue_number_goes_here>
1 parent a10cf43 commit 2490a4b

16 files changed

+2064
-1
lines changed

cmd/internal/imports.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ import (
8383
_ "github.com/googleapis/genai-toolbox/internal/tools/cockroachdb/cockroachdblistschemas"
8484
_ "github.com/googleapis/genai-toolbox/internal/tools/cockroachdb/cockroachdblisttables"
8585
_ "github.com/googleapis/genai-toolbox/internal/tools/cockroachdb/cockroachdbsql"
86+
_ "github.com/googleapis/genai-toolbox/internal/tools/conversationalanalytics/conversationalanalyticsaskdataagent"
87+
_ "github.com/googleapis/genai-toolbox/internal/tools/conversationalanalytics/conversationalanalyticsgetdataagentinfo"
88+
_ "github.com/googleapis/genai-toolbox/internal/tools/conversationalanalytics/conversationalanalyticslistaccessibledataagents"
8689
_ "github.com/googleapis/genai-toolbox/internal/tools/couchbase"
8790
_ "github.com/googleapis/genai-toolbox/internal/tools/dataform/dataformcompilelocal"
8891
_ "github.com/googleapis/genai-toolbox/internal/tools/dataplex/dataplexlookupcontext"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: "Prebuilt Configs"
3+
type: docs
4+
description: "Prebuilt configurations for Conversational Analytics to perform natural language data analysis via Data Agents."
5+
---
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
title: "Conversational Analytics with Data Agent"
3+
type: docs
4+
description: "Details of the Conversational Analytics with Data Agent prebuilt configuration."
5+
---
6+
7+
## Conversational Analytics with Data Agent
8+
9+
* `--prebuilt` value: `conversational-analytics-with-data-agent`
10+
* **Environment Variables:**
11+
* `CLOUD_GDA_PROJECT`: The GCP project ID.
12+
* `CLOUD_GDA_LOCATION`: (Optional) The location of the data agent (e.g., `us` or `eu`). Defaults to `global`.
13+
* `CLOUD_GDA_USE_CLIENT_OAUTH`: (Optional) If `true`, forwards the client's
14+
OAuth access token for authentication. Defaults to `false`.
15+
* `CLOUD_GDA_MAX_RESULTS`: (Optional) The maximum number of rows
16+
to return. Defaults to `50`.
17+
* **Permissions:**
18+
* **Gemini Data Analytics Stateless Chat User (Beta)** (`roles/geminidataanalytics.dataAgentStatelessUser`) to interact with the data agent.
19+
* **BigQuery User** (`roles/bigquery.user`) and **BigQuery Data Viewer** (`roles/bigquery.dataViewer`) on the underlying datasets/tables to allow the data agent to execute queries.
20+
* **Tools:**
21+
* `ask_data_agent`: Use this tool to perform natural language data analysis,
22+
get insights, or answer complex questions using pre-configured data
23+
sources via a specific Data Agent. For more information on
24+
required roles, API setup, and IAM configuration, see the setup and
25+
authentication section of the [Conversational Analytics API
26+
documentation](https://cloud.google.com/gemini/docs/conversational-analytics-api/overview).
27+
* `get_data_agent_info`: Retrieve details about a specific data agent.
28+
* `list_accessible_data_agents`: List data agents that are accessible.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: "conversational-analytics-ask-data-agent"
3+
type: docs
4+
weight: 1
5+
description: >
6+
A "conversational-analytics-ask-data-agent" tool allows conversational interaction with a Conversational Analytics source.
7+
aliases:
8+
- /resources/tools/conversational-analytics-ask-data-agent
9+
---
10+
11+
## About
12+
13+
A `conversational-analytics-ask-data-agent` tool allows you to ask questions about
14+
your data in natural language.
15+
16+
This function takes a user's question (which can include conversational history
17+
for context) and references to a specific BigQuery Data Agent, and sends them to a
18+
stateless conversational API.
19+
20+
The API uses a GenAI agent to understand the question, generate and execute SQL
21+
queries and Python code, and formulate an answer. This function returns a
22+
detailed, sequential log of this entire process, which includes any generated
23+
SQL or Python code, the data retrieved, and the final text answer.
24+
25+
**Note**: This tool requires additional setup in your project. Please refer to
26+
the official Conversational Analytics API
27+
documentation
28+
for instructions.
29+
30+
It's compatible with the following sources:
31+
32+
- cloud-gemini-data-analytics
33+
34+
`conversational-analytics-ask-data-agent` accepts the following parameters:
35+
36+
- **`user_query_with_context`:** The question to ask the agent, potentially
37+
including conversation history for context.
38+
- **`data_agent_id`:** The ID of the data agent to ask.
39+
40+
## Example
41+
42+
```yaml
43+
tools:
44+
ask_data_agent:
45+
kind: conversational-analytics-ask-data-agent
46+
source: my-conversational-analytics-source
47+
location: global
48+
maxResults: 50
49+
description: |
50+
Perform natural language data analysis and get insights by interacting
51+
with a specific BigQuery Data Agent. This tool allows for conversational
52+
queries and provides detailed responses based on the agent's configured
53+
data sources.
54+
```
55+
56+
## Reference
57+
58+
| **field** | **type** | **required** | **description** |
59+
|-------------|:--------:|:------------:|----------------------------------------------------|
60+
| kind | string | true | Must be "conversational-analytics-ask-data-agent". |
61+
| source | string | true | Name of the source for chat. |
62+
| description | string | true | Description of the tool that is passed to the LLM. |
63+
| location | string | false | The Google Cloud location (default: "global"). |
64+
| maxResults | integer | false | The maximum number of data rows to return in the tool's final response (default: 50). This only limits the amount of data included in the final tool return to prevent excessive token consumption, and does not affect the internal analytical process or intermediate steps. |
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: "conversational-analytics-get-data-agent-info"
3+
type: docs
4+
weight: 1
5+
description: >
6+
A "conversational-analytics-get-data-agent-info" tool allows retrieving information about a specific Conversational Analytics data agent.
7+
aliases:
8+
- /resources/tools/conversational-analytics-get-data-agent-info
9+
---
10+
11+
## About
12+
13+
A `conversational-analytics-get-data-agent-info` tool allows you to retrieve
14+
details about a specific data agent.
15+
16+
It's compatible with the following sources:
17+
18+
- cloud-gemini-data-analytics
19+
20+
`conversational-analytics-get-data-agent-info` accepts the following parameters:
21+
22+
- **`data_agent_id`:** The ID of the data agent to retrieve information for.
23+
24+
## Example
25+
26+
```yaml
27+
tools:
28+
get_agent_info:
29+
kind: conversational-analytics-get-data-agent-info
30+
source: my-conversational-analytics-source
31+
location: global
32+
description: |
33+
Use this tool to get details about a specific data agent.
34+
```
35+
36+
## Reference
37+
38+
| **field** | **type** | **required** | **description** |
39+
|-------------|:--------:|:------------:|----------------------------------------------------|
40+
| kind | string | true | Must be "conversational-analytics-get-data-agent-info". |
41+
| source | string | true | Name of the source. |
42+
| description | string | true | Description of the tool that is passed to the LLM. |
43+
| location | string | false | The Google Cloud location (default: "global"). |
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: "conversational-analytics-list-accessible-data-agents"
3+
type: docs
4+
weight: 1
5+
description: >
6+
A "conversational-analytics-list-accessible-data-agents" tool allows listing accessible Conversational Analytics data agents.
7+
aliases:
8+
- /resources/tools/conversational-analytics-list-accessible-data-agents
9+
---
10+
11+
## About
12+
13+
A `conversational-analytics-list-accessible-data-agents` tool allows you to list
14+
data agents that are accessible.
15+
16+
It's compatible with the following sources:
17+
18+
- cloud-gemini-data-analytics
19+
20+
`conversational-analytics-list-accessible-data-agents` does not accept any parameters.
21+
22+
## Example
23+
24+
```yaml
25+
tools:
26+
list_agents:
27+
kind: conversational-analytics-list-accessible-data-agents
28+
source: my-conversational-analytics-source
29+
location: global
30+
description: |
31+
Use this tool to list available data agents.
32+
```
33+
34+
## Reference
35+
36+
| **field** | **type** | **required** | **description** |
37+
|-------------|:--------:|:------------:|----------------------------------------------------|
38+
| kind | string | true | Must be "conversational-analytics-list-accessible-data-agents". |
39+
| source | string | true | Name of the source. |
40+
| description | string | true | Description of the tool that is passed to the LLM. |
41+
| location | string | false | The Google Cloud location (default: "global"). |

internal/prebuiltconfigs/prebuiltconfigs_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var expectedToolSources = []string{
2626
"alloydb-postgres-admin",
2727
"alloydb-postgres-observability",
2828
"alloydb-postgres",
29+
"conversational-analytics-with-data-agent",
2930
"bigquery",
3031
"clickhouse",
3132
"cloud-healthcare",
@@ -113,6 +114,7 @@ func TestGetPrebuiltTool(t *testing.T) {
113114
alloydb_observability_config := getOrFatal(t, "alloydb-postgres-observability")
114115
alloydb_config := getOrFatal(t, "alloydb-postgres")
115116
bigquery_config := getOrFatal(t, "bigquery")
117+
conversational_analytics_config := getOrFatal(t, "conversational-analytics-with-data-agent")
116118
clickhouse_config := getOrFatal(t, "clickhouse")
117119
cloudsqlpg_observability_config := getOrFatal(t, "cloud-sql-postgres-observability")
118120
cloudsqlpg_config := getOrFatal(t, "cloud-sql-postgres")
@@ -156,6 +158,9 @@ func TestGetPrebuiltTool(t *testing.T) {
156158
if len(bigquery_config) <= 0 {
157159
t.Fatalf("unexpected error: could not fetch bigquery prebuilt tools yaml")
158160
}
161+
if len(conversational_analytics_config) <= 0 {
162+
t.Fatalf("unexpected error: could not fetch bigquery conversational analytics prebuilt tools yaml")
163+
}
159164
if len(clickhouse_config) <= 0 {
160165
t.Fatalf("unexpected error: could not fetch clickhouse prebuilt tools yaml")
161166
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright 2026 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+
sources:
16+
conversational-analytics-source:
17+
kind: "cloud-gemini-data-analytics"
18+
projectId: ${CLOUD_GDA_PROJECT}
19+
useClientOAuth: ${CLOUD_GDA_USE_CLIENT_OAUTH:false}
20+
21+
tools:
22+
list-accessible-data-agents:
23+
kind: conversational-analytics-list-accessible-data-agents
24+
source: conversational-analytics-source
25+
location: ${CLOUD_GDA_LOCATION:global}
26+
description: |
27+
List all available Data Agents that can be used for
28+
conversational analytics in the current project.
29+
30+
get-data-agent-info:
31+
kind: conversational-analytics-get-data-agent-info
32+
source: conversational-analytics-source
33+
location: ${CLOUD_GDA_LOCATION:global}
34+
description: |
35+
Retrieve detailed information about a specific Data Agent
36+
using its ID.
37+
38+
ask-data-agent:
39+
kind: conversational-analytics-ask-data-agent
40+
source: conversational-analytics-source
41+
location: ${CLOUD_GDA_LOCATION:global}
42+
maxResults: ${CLOUD_GDA_MAX_RESULTS:50}
43+
description: |
44+
Perform natural language data analysis and get insights by interacting
45+
with a specific Data Agent. This tool allows for conversational
46+
queries and provides detailed responses based on the agent's configured
47+
data sources.
48+
49+
toolsets:
50+
conversational_analytics_tools:
51+
- list-accessible-data-agents
52+
- get-data-agent-info
53+
- ask-data-agent

internal/sources/cloudgda/cloud_gda.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ import (
2424
"github.com/googleapis/genai-toolbox/internal/util"
2525
"go.opentelemetry.io/otel/trace"
2626
"golang.org/x/oauth2"
27+
"golang.org/x/oauth2/google"
2728
"google.golang.org/api/option"
2829
)
2930

3031
const SourceType string = "cloud-gemini-data-analytics"
32+
const CloudPlatformScope string = "https://www.googleapis.com/auth/cloud-platform"
3133

3234
// NewDataChatClient can be overridden for testing.
3335
var NewDataChatClient = geminidataanalytics.NewDataChatClient
@@ -103,6 +105,18 @@ func (s *Source) GetProjectID() string {
103105
return s.ProjectID
104106
}
105107

108+
func (s *Source) GoogleCloudTokenSourceWithScope(ctx context.Context, scope string) (oauth2.TokenSource, error) {
109+
if scope == "" {
110+
scope = CloudPlatformScope
111+
}
112+
113+
creds, err := google.FindDefaultCredentials(ctx, scope)
114+
if err != nil {
115+
return nil, fmt.Errorf("failed to find default credentials: %w", err)
116+
}
117+
return creds.TokenSource, nil
118+
}
119+
106120
func (s *Source) UseClientAuthorization() bool {
107121
return s.UseClientOAuth
108122
}

0 commit comments

Comments
 (0)