Vertex AI Agent Engine in Express Mode

Source notebook

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

Build, test, deploy, and query a Gemini ADK currency agent on Vertex AI Agent Engine Express Mode.

Summary

This notebook teaches how to use Vertex AI Express Mode with Agent Engine and ADK to create a simple Gemini agent, add a currency exchange tool, and test it locally. It then writes source files, deploys the ADK app to Agent Engine from source, streams queries to the remote agent, and inspects stored session events.

Key code patterns

Initialize Express Mode

import vertexai
from vertexai import agent_engines
 
vertexai.init(api_key=express_mode_api_key)
model = "gemini-2.5-flash"

Uses an Express Mode API key to access Vertex AI services and Gemini.

Create ADK agent app

from google.adk.agents import Agent
from google.adk.apps import App
 
agent = Agent(model=model, name="currency_exchange_agent")
app = agent_engines.AdkApp(
    app=App(name="currency_exchange_app", root_agent=agent)
)

Wraps an ADK Agent in AdkApp for local Agent Engine-style interaction.

Add a Python tool

def get_exchange_rate(currency_from="USD", currency_to="EUR", currency_date="latest"):
    import requests
    response = requests.get(
        f"https://api.frankfurter.app/{currency_date}",
        params={"from": currency_from, "to": currency_to},
    )
    return response.json()
 
agent = Agent(model=model, name="currency_exchange_agent", tools=[get_exchange_rate])

Shows how a callable tool gives the agent live currency exchange data.

Deploy from source

client = vertexai.Client(api_key=express_mode_api_key)
remote_agent = client.agent_engines.create(config={
    "source_packages": ["test"],
    "entrypoint_module": "test.my_agent",
    "entrypoint_object": "adk_app",
    "requirements_file": "test/requirements.txt",
    "agent_framework": "google-adk",
})

Deploys local ADK source files to Vertex AI Agent Engine.

Stream remote queries

async for item in remote_agent.async_stream_query(
    message="What is the exchange rate between USD and Korean Won on 2025-09-25?",
    user_id="user1",
):
    print(item)

Uses the deployed agent’s async streaming method for conversations.

Models & APIs used

  • Models: gemini-2.5-flash
  • APIs / services: Vertex AI, Vertex AI Agent Engine, Vertex AI Session Service, Vertex AI Memory Bank
  • SDKs / libraries: google-cloud-aiplatform, vertexai, google-adk

When to use this

Use this pattern to prototype and deploy an ADK tool-using Gemini agent on Vertex AI Agent Engine with Express Mode API key access.

Gotchas & caveats

  • Requires signing up for Vertex AI Express Mode and pasting an API key.
  • The notebook installs google-cloud-aiplatform with agent_engines support before use.
  • The deployed source package must include a requirements file and an entrypoint object.
  • The exchange-rate tool depends on the external frankfurter.app API.
  • Express Mode model access and rate limits are linked to the documented Express Mode availability.

Best practices

  • Test the tool function directly before adding it to the agent.
  • Test the ADK agent locally before deploying it to Agent Engine.
  • Declare class_methods for the deployed async streaming and session methods.
  • Use source based deployment with source_packages, entrypoint_module, entrypoint_object, and requirements_file.
  • Inspect session events after remote conversations to view stored conversation history.