mirror of
https://github.com/EvolutionAPI/adk-python.git
synced 2025-12-19 03:42:22 -06:00
Create a developer folder and add samples.
PiperOrigin-RevId: 755885332
This commit is contained in:
committed by
Copybara-Service
parent
180c2a934b
commit
a4adb739c0
51
contributing/samples/bigquery_agent/README.md
Normal file
51
contributing/samples/bigquery_agent/README.md
Normal file
@@ -0,0 +1,51 @@
|
||||
# OAuth Sample
|
||||
|
||||
## Introduction
|
||||
|
||||
This sample tests and demos the OAuth support in ADK via two tools:
|
||||
|
||||
* 1. bigquery_datasets_list:
|
||||
|
||||
List user's datasets.
|
||||
|
||||
* 2. bigquery_datasets_get:
|
||||
Get a dataset's details.
|
||||
|
||||
* 3. bigquery_datasets_insert:
|
||||
Create a new dataset.
|
||||
|
||||
* 4. bigquery_tables_list:
|
||||
List all tables in a dataset.
|
||||
|
||||
* 5. bigquery_tables_get:
|
||||
Get a table's details.
|
||||
|
||||
* 6. bigquery_tables_insert:
|
||||
Insert a new table into a dataset.
|
||||
|
||||
## How to use
|
||||
|
||||
* 1. Follow https://developers.google.com/identity/protocols/oauth2#1.-obtain-oauth-2.0-credentials-from-the-dynamic_data.setvar.console_name. to get your client id and client secret.
|
||||
Be sure to choose "web" as your client type.
|
||||
|
||||
* 2. Configure your .env file to add two variables:
|
||||
|
||||
* GOOGLE_CLIENT_ID={your client id}
|
||||
* GOOGLE_CLIENT_SECRET={your client secret}
|
||||
|
||||
Note: done't create a separate .env , instead put it to the same .env file that stores your Vertex AI or Dev ML credentials
|
||||
|
||||
* 3. Follow https://developers.google.com/identity/protocols/oauth2/web-server#creatingcred to add http://localhost/dev-ui to "Authorized redirect URIs".
|
||||
|
||||
Note: localhost here is just a hostname that you use to access the dev ui, replace it with the actual hostname you use to access the dev ui.
|
||||
|
||||
* 4. For 1st run, allow popup for localhost in Chrome.
|
||||
|
||||
## Sample prompt
|
||||
|
||||
* `Do I have any datasets in project sean-dev-agent ?`
|
||||
* `Do I have any tables under it ?`
|
||||
* `could you get me the details of this table ?`
|
||||
* `Can you help to create a new dataset in the same project? id : sean_test , location: us`
|
||||
* `could you show me the details of this new dataset ?`
|
||||
* `could you create a new table under this dataset ? table name : sean_test_table. column1 : name is id , type is integer, required. column2 : name is info , type is string, required. column3 : name is backup , type is string, optional.`
|
||||
15
contributing/samples/bigquery_agent/__init__.py
Normal file
15
contributing/samples/bigquery_agent/__init__.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# Copyright 2025 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from . import agent
|
||||
84
contributing/samples/bigquery_agent/agent.py
Normal file
84
contributing/samples/bigquery_agent/agent.py
Normal file
@@ -0,0 +1,84 @@
|
||||
# Copyright 2025 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import os
|
||||
|
||||
from dotenv import load_dotenv
|
||||
from google.adk import Agent
|
||||
from google.adk.tools.google_api_tool import bigquery_tool_set
|
||||
|
||||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
|
||||
# Access the variable
|
||||
oauth_client_id = os.getenv("OAUTH_CLIENT_ID")
|
||||
oauth_client_secret = os.getenv("OAUTH_CLIENT_SECRET")
|
||||
bigquery_tool_set.configure_auth(oauth_client_id, oauth_client_secret)
|
||||
|
||||
bigquery_datasets_list = bigquery_tool_set.get_tool("bigquery_datasets_list")
|
||||
bigquery_datasets_get = bigquery_tool_set.get_tool("bigquery_datasets_get")
|
||||
bigquery_datasets_insert = bigquery_tool_set.get_tool(
|
||||
"bigquery_datasets_insert"
|
||||
)
|
||||
|
||||
bigquery_tables_list = bigquery_tool_set.get_tool("bigquery_tables_list")
|
||||
bigquery_tables_get = bigquery_tool_set.get_tool("bigquery_tables_get")
|
||||
bigquery_tables_insert = bigquery_tool_set.get_tool("bigquery_tables_insert")
|
||||
|
||||
|
||||
root_agent = Agent(
|
||||
model="gemini-2.0-flash",
|
||||
name="bigquery_agent",
|
||||
instruction="""
|
||||
You are a helpful Google BigQuery agent that help to manage users' data on Goolge BigQuery.
|
||||
Use the provided tools to conduct various operations on users' data in Google BigQuery.
|
||||
|
||||
Scenario 1:
|
||||
The user wants to query their biguqery datasets
|
||||
Use bigquery_datasets_list to query user's datasets
|
||||
|
||||
Scenario 2:
|
||||
The user wants to query the details of a specific dataset
|
||||
Use bigquery_datasets_get to get a dataset's details
|
||||
|
||||
Scenario 3:
|
||||
The user wants to create a new dataset
|
||||
Use bigquery_datasets_insert to create a new dataset
|
||||
|
||||
Scenario 4:
|
||||
The user wants to query their tables in a specific dataset
|
||||
Use bigquery_tables_list to list all tables in a dataset
|
||||
|
||||
Scenario 5:
|
||||
The user wants to query the details of a specific table
|
||||
Use bigquery_tables_get to get a table's details
|
||||
|
||||
Scenario 6:
|
||||
The user wants to insert a new table into a dataset
|
||||
Use bigquery_tables_insert to insert a new table into a dataset
|
||||
|
||||
Current user:
|
||||
<User>
|
||||
{userInfo?}
|
||||
</User>
|
||||
""",
|
||||
tools=[
|
||||
bigquery_datasets_list,
|
||||
bigquery_datasets_get,
|
||||
bigquery_datasets_insert,
|
||||
bigquery_tables_list,
|
||||
bigquery_tables_get,
|
||||
bigquery_tables_insert,
|
||||
],
|
||||
)
|
||||
Reference in New Issue
Block a user