Building AI Agents with Vertex AI Agent Builder

About this codelab
schedule30 minutes
subjectLast updated October 30, 2024
account_circleWritten by Thu Ya Kyaw

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.

  • 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. 833886ce0d2645ba.png
  • Click on the CONTINUE AND ACTIVATE THE API button.

Step 2:

  • You will be redirected to the App Creation page. 49191476c9dec2b5.png
  • Click on the CREATE A NEW APP button.

Step 3:

  • Select Agent on the next page

125fa74ef852ad10.png

Step 4:

  • Pick a Display Name (e.g. Travel Buddy)
  • Select global as Region
  • Click on the AGREE & CREATE button

bbf82261f4e1a45f.png

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

5bf079b3a737970d.png

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)

e3905998a6e342f8.jpeg

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:

f77de487b46a7ee4.png

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.

ab126f4e40d934cf.png

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

dbaf02cabbfbac1.png

130dc7d6ae8e26bd.png

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

932626c5a7b85c5b.png

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.

6e21fabe10678a53.png

Continuing the creation of data stores, fill up the Company name field (e.g. Travel Wise) and click on CONTINUE.

6e3eafcf8b96b7dc.png

Click on CREATE DATA STORE and select Cloud Storage.

56f344d8966abbd1.png

560f4364a1c9b496.png

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

4671502439bfa4dd.png

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.

b0c135091fb957cb.png

As a final step, SELECT the data source that you just created and click on CREATE.

3e1c3eda3c5ca2ce.png

If everything went smoothly, you should see the datastore created under the Available data stores page.

c87bfa4dab7c4e46.png

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:

b0ad058f05794b06.png

Head back to the Agent Basics page and click on Manage all tools 2489535874cd31af.png

Click on the Data Store that you created previously.

2b4f0d436cf5fa6f.png

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)

f6498ef236744ee5.png

  • In order to prevent Agent from hallucinations, set the setting to Very Low which applies tighter restrictions on Agent from making things up.

c1605bd076258050.png

  • 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.

f7558c029cf9da53.png

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.

bbbd24e8a0207e8b.png

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.

2476b61debfb742d.png

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:

751204b7ae15fae8.png

Congratulations! Your agent is now recommending places using the provided information from a text file.