10000 Create a developer folder and add samples. · luaifei/adk-python@a4adb73 · GitHub
[go: up one dir, main page]

Skip to content

Commit a4adb73

Browse files
hangfeicopybara-github
authored andcommitted
Create a developer folder and add samples.
PiperOrigin-RevId: 755885332
1 parent 180c2a9 commit a4adb73

File tree

49 files changed

+3194
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3194
-0
lines changed

.github/workflows/pyink.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
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+
115
name: Check Pyink Formatting
216

317
on:

.github/workflows/python-unit-tests.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
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+
115
name: Python Unit Tests
216

317
on:
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Application Integration Agent Sample
2+
3+
## Introduction
4+
5+
This sample demonstrates how to use the `ApplicationIntegrationToolset` within an ADK agent to interact with external applications, specifically Jira in this case. The agent (`agent.py`) is configured to manage Jira issues using a pre-configured Application Integration connection.
6+
7+
## Prerequisites
8+
9+
1. **Set up Integration Connection:**
10+
* You need an existing [Integration connection](https://cloud.google.com/integration-connectors/docs/overview) configured to interact with your Jira instance. Follow the [documentation](https://google.github.io/adk-docs/tools/google-cloud-tools/#use-integration-connectors) to provision the Integration Connector in Google Cloud and then use this [documentation](https://cloud.google.com/integration-connectors/docs/connectors/jiracloud/configure) to create an JIRA connection. Note the `Connection Name`, `Project ID`, and `Location` of your connection.
11+
*
12+
13+
2. **Configure Environment Variables:**
14+
* Create a `.env` file in the same directory as `agent.py` (or add to your existing one).
15+
* Add the following variables to the `.env` file, replacing the placeholder values with your actual connection details:
16+
17+
```dotenv
18+
CONNECTION_NAME=<YOUR_JIRA_CONNECTION_NAME>
19+
CONNECTION_PROJECT=<YOUR_GOOGLE_CLOUD_PROJECT_ID>
20+
CONNECTION_LOCATION=<YOUR_CONNECTION_LOCATION>
21+
```
22+
23+
## How to Use
24+
25+
1. **Install Dependencies:** Ensure you have the necessary libraries installed (e.g., `google-adk`, `python-dotenv`).
26+
2. **Run the Agent:** Execute the agent script from your terminal:
27+
```bash
28+
python agent.py
29+
```
30+
3. **Interact:** Once the agent starts, you can interact with it by typing prompts related to Jira issue management.
31+
32+
## Sample Prompts
33+
34+
Here are some examples of how you can interact with the agent:
35+
36+
* `Can you list me all the issues ?`
37+
* `Can you list me all the projects ?`
38+
* `Can you create an issue: "Bug in product XYZ" in project ABC ?`
39+
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: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
"""Sample agent using Application Integration toolset."""
16+
17+
import os
18+
19+
from dotenv import load_dotenv
20+
from google.adk.agents.llm_agent import LlmAgent
21+
from google.adk.tools.application_integration_tool import ApplicationIntegrationToolset
22+
23+
24+
# Load environment variables from .env file
25+
load_dotenv()
26+
27+
connection_name = os.getenv("CONNECTION_NAME")
28+
connection_project = os.getenv("CONNECTION_PROJECT")
29+
connection_location = os.getenv("CONNECTION_LOCATION")
30+
31+
32+
jira_tool = ApplicationIntegrationToolset(
33+
project=connection_project,
34+
location=connection_location,
35+
connection=connection_name,
36+
entity_operations={"Issues": [], "Projects": []},
37+
tool_name="jira_issue_manager",
38+
)
39+
40+
root_agent = LlmAgent(
41+
model="gemini-2.0-flash",
42+
name="Issue_Management_Agent",
43+
instruction="""
44+
You are an agent that helps manage issues in a JIRA instance.
45+
Be accurate in your responses based on the tool response. You can perform any formatting in the response that is appropriate or if asked by the user.
46+
If there is an error in the tool response, understand the error and try and see if you can fix the error and then and execute the tool again. For example if a variable or parameter is missing, try and see if you can find it in the request or user query or default it and then execute the tool again or check for other tools that could give you the details.
47+
If there are any math operations like count or max, min in the user request, call the tool to get the data and perform the math operations and then return the result in the response. For example for maximum, fetch the list and then do the math operation.
48+
""",
49+
tools=jira_tool.get_tools(),
50+
)
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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
from google.adk import Agent
17+
from google.adk.tools.tool_context import ToolContext
18+
from google.genai import types
19+
20+
21+
async def log_query(tool_context: ToolContext, query: str):
22+
"""Roll a die with the specified number of sides."""
23+
await tool_context.save_artifact('query', types.Part(text=query))
24+
25+
26+
root_agent = Agent(
27+
model='gemini-2.0-flash-exp',
28+
name='log_agent',
29+
description='Log user query.',
30+
instruction="""Always log the user query and reploy "kk, I've logged."
31+
""",
32+
tools=[log_query],
33+
generate_content_config=types.GenerateContentConfig(
34+
safety_settings=[
35+
types.SafetySetting( # avoid false alarm about rolling dice.
36+
category=types.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
37+
threshold=types.HarmBlockThreshold.OFF,
38+
),
39+
]
40+
),
41+
)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# OAuth Sample
2+
3+
## Introduction
4+
5+
This sample tests and demos the OAuth support in ADK via two tools:
6+
7+
* 1. bigquery_datasets_list:
8+
9+
List user's datasets.
10+
11+
* 2. bigquery_datasets_get:
12+
Get a dataset's details.
13+
14+
* 3. bigquery_datasets_insert:
15+
Create a new dataset.
16+
17+
* 4. bigquery_tables_list:
18+
List all tables in a dataset.
19+
20+
* 5. bigquery_tables_get:
21+
Get a table's details.
22+
23+
* 6. bigquery_tables_insert:
24+
Insert a new table into a dataset.
25+
26+
## How to use
27+
28+
* 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.
29+
Be sure to choose "web" as your client type.
30+
31+
* 2. Configure your .env file to add two variables:
32+
33+
* GOOGLE_CLIENT_ID={your client id}
34+
* GOOGLE_CLIENT_SECRET={your client secret}
35+
36+
Note: done't create a separate .env , instead put it to the same .env file that stores your Vertex AI or Dev ML credentials
37+
38+
* 3. Follow https://developers.google.com/identity/protocols/oauth2/web-server#creatingcred to add http://localhost/dev-ui to "Authorized redirect URIs".
39+
40+
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.
41+
42+
* 4. For 1st run, allow popup for localhost in Chrome.
43+
44+
## Sample prompt
45+
46+
* `Do I have any datasets in project sean-dev-agent ?`
47+
* `Do I have any tables under it ?`
48+
* `could you get me the details of this table ?`
49+
* `Can you help to create a new dataset in the same project? id : sean_test , location: us`
50+
* `could you show me the details of this new dataset ?`
51+
* `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.`
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: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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

Comments
 (0)
0