This document describes how to deploy ADK agents to Vertex AI Agent Engine, Google Cloud's serverless managed service for hosting agents. Agent Engine deployment packages agents as Python modules with an auto-generated wrapper, enabling production deployment without managing infrastructure.
For other deployment options, see:
Vertex AI Agent Engine deployment differs fundamentally from container-based deployments (Cloud Run, GKE). Instead of creating Docker images, it:
adk_app.py wrapper file containing an AdkApp instanceThe Agent Engine service handles all runtime infrastructure, auto-scaling, and API serving.
Sources: src/google/adk/cli/cli_deploy.py635-710
Sources: src/google/adk/cli/cli_deploy.py635-710 src/google/adk/cli/cli_tools_click.py1347-1452
The adk deploy agent_engine command orchestrates the deployment:
| Option | Type | Required | Description |
|---|---|---|---|
--project | string | No | Google Cloud project ID (default: gcloud config) |
--region | string | No | Google Cloud region (default: gcloud config) |
--staging_bucket | string | Yes | GCS bucket for staging artifacts (e.g., gs://bucket) |
--agent_engine_id | string | No | ID of existing Agent Engine to update (creates new if omitted) |
--adk_app | string | No | Name of wrapper file (default: adk_app) |
--adk_app_object | string | No | Agent object name (default: root_agent) |
--api_key | string | No | API key for Express Mode (uses GOOGLE_API_KEY env var if not set) |
--trace_to_cloud | flag | No | Enable Cloud Trace telemetry |
--display_name | string | No | Display name for Agent Engine instance |
--description | string | No | Description for Agent Engine instance |
--requirements_file | string | No | Path to custom requirements.txt |
--env_file | string | No | Path to custom .env file |
--agent_engine_config_file | string | No | Path to custom .agent_engine_config.json |
--absolutize_imports | flag | No | Convert relative to absolute imports (default: True) |
Sources: src/google/adk/cli/cli_tools_click.py1347-1452
Agent Engine expects a specific package structure. The deployment process transforms your agent folder into this structure:
<temp_folder>/
├── adk_app.py # Generated wrapper (from _AGENT_ENGINE_APP_TEMPLATE)
├── agent.py # Your agent code
├── __init__.py # Your module init
├── requirements.txt # Dependencies (if present)
├── .env # Environment vars (if present)
└── ... (other agent files)
The .ae_ignore file (similar to .gitignore) specifies patterns of files to exclude from deployment:
# Example .ae_ignore
*.pyc
__pycache__/
.pytest_cache/
tests/
docs/
Implementation: The deployment uses shutil.copytree() with shutil.ignore_patterns() to filter files according to .ae_ignore patterns.
Sources: src/google/adk/cli/cli_deploy.py733-742
The deployment auto-generates an adk_app.py file that wraps your agent. This wrapper is the entry point for Agent Engine.
The wrapper is generated from _AGENT_ENGINE_APP_TEMPLATE:
{is_config_agent}: Boolean - whether agent uses YAML config{agent_folder}: Path to agent source{temp_folder}: Staging directory name{app_name}: Agent folder name{adk_app_object}: Agent object name (default: root_agent){express_mode}: Boolean - use API key vs project/location{adk_app_type}: Either agent or app{trace_to_cloud_option}: Boolean - enable tracingSources: src/google/adk/cli/cli_deploy.py69-97
Agent Engine exposes a predefined set of methods through the AdkApp wrapper. These methods are registered in _AGENT_ENGINE_CLASS_METHODS:
| Method | Mode | Description |
|---|---|---|
stream_query | stream | Deprecated. Synchronous streaming query |
async_stream_query | async_stream | Async streaming query (recommended) |
streaming_agent_run_with_events | async_stream | For AgentSpace integration |
| Method | Mode | Description |
|---|---|---|
get_session | sync | Deprecated. Get session synchronously |
async_get_session | async | Get session for user/session ID |
list_sessions | sync | Deprecated. List sessions synchronously |
async_list_sessions | async | List all sessions for a user |
create_session | sync | Deprecated. Create session synchronously |
async_create_session | async | Create new session |
delete_session | sync | Deprecated. Delete session synchronously |
async_delete_session | async | Delete session |
| Method | Mode | Description |
|---|---|---|
async_add_session_to_memory | async | Generate memories from session |
async_search_memory | async | Search memories for user |
Method Schema Example:
Sources: src/google/adk/cli/cli_deploy.py99-376
Sources: src/google/adk/cli/cli_deploy.py710-1102
This file contains deployment configuration that overrides CLI options:
The config is merged with CLI options, with CLI options taking precedence.
Implementation: src/google/adk/cli/cli_deploy.py750-771
Standard Python dependencies file. Agent Engine installs these packages at deployment time:
Implementation: src/google/adk/cli/cli_deploy.py773-790
Environment variables loaded into the Agent Engine runtime:
Special handling:
GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION are overridden by CLI --project and --region if specifiedGOOGLE_API_KEY enables Express Mode if GOOGLE_GENAI_USE_VERTEXAI=1Implementation: src/google/adk/cli/cli_deploy.py792-832
Agent Engine supports two authentication modes:
GOOGLE_API_KEY is set in environment or via --api_keyGOOGLE_GENAI_USE_VERTEXAI=1 environment variablevertexai.init(api_key=os.environ.get("GOOGLE_API_KEY"))GOOGLE_API_KEY is not setGOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATIONvertexai.init(project=..., location=...)Determination logic:
Sources: src/google/adk/cli/cli_deploy.py834-854
By default (--absolutize_imports=True), the deployment converts relative imports to absolute imports. This prevents import resolution issues in Agent Engine's runtime environment.
Before:
After:
The absolutization process:
importlab.fs.OSFileSystem to resolve imports.py files in the staged directoryImplementation: src/google/adk/cli/cli_deploy.py856-924
Sources: src/google/adk/cli/cli_deploy.py856-924
Location: src/google/adk/cli/cli_deploy.py635-653
Sources: src/google/adk/cli/cli_deploy.py635-1102
The deployment supports both creating new Agent Engine instances and updating existing ones:
When --agent_engine_id is not provided:
The SDK:
projects/.../locations/.../reasoningEngines/123)When --agent_engine_id is provided:
The SDK:
Implementation: src/google/adk/cli/cli_deploy.py926-1102
Sources: src/google/adk/cli/cli_deploy.py926-1102
Agent Engine deployments automatically integrate with ADK's service layer:
Agent Engine provides built-in session management through the Vertex AI backend. The AdkApp wrapper exposes session methods that delegate to Vertex AI's session service:
async_get_session() → Vertex AI Session APIasync_create_session() → Vertex AI Session APIasync_list_sessions() → Vertex AI Session APITo use custom session services in Agent Engine, agents must be configured with session service URIs in their initialization code.
Similarly, memory operations use Agent Engine's managed memory service:
async_add_session_to_memory() → Vertex AI RAG/Memory APIasync_search_memory() → Vertex AI RAG/Memory APISources: src/google/adk/cli/cli_deploy.py99-376
The to_agent_engine() function validates several conditions before deploying:
Working Directory Check: Must be in the parent directory of the agent folder
ADK App Object Validation: Must be root_agent or app
Project Resolution: Resolves GCP project from CLI option or gcloud config
Sources: src/google/adk/cli/cli_deploy.py710-745
The deployment process uses a try...finally block to ensure temporary files are cleaned up:
This ensures the temporary staging directory is removed even if deployment fails.
Sources: src/google/adk/cli/cli_deploy.py732-1102
Sources: src/google/adk/cli/cli_tools_click.py1347-1452
Agent Engine has package size limits enforced by Vertex AI. Large agent folders should:
.ae_ignore to exclude unnecessary files (tests, docs, large data files)requirements.txt--absolutize_imports=True to avoid relative import issuesRefresh this wiki
This wiki was recently refreshed. Please wait 6 days to refresh again.