|
| 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 | +import os |
| 16 | + |
| 17 | +from dotenv import load_dotenv |
| 18 | +from google.adk import Agent |
| 19 | +from google.adk.tools.google_api_tool import bigquery_tool_set |
| 20 | + |
| 21 | +# Load environment variables from .env file |
| 22 | +load_dotenv() |
| 23 | + |
| 24 | +# Access the variable |
| 25 | +oauth_client_id = os.getenv("OAUTH_CLIENT_ID") |
| 26 | +oauth_client_secret = os.getenv("OAUTH_CLIENT_SECRET") |
| 27 | +bigquery_tool_set.configure_auth(oauth_client_id, oauth_client_secret) |
| 28 | + |
| 29 | +bigquery_datasets_list = bigquery_tool_set.get_tool("bigquery_datasets_list") |
| 30 | +bigquery_datasets_get = bigquery_tool_set.get_tool("bigquery_datasets_get") |
| 31 | +bigquery_datasets_insert = bigquery_tool_set.get_tool( |
| 32 | + "bigquery_datasets_insert" |
| 33 | +) |
| 34 | + |
| 35 | +bigquery_tables_list = bigquery_tool_set.get_tool("bigquery_tables_list") |
| 36 | +bigquery_tables_get = bigquery_tool_set.get_tool("bigquery_tables_get") |
| 37 | +bigquery_tables_insert = bigquery_tool_set.get_tool("bigquery_tables_insert") |
| 38 | + |
| 39 | + |
| 40 | +root_agent = Agent( |
| 41 | + model="gemini-2.0-flash", |
| 42 | + name="bigquery_agent", |
| 43 | + instruction=""" |
| 44 | + You are a helpful Google BigQuery agent that help to manage users' data on Goolge BigQuery. |
| 45 | + Use the provided tools to conduct various operations on users' data in Google BigQuery. |
| 46 | +
|
| 47 | + Scenario 1: |
| 48 | + The user wants to query their biguqery datasets |
| 49 | + Use bigquery_datasets_list to query user's datasets |
| 50 | +
|
| 51 | + Scenario 2: |
| 52 | + The user wants to query the details of a specific dataset |
| 53 | + Use bigquery_datasets_get to get a dataset's details |
| 54 | +
|
| 55 | + Scenario 3: |
| 56 | + The user wants to create a new dataset |
| 57 | + Use bigquery_datasets_insert to create a new dataset |
| 58 | +
|
| 59 | + Scenario 4: |
| 60 | + The user wants to query their tables in a specific dataset |
| 61 | + Use bigquery_tables_list to list all tables in a dataset |
| 62 | +
|
| 63 | + Scenario 5: |
| 64 | + The user wants to query the details of a specific table |
| 65 | + Use bigquery_tables_get to get a table's details |
| 66 | +
|
| 67 | + Scenario 6: |
| 68 | + The user wants to insert a new table into a dataset |
| 69 | + Use bigquery_tables_insert to insert a new table into a dataset |
| 70 | +
|
| 71 | + Current user: |
| 72 | + <User> |
| 73 | + {userInfo?} |
| 74 | + </User> |
| 75 | +""", |
| 76 | + tools=[ |
| 77 | + bigquery_datasets_list, |
| 78 | + bigquery_datasets_get, |
| 79 | + bigquery_datasets_insert, |
| 80 | + bigquery_tables_list, |
| 81 | + bigquery_tables_get, |
| 82 | + bigquery_tables_insert, |
| 83 | + ], |
| 84 | +) |
0 commit comments