Generative AI applications are rapidly moving beyond single-turn conversational chatbots toward Autonomous Multi-Tool AI Agents. Instead of just generating static text, modern agents evaluate user prompts, make routing decisions, select specialised external tools, and fetch dynamic real-time data before returning a grounded response.
In this article, we will break down the end-to-end architecture and implementation of an autonomous agent built using Vertex AI, Python, and Google Cloud infrastructure.
## High-Level System Architecture
The solution uses a three-tier agentic architecture designed for low latency, modularity, and strict session isolation:
To start, configure your Google Cloud project and enable the necessary service APIs in Cloud Shell:
``bash`
export PROJECT_ID=$(gcloud config get-value project)
export REGION="us-central1"
gcloud services enable \
aiplatform.googleapis.com \
run.googleapis.com \
cloudbuild.googleapis.com \
firestore.googleapis.com
1. Defining Agent Tools and Schema Declarations
`
import vertexai
from vertexai.generative_models import GenerativeModel, FunctionDeclaration, Tool
vertexai.init(project="YOUR_PROJECT_ID", location="us-central1")
inventory_func = FunctionDeclaration(
name="query_inventory",
description="Look up product stock, availability, and unit pricing dynamically.",
parameters={
"type": "object",
"properties": {
"item_name": {
"type": "string",
"description": "The specific item or product name to search"
},
"category": {
"type": "string",
"description": "Item category, e.g., beverages, snacks, merchandise"
}
},
"required": ["item_name"]
},
)
agent_tools = Tool(function_declarations=[inventory_func])
plaintext
2. Implementing the Orchestration Logic
def query_inventory(item_name: str, category: str = None) -> dict:
return {
"item": item_name,
"in_stock": True,
"quantity": 42,
"price_usd": 4.50
}
model = GenerativeModel(
model_name="gemini-1.5-flash-001",
tools=[agent_tools]
)
chat = model.start_chat()
response = chat.send_message("Do we have any Cold Brew in stock?")
for part in response.candidates[0].content.parts:
if part.function_call:
fn_name = part.function_call.name
fn_args = dict(part.function_call.args)
if fn_name == "query_inventory":
tool_result = query_inventory(**fn_args)
final_response = chat.send_message(
vertexai.generative_models.Part.from_function_response(
name=fn_name,
response={"content": tool_result}
)
)
print(final_response.text)
plaintext
3. Packaging and Deploying to Google Cloud Run
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8080
CMD ["streamlit", "run", "app.py", "--server.port=8080", "--server.address=0.0.0.0"]
``shell`
Deploy directly using the Google Cloud CLI:
gcloud run deploy genai-agent-service \
--source . \
--region us-central1 \
--allow-unauthenticated
`