Integrate External Data Sources into Vertex AI Agent Builder
Originally published on Premier Cloud Blog
Welcome!
In a previous tutorial on Vertex AI Agent Builder, we explored how to use static data sources like PDFs and CSV files to power a chatbot that can answer user queries. We learned how to index and analyse this data to provide information to users.
However, real-world applications often require access to dynamic and constantly changing information. This is where integrating external data sources comes into play.
This tutorial will guide you through the process of integrating external data sources, specifically APIs, into Vertex AI Agent Builder. By connecting your agent to external APIs, you can unlock a world of possibilities and create truly intelligent conversational experiences.
Incase you missed the previous article, check out the link below.
What is Vertex AI Agent Builder ?
Before we dive into integrating external data sources into conversational chat apps in Agent builder, lets understand what the tool is.
Vertex AI Agent Builder is a powerful platform for building AI agents and applications that can interact with and understand the world around them. Whether you’re crafting agents that respond to natural language queries or building applications using code, Agent Builder provides a comprehensive suite of tools. Crucially, it allows you to easily integrate your enterprise data to ground these agents in reality. This means your agents can access and utilize the relevant information they need to perform their tasks effectively. But the true power of Agent Builder comes to life when you bring in data from external sources. This article dives deep into how to seamlessly integrate external data sources, unlocking the full potential of your AI agents and applications.
If you want a video version of the blog, you can check out the video tutorial given below.
Understanding External Data Sources
Imagine an e-commerce company that relies on a conversational agent for customer support. If the agent only has access to static data, it might not be able to answer questions about product availability, shipping timelines, etc.
By integrating external data sources, such as APIs from inventory management system, shipping providers, and marketing platforms, the agent can access real time information and provide accurate and up-to-date answers to customer inquiries.
Dynamic data sources are essential for conversational agents to stay relevant and effective in a constantly changing world. Unlike static data, which quickly becomes outdated, dynamic sources provide real-time information, enabling agents to deliver accurate responses and adapt to evolving trends.
API Setup
For this article, to illustrate the concept of integrating dynamic data sources, we’ll use a simple Warehouse Address API. This API allows us to retrieve the address of a specific warehouse based on its ID, providing real-time information that ca be used to enhance our conversational agent.
This API is implemented using Flask, a popular python framework for building web applications, and deployed on Cloud Run. To know more about Cloud Run, check out the link given below.
Once you’ve deployed your API on Cloud Run, I have created a YAML file that will be used in the process of configuring the agent and tools. You can check the YAML file given below.
openapi: 3.0.0
info:
title: Warehouse Address API
version: v1
servers:
- url: 'https://my-warehouse-api-zycua53bta-uc.a.run.app'
paths:
/warehouses/{warehouseId}/address:
get:
summary: Get Warehouse Address
description: Retrieves the address of a warehouse by its ID.
parameters:
- in: path
name: warehouseId
schema:
type: integer
format: int64
required: true
description: The ID of the warehouse.
responses:
'200':
description: Successful response with the warehouse address.
content:
application/json:
schema:
type: string
description: The full address of the warehouse.
'404':
description: Warehouse not found.
Think of it as a blueprint for your API, outlining how it should handle requests and responses. This YAML file is written in a human-readable format called YAML (Yet Another Markup Language) which is often used for configuration files.It describes the different parts of the API.
This YAML file plays a critical role when integrating your API with conversational agents in Vertex AI Agent Builder. It provides a structured way for the agent to understand how to interact with your API. Agent Builder uses the YAML definition to configure tools that can access and interact with the API, allowing the agent to effectively retrieve data about warehouse addresses and seamlessly integrate it into its responses.
In essence, the YAML file acts as a translator between your API and the conversational agent, making the data accessible and usable within the Agent Builder environment.
Connect your API
Now that we have our API ready and good to go, its time to connect the API to our agent and see how we can integrate real-time data into Agent Builder. Check out the link below to know more about Agent Builder.
https://cloud.google.com/products/agent-builder?hl=en
On reaching the Agent console, go ahead and click on Tools and create a new Tool, after which you have fill in the following details.
Begin by giving the tool a name, followed by selecting the type (OPENAPI), after which you give it a description and the YAML file contents. Once you are done entering go ahead and click on Save and navigate to Agents.
Now that we are done setting up the tool, its time create the Agent the users are going to interact with. We start off by giving it a name, goal and a set of instructions. These instructions is a ordered list of step-by-step execution to achieve the goal.
Note: Remember the name of the Tool you have created and mention it in the Instructions like this — ${TOOL: Tool_name}
Test your Agent
Just like any software, agents need thorough testing. This helps identify bugs in their code, understand their current capabilities, and most important, simulate real interactions with users to refine the overall customer experience.
While you are in the console, go ahead and select the appropriate agent and select the generative model of your choice and you now ask questions to the agent and the response will be coming from the API.
I am going to be asking my agent for addresses based on their ID and the agent should be able to return the address.
Here you can see on successful execution the agent is able to return the address for the respective ID and all this information is coming from the tools that is connected to our API.
Typically it should not, but if your agent responds with generic phrases like “I didn’t understand,” it could be because it’s still processing or the tool name could be wrong or your API is not responding.
Publish your App
Now that the Chat App is up and running, it’s time to publish it and embed it into our website. To publish your Chat App, click on the Publish button which will prompt you with the following.
You have to specify the agent environment, followed by the Access type and the UI Style that you want. Once you have all of this set, go ahead and click on Enable the unauthenticated API.
You will be provided with the code which you can put into your website and your chat app will be accessible on your website.
Conclusion
In this tutorial, we look at how we can build a conversational AI agent with the integration of external/dynamic data sources into Vertex AI Agent Builder. This was a very simple example where we used an OpenAPI to return addresses based on their ID.
Feel free to reach out if you have any issues/feedback at aryanirani123@gmail.com.