1. Before you begin
This self-paced codelab will guide you through building AI Agents with Google Cloud's Vertex AI Agent Builder. Each step will highlight a specific Agent Builder feature and explain its purpose.
Prerequisites
- A basic understanding of Generative AI on Google Cloud
- A basic understanding of AI Agent Concepts
What you'll learn
- How to create a simple AI Agent using Vertex AI Agent Builder
- How to ground the created agent by attaching a datastore
What you'll need
- A curious mind
- A working computer and reliable wifi
- A Google Cloud project with billing attached
2. Designing Your First AI Agent
Now you're ready to create your own AI agent. But before diving into development, it's essential to establish a clear vision for your agent. Ask yourself these key questions:
- What problem will it solve? Will it automate tasks, provide information, offer entertainment, or facilitate creative exploration?
- What are its primary functions? Will it execute tasks or delegate tasks? Will it generate text, or generate a combination of different media?
- What are its limitations? Will it be able to do everything autonomously?
- What personality or persona should it have? Will it be formal, informal, humorous, helpful, or informative?
- What are the success metrics? How will you measure the agent's effectiveness?
To speed up the process, here are the answers to those questions for the travel agent you will be creating today:
- What problem will it solve?
- Planning a trip can be time-consuming and overwhelming. This travel agent will help users discover destinations, plan itineraries, book flights and accommodations.
- What are its primary functions?
- The agent should be able to
- answer questions about destinations, such as visa requirements
- plan itineraries that work for users' schedules and objectives
- book flights and accommodations
- What are its limitations?
- The agent might not be able to answer complicated queries by default
- The agent won't be able to generate visual images
- The agent's knowledge will limited by the underlying model
- What personality or persona should it have?
- This agent should be knowledgeable, helpful, and enthusiastic about travel. It should be able to communicate information clearly and concisely.
- What are the success metrics?
- Success for this agent could be measured by how satisfied users are with its recommendations (exploring, planning, booking)
3. Building an AI Agent with Vertex AI Agent Builder
With Vertex AI Agent Builder, AI Agents can be created in just a few steps.
Step 1:
- Head over to Vertex AI Agent Builder.
- You should see the welcome page.
- Click on the CONTINUE AND ACTIVATE THE API button.
Step 2:
- You will be redirected to the App Creation page.
- Click on the CREATE A NEW APP button.
Step 3:
- Select Agent on the next page
Step 4:
- Pick a Display Name (e.g. Travel Buddy)
- Select global as Region
- Click on the AGREE & CREATE button
Step 5:
- Pick an Agent Name (e.g. Info Agent)
- Add a Goal (e.g. Help customers answer travel related queries)
- Define an Instruction (e.g. - Greet the users, then ask how you can help them today)
- Press Save once everything is finalized
Step 6:
- Select the agent that you just created (e.g. Info Agent)
- Choose the underlying generative AI model for your agent (e.g. gemini-1.5-flash)
- Test your agent by having a conversation with it (i.e. Type something in "Enter User Input" text box)
Congratulations! You just successfully created an AI Agent using Vertex AI Agent Builder.
4. Attaching Datastores to the Agent
Try asking your agent about getting to Wakanda (e.g. "What's the best way to reach Wakanda?"), you will get a response like this:
While this is factually correct, instead of simply stating "I can't provide information" and ending the conversation, it would be more helpful to the user if the agent suggested similar places. This approach could potentially lead to users actually booking a trip through the agent.
In order for the agent to recommend similar places, you can provide more information to the agent through Datastores. It acts as an additional knowledge base for the agent to refer to if the agent is not able to answer user questions based on their built-in knowledge.
Creating a datastore is straight-forward, click on + Data store button at the bottom of the Agent Basics page.
At the next screen, fill up the following information:
- Tool name: Alternative Location
- Type: Data store
- Description: Use this tool if user's request contains a location that doesn't exist
and click Save when you are done. This creates a datastore tool for the agent to communicate with the datastore, but you still need to create an actual datastore that contains the information. To do that, click on Create a data store
You may be greeted with a pop up to agree with having your search & conversation data stores in the US region. If you want to proceed, click on the AGREE button.
Continuing the creation of data stores, fill up the Company name field (e.g. Travel Wise) and click on CONTINUE.
Click on CREATE DATA STORE and select Cloud Storage.
Once you are done with the step,
- Select Unstructured documents (PDF, HTML, TXT and more)
- Click on FILE
- Type ai-workshops/agents/data/wakanda.txt in the cell
- Click on CONTINUE button
If you are curious, here is the content of the provided text file:
Places that are similar to Wakanda
- Oribi Gorge in South Africa: The rock formations here are reminiscent of the Warrior Falls in Wakanda.
- Iguazu Falls: Located on the border of Argentina and Brazil, these massive waterfalls were a major inspiration for the Warrior Falls.
- Immerse yourself in Wakandan culture: Read the Black Panther comics, watch the movies, and explore online resources to learn more about Wakandan culture, language, and technology.
- Visit a Disney theme park: While there isn't a dedicated Wakanda land yet, you might be able to meet Black Panther at Disneyland or on a Marvel Day at Sea Disney cruise.
On the next page, name your datastore (e.g. Wakanda Alternative) and click CREATE.
As a final step, SELECT the data source that you just created and click on CREATE.
If everything went smoothly, you should see the datastore created under the Available data stores page.
If you click into the data store (Wakanda Alternative in this case), you will see more details about it, including documents that are included in the data store:
Head back to the Agent Basics page and click on Manage all tools
Click on the Data Store that you created previously.
There will be new settings under the Data stores section. If you are not able to see these new settings right away, it means that datastore is still ingesting the data from Google Cloud Storage. It should be done in less than 5 minutes.
- Choose the data store that you want to link up (e.g. Wakanda Alternative)
- In order to prevent Agent from hallucinations, set the setting to Very Low which applies tighter restrictions on Agent from making things up.
- Click on Save button at the top of the page, once you are done with the edits.
Head back to the Agent Basics page again, check the Data Store (e.g. Alternative Location), and click on Save button at top of the page.
You are almost there! The final step is to include the "Alternative Location" tool in the agent's instructions. Add a line, - Use ${TOOL: Alternative Location} if the user's request contains a location that does not exist, to the agent's instructions.
The border of the instructions box might turn red, but that's ok. Process on saving the agent by clicking the Save button on top of the page.
Once you have saved the agent's configuration, try asking your agent about getting to Wakanda (e.g. "What's the best way to reach Wakanda?") again, you will get a different response like this:
Congratulations! Your agent is now recommending places using the provided information from a text file.