mirror of
https://github.com/EvolutionAPI/adk-python.git
synced 2025-07-14 01:41:25 -06:00
chore: add toolbox sample agent
PiperOrigin-RevId: 759746416
This commit is contained in:
parent
11ca528090
commit
f83504dffb
74
contributing/samples/toolbox_agent/README.md
Normal file
74
contributing/samples/toolbox_agent/README.md
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
# Toolbox Agent
|
||||||
|
|
||||||
|
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.
|
||||||
|
Follow below steps to run this agent
|
||||||
|
|
||||||
|
# Install toolbox
|
||||||
|
|
||||||
|
* Run below command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export OS="linux/amd64" # one of linux/amd64, darwin/arm64, darwin/amd64, or windows/amd64
|
||||||
|
curl -O https://storage.googleapis.com/genai-toolbox/v0.5.0/$OS/toolbox
|
||||||
|
chmod +x toolbox
|
||||||
|
```
|
||||||
|
|
||||||
|
# install SQLite
|
||||||
|
|
||||||
|
* install sqlite from https://sqlite.org/
|
||||||
|
|
||||||
|
|
||||||
|
# Create DB (optional. The db instance is already attached in the folder)
|
||||||
|
|
||||||
|
* Run below command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sqlite3 tool_box.db
|
||||||
|
```
|
||||||
|
|
||||||
|
* Run below SQL:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
CREATE TABLE hotels(
|
||||||
|
id INTEGER NOT NULL PRIMARY KEY,
|
||||||
|
name VARCHAR NOT NULL,
|
||||||
|
location VARCHAR NOT NULL,
|
||||||
|
price_tier VARCHAR NOT NULL,
|
||||||
|
checkin_date DATE NOT NULL,
|
||||||
|
checkout_date DATE NOT NULL,
|
||||||
|
booked BIT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
INSERT INTO hotels(id, name, location, price_tier, checkin_date, checkout_date, booked)
|
||||||
|
VALUES
|
||||||
|
(1, 'Hilton Basel', 'Basel', 'Luxury', '2024-04-22', '2024-04-20', 0),
|
||||||
|
(2, 'Marriott Zurich', 'Zurich', 'Upscale', '2024-04-14', '2024-04-21', 0),
|
||||||
|
(3, 'Hyatt Regency Basel', 'Basel', 'Upper Upscale', '2024-04-02', '2024-04-20', 0),
|
||||||
|
(4, 'Radisson Blu Lucerne', 'Lucerne', 'Midscale', '2024-04-24', '2024-04-05', 0),
|
||||||
|
(5, 'Best Western Bern', 'Bern', 'Upper Midscale', '2024-04-23', '2024-04-01', 0),
|
||||||
|
(6, 'InterContinental Geneva', 'Geneva', 'Luxury', '2024-04-23', '2024-04-28', 0),
|
||||||
|
(7, 'Sheraton Zurich', 'Zurich', 'Upper Upscale', '2024-04-27', '2024-04-02', 0),
|
||||||
|
(8, 'Holiday Inn Basel', 'Basel', 'Upper Midscale', '2024-04-24', '2024-04-09', 0),
|
||||||
|
(9, 'Courtyard Zurich', 'Zurich', 'Upscale', '2024-04-03', '2024-04-13', 0),
|
||||||
|
(10, 'Comfort Inn Bern', 'Bern', 'Midscale', '2024-04-04', '2024-04-16', 0);
|
||||||
|
```
|
||||||
|
|
||||||
|
# create tools configurations
|
||||||
|
|
||||||
|
* Create a yaml file named "tools.yaml", see its contents in the agent folder.
|
||||||
|
|
||||||
|
# start toolbox server
|
||||||
|
|
||||||
|
* Run below commands in the agent folder
|
||||||
|
|
||||||
|
```bash
|
||||||
|
toolbox --tools-file "tools.yaml"
|
||||||
|
```
|
||||||
|
|
||||||
|
# start ADK web UI
|
||||||
|
|
||||||
|
# send user query
|
||||||
|
|
||||||
|
* query 1: what can you do for me ?
|
||||||
|
* query 2: could you let know the information about "Hilton Basel" hotel ?
|
15
contributing/samples/toolbox_agent/__init__.py
Normal file
15
contributing/samples/toolbox_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
|
28
contributing/samples/toolbox_agent/agent.py
Normal file
28
contributing/samples/toolbox_agent/agent.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# 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 google.adk.agents import Agent
|
||||||
|
from google.adk.tools import ToolboxToolset
|
||||||
|
|
||||||
|
root_agent = Agent(
|
||||||
|
model="gemini-2.0-flash",
|
||||||
|
name="root_agent",
|
||||||
|
instruction="You are a helpful assistant",
|
||||||
|
# Add Toolbox tools to ADK agent
|
||||||
|
tools=[
|
||||||
|
ToolboxToolset(
|
||||||
|
server_url="http://127.0.0.1:5000", toolset_name="my-toolset"
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
BIN
contributing/samples/toolbox_agent/tool_box.db
Normal file
BIN
contributing/samples/toolbox_agent/tool_box.db
Normal file
Binary file not shown.
81
contributing/samples/toolbox_agent/tools.yaml
Normal file
81
contributing/samples/toolbox_agent/tools.yaml
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
# 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.
|
||||||
|
sources:
|
||||||
|
my-sqlite-db:
|
||||||
|
kind: "sqlite"
|
||||||
|
database: "tool_box.db"
|
||||||
|
tools:
|
||||||
|
search-hotels-by-name:
|
||||||
|
kind: sqlite-sql
|
||||||
|
source: my-sqlite-db
|
||||||
|
description: Search for hotels based on name.
|
||||||
|
parameters:
|
||||||
|
- name: name
|
||||||
|
type: string
|
||||||
|
description: The name of the hotel.
|
||||||
|
statement: SELECT * FROM hotels WHERE name LIKE '%' || $1 || '%';
|
||||||
|
search-hotels-by-location:
|
||||||
|
kind: sqlite-sql
|
||||||
|
source: my-sqlite-db
|
||||||
|
description: Search for hotels based on location.
|
||||||
|
parameters:
|
||||||
|
- name: location
|
||||||
|
type: string
|
||||||
|
description: The location of the hotel.
|
||||||
|
statement: SELECT * FROM hotels WHERE location LIKE '%' || $1 || '%';
|
||||||
|
book-hotel:
|
||||||
|
kind: sqlite-sql
|
||||||
|
source: my-sqlite-db
|
||||||
|
description: >-
|
||||||
|
Book a hotel by its ID. If the hotel is successfully booked, returns a NULL, raises an error if not.
|
||||||
|
parameters:
|
||||||
|
- name: hotel_id
|
||||||
|
type: string
|
||||||
|
description: The ID of the hotel to book.
|
||||||
|
statement: UPDATE hotels SET booked = 1 WHERE id = $1;
|
||||||
|
update-hotel:
|
||||||
|
kind: sqlite-sql
|
||||||
|
source: my-sqlite-db
|
||||||
|
description: >-
|
||||||
|
Update a hotel's check-in and check-out dates by its ID. Returns a message
|
||||||
|
indicating whether the hotel was successfully updated or not.
|
||||||
|
parameters:
|
||||||
|
- name: hotel_id
|
||||||
|
type: string
|
||||||
|
description: The ID of the hotel to update.
|
||||||
|
- name: checkin_date
|
||||||
|
type: string
|
||||||
|
description: The new check-in date of the hotel.
|
||||||
|
- name: checkout_date
|
||||||
|
type: string
|
||||||
|
description: The new check-out date of the hotel.
|
||||||
|
statement: >-
|
||||||
|
UPDATE hotels SET checkin_date = CAST($2 as date), checkout_date = CAST($3
|
||||||
|
as date) WHERE id = $1;
|
||||||
|
cancel-hotel:
|
||||||
|
kind: sqlite-sql
|
||||||
|
source: my-sqlite-db
|
||||||
|
description: Cancel a hotel by its ID.
|
||||||
|
parameters:
|
||||||
|
- name: hotel_id
|
||||||
|
type: string
|
||||||
|
description: The ID of the hotel to cancel.
|
||||||
|
statement: UPDATE hotels SET booked = 0 WHERE id = $1;
|
||||||
|
toolsets:
|
||||||
|
my-toolset:
|
||||||
|
- search-hotels-by-name
|
||||||
|
- search-hotels-by-location
|
||||||
|
- book-hotel
|
||||||
|
- update-hotel
|
||||||
|
- cancel-hotel
|
Loading…
Reference in New Issue
Block a user