From b8e4aedfbf0eb55b34599ee24e163b41072a699c Mon Sep 17 00:00:00 2001 From: Yeesian Ng Date: Thu, 13 Nov 2025 15:22:50 -0800 Subject: [PATCH] fix: Add vertexai initialization for code being deployed to AgentEngine Co-authored-by: Yeesian Ng PiperOrigin-RevId: 832031219 --- src/google/adk/cli/cli_deploy.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/google/adk/cli/cli_deploy.py b/src/google/adk/cli/cli_deploy.py index 335c786b..1467e1e4 100644 --- a/src/google/adk/cli/cli_deploy.py +++ b/src/google/adk/cli/cli_deploy.py @@ -64,6 +64,8 @@ CMD adk {command} --port={port} {host_option} {service_option} {trace_to_cloud_o """ _AGENT_ENGINE_APP_TEMPLATE: Final[str] = """ +import os +import vertexai from vertexai.agent_engines import AdkApp if {is_config_agent}: @@ -78,9 +80,12 @@ else: from .agent import {adk_app_object} if {express_mode}: # Whether or not to use Express Mode - import os - import vertexai vertexai.init(api_key=os.environ.get("GOOGLE_API_KEY")) +else: + vertexai.init( + project=os.environ.get("GOOGLE_CLOUD_PROJECT"), + location=os.environ.get("GOOGLE_CLOUD_LOCATION"), + ) adk_app = AdkApp( {adk_app_type}={adk_app_object},