Google AgentBuilder + Reasoning Engine?—?Turn your Langchain demos into enterprise Agents with open source flexibility and unlimited scalability.
In our previous articles [Part1, Part2], we dived into the realm of Google Agent Builder, harnessing its simplicity to build secure, data-aware generative agents and seamlessly integrate them into existing enterprise workflows. We learned how to safeguard these agents with authentication and fine-grained access control, ensuring both security and compliance.
Now, we take another step forward, demonstrating how to transition your experimental Langchain or OneTwo agents from sandboxed demos to a robust, scalable production environment. We’ll leverage the capabilities of Vertex AI Reasoning Engine to deploy these agents, and then seamlessly plug them into the fabric of our main multi-agent application built with Agent Builder which is going to be a main brain orchestrating conversations with users and delegating execution to more specialized components like Agent Builder Search app or Langchain agent that is able to lookup currency exchange rates:?
What is new it this story is Vertex AI Reasoning Engine so let me introduce this component.?
Many of you have know Firebase. Firebase is a comprehensive application development platform that streamlines the entire process, from building and testing all the way to deploying and scaling your Mobile and Web applications.
Similarly, many of you are likely familiar with Vertex AI. It’s a powerful machine learning platform designed to simplify the entire machine learning lifecycle, from initial experimentation and model training to seamless deployment, monitoring, and scaling of your machine learning and AI models.
Vertex AI Reasoning Engine is akin to Firebase for app development and Vertex AI for machine learning, but with a laser focus on enterprise-grade generative AI applications. Its core purpose is to streamline the entire lifecycle of these applications, specifically Agents, making it easier to build, test, deploy, and scale them efficiently. Unlike AgentBuilder which is a low-code approach to building multi-agent applications, Vertex AI Reasoning Engine caters specifically to developers who prefer the flexibility and control of open-source frameworks like Langchain or OneTwo. It empowers developers to leverage their coding skills and preferred tools to craft sophisticated generative AI applications.
In my previous blog From Zero to Hero: Building LLM Chains and Agents with Google DeepMind’s OneTwo OpenSource Toolkit I showed how to develop, deploy and query agents built using OneTwo library and Cloud Run in Do It Yourself (DYI) approach. Reasoning Engine simplifies this process with standardized interface to a variety of frameworks, single click deployments and a common registry of Agents deployed to Reasoning Engine so you can mange them. Because you can manage them from a central place you gain a clear overview of your agent landscape, enabling you to understand their types and easily retire those that are no longer required.
In this article I will show you how AgentBuilder and Reasoning Engine can be used together and how will this help you build Multi-Agents applications with enterprise security, open source flexibility and unlimited scalability!?
Enough talk, let’s dive into action! In this section, we’ll walk through the process of deploying your Langchain agent onto Vertex AI Reasoning Engine. (If you’re interested in deploying OneTwo agents, be sure to check out my other article on that topic). Get ready to experience the streamlined deployment process firsthand!
We will use Vertex AI Colabs as working environment.?
Install necessary dependencies:
!pip install langchain==0.1.16 langchain-google-vertexai==1.0.2 pydantic
Instantiate session with VertexAI using its SDK:
PROJECT_ID = "genai-app-builder" # @param {type:"string"}
LOCATION = "us-central1" # @param {type:"string"}
STAGING_BUCKET = "gs://lolejniczak-imagen2-segmenttaion" # @param {type:"string"}
import vertexai
vertexai.init(project=PROJECT_ID, location=LOCATION, staging_bucket=STAGING_BUCKET)
We need the following imports to work with Reasoning Engine:
import requests
from vertexai.preview import reasoning_engines
OUr agent will run on Gemini-1.5-Pro:
model = "gemini-1.5-pro-001"
Agent will be responsible for providing information about currency exchange rates. Of course Gemini does not have this knowledge but our agent will be equipped with Tool?—?pyhon function which is making calls to https://api.frankfurter.app/ to get the necessary exchange rate:
def get_exchange_rate(
currency_from: str = "USD",
currency_to: str = "EUR",
currency_date: str = "latest",
):
"""Retrieves the exchange rate between two currencies on a specified date."""
import requests
response = requests.get(
f"https://api.frankfurter.app/{currency_date}",
params={"from": currency_from, "to": currency_to},
)
return response.json()
We can run this function without asking Agent?:D?
get_exchange_rate(currency_from="USD", currency_to="SEK")
but in the end we want agent to engage with users, collect essential information, process it through its available tool functions [get_exchange_rate], and then present meaningful results back to the user in a clear and concise manner.
agent = reasoning_engines.LangchainAgent(
model=model,
tools=[get_exchange_rate],
agent_executor_kwargs={"return_intermediate_steps": True},
)
It runs locally on virtual machine used to run your Colab instance:
Here is how you can send queries to this local agent:
agent.query(input="What's the exchange rate from US dollars to Swedish currency today?")
OK it works as expected.?
We’re all set for remote deployment so our Agent will be available as API endpoint!?
remote_agent = reasoning_engines.ReasoningEngine.create(
reasoning_engines.LangchainAgent(
model="gemini-1.0-pro-001",
tools=[get_exchange_rate],
enable_tracing=True,
),
requirements=[
"google-cloud-aiplatform[langchain,reasoningengine]",
"cloudpickle==3.0",
],
)
Deployment complete! We’re good to go. Start sending queries to your remote agent:?
remote_agent.query(
input="Jaki jest dzisiejszy kurs wymiany dolara amerykanskiego na PLN?"
)
Great news! You now have your Langchain Agent at your disposal, ready to be integrated into your backend systems using the Vertex AI Python SDK or through a convenient REST API. This opens up a world of possibilities, allowing you to effortlessly connect your agent to your user interface and perform the tasks you typically handle with your Langchain or OneTwo agents.
While the standard integration options are already valuable, we’re going to explore a different path here. We’ll integrate your agent with Agent Builder app.?
We will proceed by creating a tool within our existing Agent application implement in Part 1. The tool will represent our Langchain agent running on Vertex AI Reasoning Engine. We’ll name it currency_exchange_agent:
For the Open API specification of this tool, I utilized the following: (modify paths attribute?—?include ID assigned to your agent from Reasoning Engine):
projects/{YOUR_GCP_PROJECT}/locations/us-central1/reasoningEngines/{YOUR REASONING ENGINE AGENT ID}:query:
openapi: 3.0.0
info:
title: Vertex AI Reasoning Engine Query API (genai-app-builder)
description: API for interacting with a specific Google Vertex AI Reasoning Engine.
version: 1.0.0
servers:
- url: https://us-central1-aiplatform.googleapis.com/v1beta1
paths:
/projects/genai-app-builder/locations/us-central1/reasoningEngines/XXXXXXXXXXXX:query:
post:
operationId: queryReasoningEngine
summary: Query a specific Vertex AI Reasoning Engine
description: Submit a query to a specific Reasoning Engine for processing.
requestBody:
description: Query input data.
required: true
content:
application/json:
schema:
type: object
properties:
input:
type: object
properties:
input:
type: string
description: Text of the query.
example: "What's the exchange rate from US dollars to Swedish currency today?"
example:
input:
input: "What's the exchange rate from US dollars to Swedish currency today?"
responses:
200:
description: Successful query response.
content:
application/json:
schema:
type: object
properties:
output:
type: string
description: The final response from the Reasoning Engine.
input:
type: string
description: The original input query.
example:
output: "The exchange rate from US Dollar to Swedish krona today is 10.5035. That means that for every US Dollar, you will get 10.5035 Swedish krona."
input: "What's the exchange rate from US dollars to Swedish currency today?"
400:
description: Bad request (invalid input format).
401:
description: Unauthorized (missing or invalid authentication credentials).
403:
description: Forbidden (insufficient permissions).
404:
description: Not found (Reasoning Engine not found).
500:
description: Internal server error.
领英推荐
Let’s break it down piece by piece:
openapi: 3.0.0: This simply says "Hey, I'm using version 3.0.0 of the OpenAPI standard to describe this API." Think of it like specifying which version of a language you're speaking.
info: This section gives some basic information about the API:
title: "Vertex AI Reasoning Engine Query API (genai-app-builder)" - A descriptive name.
description: "API for interacting with a specific Google Vertex AI Reasoning Engine" - Tells you what it's used for.
version: "1.0.0" - The version number of this specific API.
servers: This tells you where to find the AI agent you want to talk to:
url: "https://us-central1-aiplatform.googleapis.com/v1beta1" - This is the web address (like a house address) where your AI agent lives.
paths: This is the heart of the specification. It defines the different ways you can interact with your AI agent:
/projects/genai-app-builder/locations/us-central1/reasoningEngines/XXXXXXXXXXXX:query: This is like a specific path or doorway to your AI agent.
post: This means you'll be sending information to the AI agent (like posting a letter).
operationId: "queryReasoningEngine" - A name for this specific action.
summary & description: Explain what this action does (submit a query to the AI).
requestBody: This is the important part! It describes what kind of information you need to send in your "letter" to the AI:
It needs to be in application/json format (a common way to structure data).
It needs to have an input object, which contains the actual input text (your question or task for the AI).
responses: This tells you what kind of "replies" you can expect from the AI:
200: This is a good response! It means everything went well and the AI has an answer for you. The example shows what the response might look like.
400, 401, 403, 404, 500: These are error codes. They tell you if something went wrong, like if you sent the request incorrectly or if the AI agent couldn't be found.
For this tool’s authentication, we don’t need to tie queries to specific logged-in users. This TOOL will just access data that we want to make available to any logged-in user, so we’ll use a service account representing our Agent Builder applications when calling the currency exchange agent.
We just need to grant this service account necessary privileges (Vertex AI User Role) in GCP IAM:
Finally, let’s update the reasoning rules for our Agent. Whenever a user inquires about currencies, we want our agent to relay their queries to our Langchain agent:
When we give it a try from our application:?
We can audit this conversation from conversation history in Agent Builder:
To get more in-depth information about what’s happening during the execution of your Langchain agent, you’ll want to activate tracing. Here’s the adjusted code snippet to enable tracing:
agent = reasoning_engines.LangchainAgent(
model="gemini-1.0-pro-001",
tools=[get_exchange_rate],
enable_tracing=True,
)
Once you’ve enabled tracing in your Langchain agent, you can leverage GCP Cloud Trace to analyze the collected trace data.?
Cloud Trace provides a visual interface and auxiliary tools to help you:
By combining Langchain’s tracing capabilities with Cloud Trace’s visualization and analysis tools, you can gain a deeper understanding of your agent’s behavior and performance, and make informed decisions about how to optimize its design and implementation.
That’s it! We’ve built an enterprise-ready multi-agent application with Langchain integration for currency exchange, deployed on Reasoning Engine. This showcases how to transition your Langchain demos into production using Google AgentBuilder and Reasoning Engine, providing open-source flexibility and unlimited scalability.
You may want to check previous articles from this series:
- Putting Generative Agents behind authentication and controlling their Access. From sandbox to production. Part?1
- Chat on Confluence/Jira/Sharepoint?… Data with access control. Google Agent Builder. From sandbox to production. Part?2.
- OneTwo and Vertex AI Reasoning Engine: exploring advanced AI agent development on Google?Cloud
Summary:
This article guides how to deploy a Langchain agent to Vertex AI Reasoning Engine and integrate it with an existing multi-agent application built with Agent Builder.
Vertex AI Reasoning Engine is a platform designed to streamline the lifecycle of generative AI applications, particularly Agents. It facilitates the building, testing, deployment, and scaling of these applications.
The article details the process of deploying a Langchain agent to Vertex AI Reasoning Engine using Vertex AI Colabs. It also outlines how to create a tool within the existing Agent application to represent the Langchain agent running on Vertex AI Reasoning Engine, set up authentication, and update the reasoning rules to allow the agent to handle currency-related queries.
Please clap for this article if you enjoyed reading it. For more about google cloud, data science, data engineering, and AI/ML follow me on LinkedIn.
This article is authored by Lukasz Olejniczak? —?AI Specialist at Google Cloud. The views expressed are those of the authors and don’t necessarily reflect those of Google.
Data, AI, ML @Google
7 个月Great stuff! As usual. ????? I believe this demo-to-production step is the most challenging for teams starting their AI journeys. Thanks for sharing
Applied AI - AI/ML at Google Cloud
7 个月Medium (free for everyone): https://medium.com/@olejniczak.lukasz/google-agentbuilder-reasoning-engine-turn-your-langchain-demos-into-enterprise-agents-with-069c84f28dc6