From c676a6c0df68b3199df44150b6feae5b168e2a51 Mon Sep 17 00:00:00 2001 From: Twisha Bansal Date: Wed, 15 Jan 2025 23:23:03 +0530 Subject: [PATCH 01/16] Added basic quickstart --- samples/quickstart.md | 252 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100644 samples/quickstart.md diff --git a/samples/quickstart.md b/samples/quickstart.md new file mode 100644 index 000000000..82d0b4165 --- /dev/null +++ b/samples/quickstart.md @@ -0,0 +1,252 @@ +# Toolbox Quickstart + +This guide would help you set up a basic agentic application using toolbox. + +## Step 1: Set up a Cloud SQL database + +1. [Create a Cloud SQL instance](https://cloud.google.com/sql/docs/postgres/connect-instance-local-computer#create-instance) +1. [Create a + database](https://cloud.google.com/sql/docs/postgres/connect-instance-local-computer#create-database) +1. [Create a database + user](https://cloud.google.com/sql/docs/postgres/connect-instance-local-computer#create_a_user) +1. [Set up a service + account](https://cloud.google.com/sql/docs/postgres/connect-instance-local-computer#set_up_a_service_account) + +## Step 2: Import data into the database + +Import the database using the command + +```bash +gcloud sql import sql {INSTANCE_NAME} gs://toolbox-quickstart/hotels.gz --database={DATABASE_NAME} +``` + +## Step 3: Create a tools config file + +Copy the following into an empty `tools.yaml` file. + +```yaml +sources: + my-cloud-sql-pg-source: + kind: cloud-sql-postgres + project: {GCP_PROJECT} + region: us-central1 + instance: {INSTANCE_NAME} + database: {DATABASE_NAME} + user: {DATABASE_USER} + password: {PASSWORD} +tools: + search-hotels: + kind: postgres-sql + source: my-cloud-sql-pg-source + description: Search for hotels based on location and name. + Returns a list of hotel dictionaries matching the search criteria. + parameters: + - name: location + type: string + description: The location of the hotel. + - name: name + type: string + description: The name of the hotel. + statement: SELECT * FROM hotels WHERE location ILIKE '%' || $1 || '%' AND + name ILIKE '%' || $2 || '%'; + book-hotel: + kind: postgres-sql + source: my-cloud-sql-pg-source + description: Book a hotel by its ID. Returns a message indicating + whether the hotel was successfully booked or not. + parameters: + - name: hotel_id + type: string + description: The ID of the hotel to book. + statement: UPDATE hotels SET booked = B'1' WHERE id = $1; + update-hotel: + kind: postgres-sql + source: my-cloud-sql-pg-source + 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: postgres-sql + source: my-cloud-sql-pg-source + 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 = B'0' WHERE id = $1; +``` + +Update the `project`, `database`, `instance`, `user` and `password` fields. + +> [!NOTE] +> If your instance belongs to a different region, update the `region` field. + +You can see that in the above file, we have four tools configured: +`search-hotels`, `book-hotel`, `update-hotel` and `cancel-hotel`. + +For each tool, we mention the tool name, description, +[kind](https://github.com/googleapis/genai-toolbox/blob/main/docs/sources/cloud-sql-pg.md#requirements) and +[source](./docs/sources/README.md). + +We also mention that various parameters that the tool takes along with their +[types](https://github.com/googleapis/genai-toolbox/blob/main/docs/sources/cloud-sql-pg.md#requirements) +and descriptions. +Each tool also has a corresponding statement, which is the SQL query to be executed +on tool invocation. + +## Step 4: Start a toolbox server locally + +1. Use the command to download the toolbox binary. + + ```bash + curl -O https://storage.googleapis.com/genai-toolbox/v0.0.5/linux/amd64/toolbox + ``` + + > [!TIP] + > Use the latest features provided by toolbox by downloading the latest + > toolbox version. Here, '0.0.5' represents the latest toolbox version currently. + +1. Provide binary execution permissions. + + ```bash + chmod +x toolbox + ``` + +1. Run the toolbox server. + + ```bash + ./toolbox --tools_file "tools.yaml" + ``` + +## Step 5: Start using Toolbox + +1. Install the toolbox_langchain_sdk package. + + ```bash + pip install toolbox_langchain_sdk + ``` + + > [!NOTE] + > Right now, the toolbox_langchain_sdk package is not available on pip. To + > use the sdk, download the source code from [git](https://github.com/googleapis/genai-toolbox/tree/main/sdks/langchain) and install it locally + > using the command: + > + > ```bash + > pip install . + > ``` + +1. Create an async runner function to help run async functions in python. + + ```python + import asyncio + + async def main(): + # All our code will be added here + pass + + asyncio.run(main()) + ``` + +1. Connect to the toolbox SDK + + ```python + from toolbox_langchain_sdk import ToolboxClient + + client = ToolboxClient("http://127.0.0.1:5000") + ``` + +1. Try out the `search-hotels` tool. + + ```python + search_tool = await client.load_tool('search-hotels') + response = await search_tool.ainvoke({"location": "Zurich", "name": ""}) + print(response) + ``` + +1. Load all tools. + + ```python + tools = await client.load_toolset() + ``` + +1. Install required modules + + ```bash + pip install langgraph langchain-google-vertexai + ``` + +1. Create a langraph [ReAct + agent](https://langchain-ai.github.io/langgraph/reference/prebuilt/#langgraph.prebuilt.chat_agent_executor.create_react_agent). + + + ```python + from langgraph.prebuilt import create_react_agent + from langchain_google_vertexai import ChatVertexAI + from langgraph.checkpoint.memory import MemorySaver + + model = ChatVertexAI(model_name="gemini-pro", project="my-project") # Change the GCP project here + agent = create_react_agent(model, tools, checkpointer=MemorySaver()) + ``` + +1. Define the initial prompt for a hotel assistant. + + ```python + prompt = """ + You're a helpful hotel assistant. You handle hotel searching, booking and + cancellations. When the user searches for a hotel, mention it's name, id, + location and price tier. Always mention hotel ids while performing any + searches. This is very important for any operations. For any bookings or + cancellations, please provide the appropriate confirmation. + """ + ``` + +1. Write the user queries that we want to run. + + ```python + queries = [ + "Find hotels in Basel with Basel in it's name.", + "Can you book the Hilton Basel for me?", + "Oh wait, this is too expensive. Please cancel it and book the Hyatt Regency instead.", + "My check in dates would be from April 10, 2024 to April 19, 2024.", + ] + ``` + +1. Explore your dataset + + 1. [Login into Cloud SQL + studio](https://cloud.google.com/sql/docs/mysql/manage-data-using-studio#explore-data) + 1. In the query editor, run the query to view the data. + + ```sql + SELECT * FROM hotels; + ``` + + 1. Observe that the `booked` column is `0` for all hotels. This means that + none of the hotels are booked yet. + +1. Run the queries and see the output! + + ```python + config = {"configurable": {"thread_id": "thread-1"}} + + for query in queries: + inputs = {"messages": [("user", prompt + query)]} + response = await agent.ainvoke(inputs, stream_mode="values", config=config) + print(response["messages"][-1].content) + ``` + + You can now see that the `booked` column for `Hyatt Regency Basel` has been + changed to `1`. This means that the hotel has been booked by the agent. Also + note that the checkin and checkout dates of the hotel have been updated to + `2024-04-10` and `2024-04-19` from `2024-04-02` and `2024-04-20`. \ No newline at end of file From 942744686f4d5865e8372ecbfb9e2592d7cf83bd Mon Sep 17 00:00:00 2001 From: Twisha Bansal Date: Wed, 15 Jan 2025 23:44:34 +0530 Subject: [PATCH 02/16] Cleanup --- samples/quickstart.md | 97 ++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 61 deletions(-) diff --git a/samples/quickstart.md b/samples/quickstart.md index 82d0b4165..a539a791d 100644 --- a/samples/quickstart.md +++ b/samples/quickstart.md @@ -4,25 +4,32 @@ This guide would help you set up a basic agentic application using toolbox. ## Step 1: Set up a Cloud SQL database -1. [Create a Cloud SQL instance](https://cloud.google.com/sql/docs/postgres/connect-instance-local-computer#create-instance) +1. [Create a Cloud SQL instance](https://cloud.google.com/sql/docs/postgres/connect-instance-local-computer#create-instance). 1. [Create a - database](https://cloud.google.com/sql/docs/postgres/connect-instance-local-computer#create-database) + database](https://cloud.google.com/sql/docs/postgres/connect-instance-local-computer#create-database). 1. [Create a database - user](https://cloud.google.com/sql/docs/postgres/connect-instance-local-computer#create_a_user) + user](https://cloud.google.com/sql/docs/postgres/connect-instance-local-computer#create_a_user). 1. [Set up a service - account](https://cloud.google.com/sql/docs/postgres/connect-instance-local-computer#set_up_a_service_account) + account](https://cloud.google.com/sql/docs/postgres/connect-instance-local-computer#set_up_a_service_account). ## Step 2: Import data into the database -Import the database using the command +Run the command. ```bash gcloud sql import sql {INSTANCE_NAME} gs://toolbox-quickstart/hotels.gz --database={DATABASE_NAME} ``` +### (Optional) Explore your data + +You can explore the data by logging into [Cloud SQL +Studio](https://cloud.google.com/sql/docs/mysql/manage-data-using-studio#explore-data) +and running SQL queries. + ## Step 3: Create a tools config file -Copy the following into an empty `tools.yaml` file. +Create a `tools.yaml` file with the following content, updating the `project`, +`database`, `instance`, `user`, and `password` fields: ```yaml sources: @@ -87,43 +94,32 @@ tools: statement: UPDATE hotels SET booked = B'0' WHERE id = $1; ``` -Update the `project`, `database`, `instance`, `user` and `password` fields. - > [!NOTE] > If your instance belongs to a different region, update the `region` field. -You can see that in the above file, we have four tools configured: +The config file defines four tools: `search-hotels`, `book-hotel`, `update-hotel` and `cancel-hotel`. -For each tool, we mention the tool name, description, -[kind](https://github.com/googleapis/genai-toolbox/blob/main/docs/sources/cloud-sql-pg.md#requirements) and -[source](./docs/sources/README.md). - -We also mention that various parameters that the tool takes along with their -[types](https://github.com/googleapis/genai-toolbox/blob/main/docs/sources/cloud-sql-pg.md#requirements) -and descriptions. -Each tool also has a corresponding statement, which is the SQL query to be executed -on tool invocation. +Each tool specifies its description, +[kind](https://github.com/googleapis/genai-toolbox/blob/main/docs/sources/cloud-sql-pg.md#requirements), +[source](./docs/sources/README.md), required parameters +and the corresponding SQL statements to execute upon tool invocation. ## Step 4: Start a toolbox server locally -1. Use the command to download the toolbox binary. +1. Download the latest toolbox binary. ```bash curl -O https://storage.googleapis.com/genai-toolbox/v0.0.5/linux/amd64/toolbox ``` - > [!TIP] - > Use the latest features provided by toolbox by downloading the latest - > toolbox version. Here, '0.0.5' represents the latest toolbox version currently. - 1. Provide binary execution permissions. ```bash chmod +x toolbox ``` -1. Run the toolbox server. +1. Run the Toolbox server. ```bash ./toolbox --tools_file "tools.yaml" @@ -131,7 +127,7 @@ on tool invocation. ## Step 5: Start using Toolbox -1. Install the toolbox_langchain_sdk package. +1. Install the `toolbox_langchain_sdk` package. ```bash pip install toolbox_langchain_sdk @@ -146,26 +142,20 @@ on tool invocation. > pip install . > ``` -1. Create an async runner function to help run async functions in python. +1. Create a python script to connect to the toolbox SDK. ```python import asyncio + from toolbox_langchain_sdk import ToolboxClient async def main(): - # All our code will be added here - pass + client = ToolboxClient("http://127.0.0.1:5000") + # All our code will be added here + pass asyncio.run(main()) ``` -1. Connect to the toolbox SDK - - ```python - from toolbox_langchain_sdk import ToolboxClient - - client = ToolboxClient("http://127.0.0.1:5000") - ``` - 1. Try out the `search-hotels` tool. ```python @@ -186,7 +176,7 @@ on tool invocation. pip install langgraph langchain-google-vertexai ``` -1. Create a langraph [ReAct +1. Create a LangGraph [ReAct agent](https://langchain-ai.github.io/langgraph/reference/prebuilt/#langgraph.prebuilt.chat_agent_executor.create_react_agent). @@ -199,7 +189,7 @@ on tool invocation. agent = create_react_agent(model, tools, checkpointer=MemorySaver()) ``` -1. Define the initial prompt for a hotel assistant. +1. Define the initial prompt and user queries. ```python prompt = """ @@ -209,11 +199,7 @@ on tool invocation. searches. This is very important for any operations. For any bookings or cancellations, please provide the appropriate confirmation. """ - ``` - -1. Write the user queries that we want to run. - - ```python + queries = [ "Find hotels in Basel with Basel in it's name.", "Can you book the Hilton Basel for me?", @@ -222,20 +208,7 @@ on tool invocation. ] ``` -1. Explore your dataset - - 1. [Login into Cloud SQL - studio](https://cloud.google.com/sql/docs/mysql/manage-data-using-studio#explore-data) - 1. In the query editor, run the query to view the data. - - ```sql - SELECT * FROM hotels; - ``` - - 1. Observe that the `booked` column is `0` for all hotels. This means that - none of the hotels are booked yet. - -1. Run the queries and see the output! +1. Run the queries and observe the output! ```python config = {"configurable": {"thread_id": "thread-1"}} @@ -246,7 +219,9 @@ on tool invocation. print(response["messages"][-1].content) ``` - You can now see that the `booked` column for `Hyatt Regency Basel` has been - changed to `1`. This means that the hotel has been booked by the agent. Also - note that the checkin and checkout dates of the hotel have been updated to - `2024-04-10` and `2024-04-19` from `2024-04-02` and `2024-04-20`. \ No newline at end of file + To verify the agent's actions, you can [examine the hotels table in Cloud + SQL Studio](#optional-explore-your-data). You should observe that the + `booked` column for the `Hyatt Regency Basel` has changed from `0` to `1`, + indicating that the hotel has been successfully booked. Additionally, the + `checkin_date` and `checkout_date` have been updated to `2024-04-10` and + `2024-04-19` from `2024-04-02` and `2024-04-20` respectively. \ No newline at end of file From 67ee18150eab69ee1882adf233eadc08b0ab589a Mon Sep 17 00:00:00 2001 From: Twisha Bansal Date: Wed, 15 Jan 2025 23:51:01 +0530 Subject: [PATCH 03/16] small change --- samples/quickstart.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/quickstart.md b/samples/quickstart.md index a539a791d..464516b15 100644 --- a/samples/quickstart.md +++ b/samples/quickstart.md @@ -170,7 +170,7 @@ and the corresponding SQL statements to execute upon tool invocation. tools = await client.load_toolset() ``` -1. Install required modules +1. Install required modules. ```bash pip install langgraph langchain-google-vertexai From d8151023f1f784fc3ecf954e016188d796e155eb Mon Sep 17 00:00:00 2001 From: Twisha Bansal Date: Wed, 15 Jan 2025 23:55:38 +0530 Subject: [PATCH 04/16] small change --- samples/quickstart.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/quickstart.md b/samples/quickstart.md index 464516b15..721f4c6ee 100644 --- a/samples/quickstart.md +++ b/samples/quickstart.md @@ -125,7 +125,7 @@ and the corresponding SQL statements to execute upon tool invocation. ./toolbox --tools_file "tools.yaml" ``` -## Step 5: Start using Toolbox +## Step 5: Start building using Toolbox 1. Install the `toolbox_langchain_sdk` package. From 872fe0fe2e1b85b51cce951afec4aa1b2b6f9b50 Mon Sep 17 00:00:00 2001 From: Twisha Bansal Date: Thu, 16 Jan 2025 14:21:15 +0530 Subject: [PATCH 05/16] 1. move repo to different file and cleanup 2. configure hugo --- {samples => docs/en/getting-started}/quickstart.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) rename {samples => docs/en/getting-started}/quickstart.md (96%) diff --git a/samples/quickstart.md b/docs/en/getting-started/quickstart.md similarity index 96% rename from samples/quickstart.md rename to docs/en/getting-started/quickstart.md index 721f4c6ee..fee24e30e 100644 --- a/samples/quickstart.md +++ b/docs/en/getting-started/quickstart.md @@ -1,6 +1,10 @@ -# Toolbox Quickstart +--- +title: "Toolbox Quickstart" +type: docs +weight: 1 +description: This guide would help you set up a basic agentic application using toolbox. -This guide would help you set up a basic agentic application using toolbox. +--- ## Step 1: Set up a Cloud SQL database @@ -94,8 +98,7 @@ tools: statement: UPDATE hotels SET booked = B'0' WHERE id = $1; ``` -> [!NOTE] -> If your instance belongs to a different region, update the `region` field. +> **_NOTE:_** If your instance belongs to a different region, update the `region` field. The config file defines four tools: `search-hotels`, `book-hotel`, `update-hotel` and `cancel-hotel`. @@ -133,7 +136,7 @@ and the corresponding SQL statements to execute upon tool invocation. pip install toolbox_langchain_sdk ``` - > [!NOTE] + > **_NOTE:_** > Right now, the toolbox_langchain_sdk package is not available on pip. To > use the sdk, download the source code from [git](https://github.com/googleapis/genai-toolbox/tree/main/sdks/langchain) and install it locally > using the command: From e22cc457c52f9418497b3764d21e2a01d950105c Mon Sep 17 00:00:00 2001 From: Twisha Bansal Date: Thu, 16 Jan 2025 14:33:18 +0530 Subject: [PATCH 06/16] use absolute paths for hugo --- docs/en/getting-started/quickstart.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/en/getting-started/quickstart.md b/docs/en/getting-started/quickstart.md index fee24e30e..b0d1e855a 100644 --- a/docs/en/getting-started/quickstart.md +++ b/docs/en/getting-started/quickstart.md @@ -105,7 +105,7 @@ The config file defines four tools: Each tool specifies its description, [kind](https://github.com/googleapis/genai-toolbox/blob/main/docs/sources/cloud-sql-pg.md#requirements), -[source](./docs/sources/README.md), required parameters +[source](https://github.com/googleapis/genai-toolbox/blob/main/docs/sources/README.md), required parameters and the corresponding SQL statements to execute upon tool invocation. ## Step 4: Start a toolbox server locally @@ -116,6 +116,8 @@ and the corresponding SQL statements to execute upon tool invocation. curl -O https://storage.googleapis.com/genai-toolbox/v0.0.5/linux/amd64/toolbox ``` + > **_NOTE:_** Use the [correct binary](https://github.com/googleapis/genai-toolbox/releases) corresponding to your OS and CPU architecture. + 1. Provide binary execution permissions. ```bash From 7e033deb0bbfd500361de26147bf894cfa4b5fd9 Mon Sep 17 00:00:00 2001 From: Twisha Bansal Date: Thu, 16 Jan 2025 14:34:43 +0530 Subject: [PATCH 07/16] fix link --- docs/en/getting-started/quickstart.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/getting-started/quickstart.md b/docs/en/getting-started/quickstart.md index b0d1e855a..89e4a2ceb 100644 --- a/docs/en/getting-started/quickstart.md +++ b/docs/en/getting-started/quickstart.md @@ -104,7 +104,7 @@ The config file defines four tools: `search-hotels`, `book-hotel`, `update-hotel` and `cancel-hotel`. Each tool specifies its description, -[kind](https://github.com/googleapis/genai-toolbox/blob/main/docs/sources/cloud-sql-pg.md#requirements), +[kind](https://github.com/googleapis/genai-toolbox/tree/main/docs/sources#kinds-of-sources), [source](https://github.com/googleapis/genai-toolbox/blob/main/docs/sources/README.md), required parameters and the corresponding SQL statements to execute upon tool invocation. From 68c91c450e78b3d1150660cb40d72264f8dae124 Mon Sep 17 00:00:00 2001 From: Twisha Bansal Date: Fri, 17 Jan 2025 12:08:21 +0530 Subject: [PATCH 08/16] use a local db --- docs/en/getting-started/quickstart.md | 101 ++++++++++++++++---------- 1 file changed, 62 insertions(+), 39 deletions(-) diff --git a/docs/en/getting-started/quickstart.md b/docs/en/getting-started/quickstart.md index 89e4a2ceb..2ff7d9448 100644 --- a/docs/en/getting-started/quickstart.md +++ b/docs/en/getting-started/quickstart.md @@ -6,49 +6,73 @@ description: This guide would help you set up a basic agentic application using --- -## Step 1: Set up a Cloud SQL database +## Step 1: Set up a database -1. [Create a Cloud SQL instance](https://cloud.google.com/sql/docs/postgres/connect-instance-local-computer#create-instance). -1. [Create a - database](https://cloud.google.com/sql/docs/postgres/connect-instance-local-computer#create-database). -1. [Create a database - user](https://cloud.google.com/sql/docs/postgres/connect-instance-local-computer#create_a_user). -1. [Set up a service - account](https://cloud.google.com/sql/docs/postgres/connect-instance-local-computer#set_up_a_service_account). +[Install postgres and configure a +database](https://neon.tech/postgresql/postgresql-getting-started) for your +system. -## Step 2: Import data into the database +This process creates a database `postgres` with superuser `postgres`. -Run the command. +## Step 2: Import data into the database -```bash -gcloud sql import sql {INSTANCE_NAME} gs://toolbox-quickstart/hotels.gz --database={DATABASE_NAME} -``` +1. Connect to the database using command line. -### (Optional) Explore your data + ```bash + psql -U postgres -d postgres + ``` -You can explore the data by logging into [Cloud SQL -Studio](https://cloud.google.com/sql/docs/mysql/manage-data-using-studio#explore-data) -and running SQL queries. + Here, the first postgres denotes the user and the second one denotes the + database name. + +1. Create a table using the following command. + + ```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 + ); + ``` + + +1. Insert data into the table. + + ```sql + 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', B'0'), + (2, 'Marriott Zurich', 'Zurich', 'Upscale', '2024-04-14', '2024-04-21', B'0'), + (3, 'Hyatt Regency Basel', 'Basel', 'Upper Upscale', '2024-04-02', '2024-04-20', B'0'), + (4, 'Radisson Blu Lucerne', 'Lucerne', 'Midscale', '2024-04-24', '2024-04-05', B'0'), + (5, 'Best Western Bern', 'Bern', 'Upper Midscale', '2024-04-23', '2024-04-01', B'0'), + (6, 'InterContinental Geneva', 'Geneva', 'Luxury', '2024-04-23', '2024-04-28', B'0'), + (7, 'Sheraton Zurich', 'Zurich', 'Upper Upscale', '2024-04-27', '2024-04-02', B'0'), + (8, 'Holiday Inn Basel', 'Basel', 'Upper Midscale', '2024-04-24', '2024-04-09', B'0'), + (9, 'Courtyard Zurich', 'Zurich', 'Upscale', '2024-04-03', '2024-04-13', B'0'), + (10, 'Comfort Inn Bern', 'Bern', 'Midscale', '2024-04-04', '2024-04-16', B'0'); + ``` ## Step 3: Create a tools config file -Create a `tools.yaml` file with the following content, updating the `project`, -`database`, `instance`, `user`, and `password` fields: +Create a `tools.yaml` file with the following content, updating the `password` field: ```yaml sources: - my-cloud-sql-pg-source: - kind: cloud-sql-postgres - project: {GCP_PROJECT} - region: us-central1 - instance: {INSTANCE_NAME} - database: {DATABASE_NAME} - user: {DATABASE_USER} - password: {PASSWORD} + my-pg-source: + kind: postgres + host: 127.0.0.1 + port: 5432 + database: postgres + user: postgres + password: {password} tools: search-hotels: kind: postgres-sql - source: my-cloud-sql-pg-source + source: my-pg-source description: Search for hotels based on location and name. Returns a list of hotel dictionaries matching the search criteria. parameters: @@ -62,7 +86,7 @@ tools: name ILIKE '%' || $2 || '%'; book-hotel: kind: postgres-sql - source: my-cloud-sql-pg-source + source: my-pg-source description: Book a hotel by its ID. Returns a message indicating whether the hotel was successfully booked or not. parameters: @@ -72,7 +96,7 @@ tools: statement: UPDATE hotels SET booked = B'1' WHERE id = $1; update-hotel: kind: postgres-sql - source: my-cloud-sql-pg-source + source: my-pg-source 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: @@ -89,7 +113,7 @@ tools: checkout_date = CAST($3 as date) WHERE id = $1; cancel-hotel: kind: postgres-sql - source: my-cloud-sql-pg-source + source: my-pg-source description: Cancel a hotel by its ID. parameters: - name: hotel_id @@ -98,8 +122,6 @@ tools: statement: UPDATE hotels SET booked = B'0' WHERE id = $1; ``` -> **_NOTE:_** If your instance belongs to a different region, update the `region` field. - The config file defines four tools: `search-hotels`, `book-hotel`, `update-hotel` and `cancel-hotel`. @@ -198,12 +220,13 @@ and the corresponding SQL statements to execute upon tool invocation. ```python prompt = """ - You're a helpful hotel assistant. You handle hotel searching, booking and - cancellations. When the user searches for a hotel, mention it's name, id, - location and price tier. Always mention hotel ids while performing any - searches. This is very important for any operations. For any bookings or - cancellations, please provide the appropriate confirmation. - """ + You're a helpful hotel assistant. You handle hotel searching, booking and + cancellations. When the user searches for a hotel, mention it's name, id, + location and price tier. Always mention hotel ids while performing any + searches. This is very important for any operations. For any bookings or + cancellations, please provide the appropriate confirmation. + Don't ask for confirmations from the user. + """ queries = [ "Find hotels in Basel with Basel in it's name.", From 4b23c55e732b4e0cc1279e4ef0aa81d3f3a69874 Mon Sep 17 00:00:00 2001 From: Twisha Bansal Date: Fri, 17 Jan 2025 12:12:47 +0530 Subject: [PATCH 09/16] lint and fix para --- docs/en/getting-started/quickstart.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/docs/en/getting-started/quickstart.md b/docs/en/getting-started/quickstart.md index 2ff7d9448..a3d79eb32 100644 --- a/docs/en/getting-started/quickstart.md +++ b/docs/en/getting-started/quickstart.md @@ -160,7 +160,7 @@ and the corresponding SQL statements to execute upon tool invocation. pip install toolbox_langchain_sdk ``` - > **_NOTE:_** + > **_NOTE:_** > Right now, the toolbox_langchain_sdk package is not available on pip. To > use the sdk, download the source code from [git](https://github.com/googleapis/genai-toolbox/tree/main/sdks/langchain) and install it locally > using the command: @@ -206,7 +206,6 @@ and the corresponding SQL statements to execute upon tool invocation. 1. Create a LangGraph [ReAct agent](https://langchain-ai.github.io/langgraph/reference/prebuilt/#langgraph.prebuilt.chat_agent_executor.create_react_agent). - ```python from langgraph.prebuilt import create_react_agent from langchain_google_vertexai import ChatVertexAI @@ -247,9 +246,9 @@ and the corresponding SQL statements to execute upon tool invocation. print(response["messages"][-1].content) ``` - To verify the agent's actions, you can [examine the hotels table in Cloud - SQL Studio](#optional-explore-your-data). You should observe that the - `booked` column for the `Hyatt Regency Basel` has changed from `0` to `1`, - indicating that the hotel has been successfully booked. Additionally, the - `checkin_date` and `checkout_date` have been updated to `2024-04-10` and - `2024-04-19` from `2024-04-02` and `2024-04-20` respectively. \ No newline at end of file + To verify the agent's actions, you can examine the hotels table. You should + observe that the `booked` column for the `Hyatt Regency Basel` has changed + from `0` to `1`, indicating that the hotel has been successfully booked. + Additionally, the `checkin_date` and `checkout_date` have been updated to + `2024-04-10` and `2024-04-19` from `2024-04-02` and `2024-04-20` + respectively. From 5152af2dd708a04d36af9bb1aa2c4570270ae3c9 Mon Sep 17 00:00:00 2001 From: Twisha Bansal Date: Fri, 17 Jan 2025 23:10:00 +0530 Subject: [PATCH 10/16] change title to local quickstart --- docs/en/getting-started/quickstart.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/getting-started/quickstart.md b/docs/en/getting-started/quickstart.md index a3d79eb32..fe5d08d0a 100644 --- a/docs/en/getting-started/quickstart.md +++ b/docs/en/getting-started/quickstart.md @@ -1,5 +1,5 @@ --- -title: "Toolbox Quickstart" +title: "Local Quickstart" type: docs weight: 1 description: This guide would help you set up a basic agentic application using toolbox. From 55862886cdff7170b743217cee44f80f8ef1fa44 Mon Sep 17 00:00:00 2001 From: Twisha Bansal Date: Fri, 17 Jan 2025 23:14:02 +0530 Subject: [PATCH 11/16] move up module installation --- docs/en/getting-started/quickstart.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/en/getting-started/quickstart.md b/docs/en/getting-started/quickstart.md index fe5d08d0a..dad195084 100644 --- a/docs/en/getting-started/quickstart.md +++ b/docs/en/getting-started/quickstart.md @@ -169,6 +169,12 @@ and the corresponding SQL statements to execute upon tool invocation. > pip install . > ``` +1. Install other required modules. + + ```bash + pip install langgraph langchain-google-vertexai + ``` + 1. Create a python script to connect to the toolbox SDK. ```python @@ -197,12 +203,6 @@ and the corresponding SQL statements to execute upon tool invocation. tools = await client.load_toolset() ``` -1. Install required modules. - - ```bash - pip install langgraph langchain-google-vertexai - ``` - 1. Create a LangGraph [ReAct agent](https://langchain-ai.github.io/langgraph/reference/prebuilt/#langgraph.prebuilt.chat_agent_executor.create_react_agent). From da1fd3c703817220bf19d2aca113923209668570 Mon Sep 17 00:00:00 2001 From: Twisha Bansal Date: Fri, 17 Jan 2025 23:24:05 +0530 Subject: [PATCH 12/16] remove comment: not useful --- docs/en/getting-started/quickstart.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/en/getting-started/quickstart.md b/docs/en/getting-started/quickstart.md index dad195084..9ca1fe5c7 100644 --- a/docs/en/getting-started/quickstart.md +++ b/docs/en/getting-started/quickstart.md @@ -38,7 +38,6 @@ This process creates a database `postgres` with superuser `postgres`. booked BIT NOT NULL ); ``` - 1. Insert data into the table. From 4ed8b2d1f6ab4467c706b95c5d580978418e8709 Mon Sep 17 00:00:00 2001 From: Twisha Bansal Date: Fri, 17 Jan 2025 23:48:13 +0530 Subject: [PATCH 13/16] created a new db and user for postgres --- docs/en/getting-started/quickstart.md | 29 ++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/docs/en/getting-started/quickstart.md b/docs/en/getting-started/quickstart.md index 9ca1fe5c7..793d8c2f6 100644 --- a/docs/en/getting-started/quickstart.md +++ b/docs/en/getting-started/quickstart.md @@ -16,14 +16,28 @@ This process creates a database `postgres` with superuser `postgres`. ## Step 2: Import data into the database -1. Connect to the database using command line. +1. Connect to postgres using command line. ```bash - psql -U postgres -d postgres + psql -U postgres ``` - Here, the first postgres denotes the user and the second one denotes the - database name. + Here, `postgres` denotes the default postgres superuser. + +1. Create a new database and a new user. + + ```bash + CREATE USER test_user WITH PASSWORD '{password}'; + CREATE DATABASE test_db; + GRANT ALL PRIVILEGES ON DATABASE test_db to test_user; + ALTER DATABASE test_db OWNER TO test_user; + ``` + +1. Connect to your database with your new user. + + ```bash + psql -U test_user -d test_db + ``` 1. Create a table using the following command. @@ -65,8 +79,8 @@ sources: kind: postgres host: 127.0.0.1 port: 5432 - database: postgres - user: postgres + database: test_db + user: test_user password: {password} tools: search-hotels: @@ -222,7 +236,8 @@ and the corresponding SQL statements to execute upon tool invocation. cancellations. When the user searches for a hotel, mention it's name, id, location and price tier. Always mention hotel ids while performing any searches. This is very important for any operations. For any bookings or - cancellations, please provide the appropriate confirmation. + cancellations, please provide the appropriate confirmation. Be sure to update + checkin or checkout dates if mentioned by the user. Don't ask for confirmations from the user. """ From 13445d16feea2760ba95d8f5eb133695be088862 Mon Sep 17 00:00:00 2001 From: Twisha Bansal Date: Fri, 17 Jan 2025 23:50:31 +0530 Subject: [PATCH 14/16] add connection quitting with superuser --- docs/en/getting-started/quickstart.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/en/getting-started/quickstart.md b/docs/en/getting-started/quickstart.md index 793d8c2f6..158ce4021 100644 --- a/docs/en/getting-started/quickstart.md +++ b/docs/en/getting-started/quickstart.md @@ -33,6 +33,12 @@ This process creates a database `postgres` with superuser `postgres`. ALTER DATABASE test_db OWNER TO test_user; ``` +1. Quit the db connection with the superuser. + + ```bash + \q + ``` + 1. Connect to your database with your new user. ```bash From 2521da03f8104e37081b13862e699cc82be6e482 Mon Sep 17 00:00:00 2001 From: Twisha Bansal Date: Fri, 17 Jan 2025 23:57:02 +0530 Subject: [PATCH 15/16] rearrange steps --- docs/en/getting-started/quickstart.md | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/docs/en/getting-started/quickstart.md b/docs/en/getting-started/quickstart.md index 158ce4021..3c207e867 100644 --- a/docs/en/getting-started/quickstart.md +++ b/docs/en/getting-started/quickstart.md @@ -8,13 +8,9 @@ description: This guide would help you set up a basic agentic application using ## Step 1: Set up a database -[Install postgres and configure a +1. [Install postgres and configure a database](https://neon.tech/postgresql/postgresql-getting-started) for your -system. - -This process creates a database `postgres` with superuser `postgres`. - -## Step 2: Import data into the database +system. This process creates a database `postgres` with superuser `postgres`. 1. Connect to postgres using command line. @@ -27,7 +23,7 @@ This process creates a database `postgres` with superuser `postgres`. 1. Create a new database and a new user. ```bash - CREATE USER test_user WITH PASSWORD '{password}'; + CREATE USER test_user WITH PASSWORD 'test-password'; CREATE DATABASE test_db; GRANT ALL PRIVILEGES ON DATABASE test_db to test_user; ALTER DATABASE test_db OWNER TO test_user; @@ -39,6 +35,8 @@ This process creates a database `postgres` with superuser `postgres`. \q ``` +## Step 2: Import data into the database + 1. Connect to your database with your new user. ```bash @@ -87,7 +85,7 @@ sources: port: 5432 database: test_db user: test_user - password: {password} + password: test-password tools: search-hotels: kind: postgres-sql From 4067a030a7151ad41a7ebf67c153ab4a772691c9 Mon Sep 17 00:00:00 2001 From: Twisha Bansal Date: Sat, 18 Jan 2025 00:04:21 +0530 Subject: [PATCH 16/16] split search tool into two: search by name and search by location --- docs/en/getting-started/quickstart.md | 30 +++++++++++++++------------ 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/docs/en/getting-started/quickstart.md b/docs/en/getting-started/quickstart.md index 3c207e867..0627acad8 100644 --- a/docs/en/getting-started/quickstart.md +++ b/docs/en/getting-started/quickstart.md @@ -87,20 +87,24 @@ sources: user: test_user password: test-password tools: - search-hotels: + search-hotels-by-name: kind: postgres-sql source: my-pg-source - description: Search for hotels based on location and name. - Returns a list of hotel dictionaries matching the search criteria. + description: Search for hotels based on name. parameters: - - name: location - type: string - description: The location of the hotel. - name: name type: string description: The name of the hotel. - statement: SELECT * FROM hotels WHERE location ILIKE '%' || $1 || '%' AND - name ILIKE '%' || $2 || '%'; + statement: SELECT * FROM hotels WHERE name ILIKE '%' || $1 || '%'; + search-hotels-by-location: + kind: postgres-sql + source: my-pg-source + description: Search for hotels based on location. + parameters: + - name: location + type: string + description: The location of the hotel. + statement: SELECT * FROM hotels WHERE location ILIKE '%' || $1 || '%'; book-hotel: kind: postgres-sql source: my-pg-source @@ -139,8 +143,8 @@ tools: statement: UPDATE hotels SET booked = B'0' WHERE id = $1; ``` -The config file defines four tools: -`search-hotels`, `book-hotel`, `update-hotel` and `cancel-hotel`. +The config file defines five tools: +`search-hotels-by-name`, `search-hotels-by-location`, `book-hotel`, `update-hotel` and `cancel-hotel`. Each tool specifies its description, [kind](https://github.com/googleapis/genai-toolbox/tree/main/docs/sources#kinds-of-sources), @@ -206,11 +210,11 @@ and the corresponding SQL statements to execute upon tool invocation. asyncio.run(main()) ``` -1. Try out the `search-hotels` tool. +1. Try out the `search-hotels-by-name` tool. ```python - search_tool = await client.load_tool('search-hotels') - response = await search_tool.ainvoke({"location": "Zurich", "name": ""}) + search_tool = await client.load_tool('search-hotels-by-name') + response = await search_tool.ainvoke({"name": "Hilton"}) print(response) ```