Building and Deploying a LangGraph Agent with Agent Engine in Vertex AI

Source notebook

Repo path: gemini/agent-engine/tutorial_langgraph.ipynb · Open on GitHub · intermediate

Builds, tests, deploys, and deletes a Gemini LangGraph agent on Vertex AI Agent Engine.

Summary

This notebook teaches how to define a Python tool, wrap it in an Agent Engine LanggraphAgent using Gemini, and test it locally. It then deploys the same agent to Vertex AI Agent Engine with a staging bucket and requirements, tests the remote agent, and deletes the deployed resource.

Key code patterns

Initialize Vertex AI

PROJECT_ID = "[your-project-id]"
LOCATION = "us-central1"
STAGING_BUCKET = f"gs://{PROJECT_ID}-agent-engine-staging"
 
import vertexai
vertexai.init(project=PROJECT_ID, location=LOCATION)

Sets the Google Cloud project and region before using Vertex AI resources.

Define a tool

def get_product_details(product_name: str):
    details = {
        "headphones": "Wireless headphones with advanced noise cancellation technology for immersive audio.",
        "shoes": "High-performance running shoes designed for comfort, support, and speed.",
    }
    return details.get(product_name, "Product details not found.")

Shows how a plain Python function can become an agent tool.

Create LangGraph agent

from vertexai import agent_engines
 
agent = agent_engines.LanggraphAgent(
    model="gemini-2.5-flash",
    tools=[get_product_details],
)

Uses the Agent Engine LanggraphAgent template with Gemini and a custom tool.

Test locally

response = agent.query(
    input={"messages": [("user", "Get product details for headphones")]}
)
 
print(response["messages"][-1]["kwargs"]["content"])

Verifies agent behavior before deployment.

Deploy to Agent Engine

client = vertexai.Client(project=PROJECT_ID, location=LOCATION)
remote_agent = client.agent_engines.create(
    agent=agent,
    config={"staging_bucket": STAGING_BUCKET,
            "requirements": ["google-cloud-aiplatform[agent_engines,langchain]"]},
)

Creates a remote Agent Engine deployment with dependency and staging configuration.

Clean up deployment

client.agent_engines.delete(name=remote_agent.api_resource.name)

Removes the deployed agent to avoid unnecessary charges.

Models & APIs used

  • Models: gemini-2.5-flash
  • APIs / services: Vertex AI, Agent Engine, Cloud Storage
  • SDKs / libraries: google-cloud-aiplatform[agent_engines,langchain], vertexai

When to use this

Use this pattern to deploy a LangGraph agent with custom Python tools to Vertex AI Agent Engine.

Gotchas & caveats

  • A Google Cloud project is required.
  • The Vertex AI API must be enabled.
  • Colab requires auth.authenticate_user().
  • The notebook uses LOCATION = “us-central1”.
  • A Cloud Storage staging bucket is configured as gs://{PROJECT_ID}-agent-engine-staging.
  • Remote deployment requires listing runtime requirements.
  • Deployed Agent Engine resources should be deleted to avoid charges.

Best practices

  • Test the LangGraph agent locally before deployment.
  • Provide deployment requirements in the Agent Engine config.
  • Use a staging bucket for Agent Engine deployment artifacts.
  • Delete the deployed agent after experimentation.
  • Optionally delete the staging bucket after cleanup.