8000 chore: add toolbox sample agent · wongjoey/adk-python@f83504d · GitHub
[go: up one dir, main page]

Skip to content

Commit f83504d

Browse files
seanzhougooglecopybara-github
authored andcommitted
chore: add toolbox sample agent
PiperOrigin-RevId: 759746416
1 parent 11ca528 commit f83504d

File tree

5 files changed

+198
-0
lines changed

5 files changed

+198
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Toolbox Agent
2+
3+
This agent is utilizing [mcp toolbox for database](https://googleapis.github.io/genai-toolbox/getting-started/introduction/) to assist end user based on the informaton stored in database.
4+
Follow below steps to run this agent
5+
6+
# Install toolbox
7+
8+
* Run below command:
9+
10+
```bash
11+
export OS="linux/amd64" # one of linux/amd64, darwin/arm64, darwin/amd64, or windows/amd64
12+
curl -O https://storage.googleapis.com/genai-toolbox/v0.5.0/$OS/toolbox
13+
chmod +x toolbox
14+
```
15+
16+
# install SQLite
17+
18+
* install sqlite from https://sqlite.org/
19+
20+
21+
# Create DB (optional. The db instance is already attached in the folder)
22+
23+
* Run below command:
10000 24+
25+
```bash
26+
sqlite3 tool_box.db
27+
```
28+
29+
* Run below SQL:
30+
31+
```sql
32+
CREATE TABLE hotels(
33+
id INTEGER NOT NULL PRIMARY KEY,
34+
name VARCHAR NOT NULL,
35+
location VARCHAR NOT NULL,
36+
price_tier VARCHAR NOT NULL,
37+
checkin_date DATE NOT NULL,
38+
checkout_date DATE NOT NULL,
39+
booked BIT NOT NULL
40+
);
41+
42+
43+
INSERT INTO hotels(id, name, location, price_tier, checkin_date, checkout_date, booked)
44+
VALUES
45+
(1, 'Hilton Basel', 'Basel', 'Luxury', '2024-04-22', '2024-04-20', 0),
46+
(2, 'Marriott Zurich', 'Zurich', 'Upscale', '2024-04-14', '2024-04-21', 0),
47+
(3, 'Hyatt Regency Basel', 'Basel', 'Upper Upscale', '2024-04-02', '2024-04-20', 0),
48+
(4, 'Radisson Blu Lucerne', 'Lucerne', 'Midscale', '2024-04-24', '2024-04-05', 0),
49+
(5, 'Best Western Bern', 'Bern', 'Upper Midscale', '2024-04-23', '2024-04-01', 0),
50+
(6, 'InterContinental Geneva', 'Geneva', 'Luxury', '2024-04-23', '2024-04-28', 0),
51+
(7, 'Sheraton Zurich', 'Zurich', 'Upper Upscale', '2024-04-27', '2024-04-02', 0),
52+
(8, 'Holiday Inn Basel', 'Basel', 'Upper Midscale', '2024-04-24', '2024-04-09', 0),
53+
(9, 'Courtyard Zurich', 'Zurich', 'Upscale', '2024-04-03', '2024-04-13', 0),
54+
(10, 'Comfort Inn Bern', 'Bern', 'Midscale', '2024-04-04', '2024-04-16', 0);
55+
```
56+
57+
# create tools configurations
58+
59+
* Create a yaml file named "tools.yaml", see its contents in the agent folder.
60+
61+
# start toolbox server
62+
63+
* Run below commands in the agent folder
64+
65+
```bash
66+
toolbox --tools-file "tools.yaml"
67+
```
68+
69+
# start ADK web UI
70+
71+
# send user query
72+
73+
* query 1: what can you do for me ?
74+
* query 2: could you let know the information about "Hilton Basel" hotel ?
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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 google.adk.agents import Agent
16+
from google.adk.tools import ToolboxToolset
17+
18+
root_agent = Agent(
19+
model="gemini-2.0-flash",
20+
name="root_agent",
21+
instruction="You are a helpful assistant",
22+
# Add Toolbox tools to ADK agent
23+
tools=[
24+
ToolboxToolset(
25+
server_url="http://127.0.0.1:5000", toolset_name="my-toolset"
26+
)
27+
],
28+
)
Binary file not shown.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
sources:
15+
my-sqlite-db:
16+
kind: "sqlite"
17+
database: "tool_box.db"
18+
tools:
19+
search-hotels-by-name:
20+
kind: sqlite-sql
21+
source: my-sqlite-db
22+
description: Search for hotels based on name.
23+
parameters:
24+
- name: name
25+
type: string
26+
description: The name of the hotel.
27+
statement: SELECT * FROM hotels WHERE name LIKE '%' || $1 || '%';
28+
search-hotels-by-location:
29+
kind: sqlite-sql
30+
source: my-sqlite-db
31+
description: Search for hotels based on location.
32+
parameters:
33+
- name: location
34+
type: string
35+
description: The location of the hotel.
36+
statement: SELECT * FROM hotels WHERE location LIKE '%' || $1 || '%';
37+
book-hotel:
38+
kind: sqlite-sql
39+
source: my-sqlite-db
40+
description: >-
41+
Book a hotel by its ID. If the hotel is successfully booked, returns a NULL, raises an error if not.
42+
parameters:
43+
- name: hotel_id
44+
type: string
45+
description: The ID of the hotel to book.
46+
statement: UPDATE hotels SET booked = 1 WHERE id = $1;
47+
update-hotel:
48+
kind: sqlite-sql
49+
source: my-sqlite-db
50+
description: >-
51+
Update a hotel's check-in and check-out dates by its ID. Returns a message
52+
indicating whether the hotel was successfully updated or not.
53+
parameters:
54+
- name: hotel_id
55+
type: string
56+
description: The ID of the hotel to update.
57+
- name: checkin_date
58+
type: string
59+
description: The new check-in date of the hotel.
60+
- name: checkout_date
61+
type: string
62+
description: The new check-out date of the hotel.
63+
statement: >-
64+
UPDATE hotels SET checkin_date = CAST($2 as date), checkout_date = CAST($3
65+
as date) WHERE id = $1;
66+
cancel-hotel:
67+
kind: sqlite-sql
68+
source: my-sqlite-db
69+
description: Cancel a hotel by its ID.
70+
parameters:
71+
- name: hotel_id
72+
type: string
73+
description: The ID of the hotel to cancel.
74+
statement: UPDATE hotels SET booked = 0 WHERE id = $1;
75+
toolsets:
76+
my-toolset:
77+
- search-hotels-by-name
78+
- search-hotels-by-location
79+
- book-hotel
80+
- update-hotel
81+
- cancel-hotel

0 commit comments

Comments
 (0)
0