@@ -505,13 +505,13 @@ def __init__(
505505 """
506506 from google .cloud .aiplatform import initializer
507507
508- adk_version = get_adk_version ()
509- if not is_version_sufficient ("1.5.0" ):
510- msg = (
511- f"Unsupported google-adk version: { adk_version } , please use "
512- "google-adk>=1.5.0 for AdkApp deployment on Agent Engine."
513- )
514- raise ValueError (msg )
508+ # adk_version = get_adk_version()
509+ # if not is_version_sufficient("1.5.0"):
510+ # msg = (
511+ # f"Unsupported google-adk version: {adk_version}, please use "
512+ # "google-adk>=1.5.0 for AdkApp deployment on Agent Engine."
513+ # )
514+ # raise ValueError(msg)
515515
516516 if not agent and not app :
517517 raise ValueError ("One of `agent` or `app` must be provided." )
@@ -540,6 +540,7 @@ def __init__(
540540 "artifact_service_builder" : artifact_service_builder ,
541541 "memory_service_builder" : memory_service_builder ,
542542 "instrumentor_builder" : instrumentor_builder ,
543+ "express_mode_api_key" : initializer .global_config .api_key ,
543544 }
544545
545546 async def _init_session (
@@ -683,9 +684,14 @@ def set_up(self):
683684
684685 os .environ ["GOOGLE_GENAI_USE_VERTEXAI" ] = "1"
685686 project = self ._tmpl_attrs .get ("project" )
686- os .environ ["GOOGLE_CLOUD_PROJECT" ] = project
687+ if project :
688+ os .environ ["GOOGLE_CLOUD_PROJECT" ] = project
687689 location = self ._tmpl_attrs .get ("location" )
688- os .environ ["GOOGLE_CLOUD_LOCATION" ] = location
690+ if location :
691+ os .environ ["GOOGLE_CLOUD_LOCATION" ] = location
692+ express_mode_api_key = self ._tmpl_attrs .get ("express_mode_api_key" )
693+ if express_mode_api_key :
694+ os .environ ["GOOGLE_API_KEY" ] = express_mode_api_key
689695
690696 # Disable content capture in custom ADK spans unless user enabled
691697 # tracing explicitly with the old flag
@@ -769,21 +775,37 @@ def tracing_enabled() -> bool:
769775 VertexAiSessionService ,
770776 )
771777
772- self ._tmpl_attrs ["session_service" ] = VertexAiSessionService (
773- project = project ,
774- location = location ,
775- agent_engine_id = os .environ .get ("GOOGLE_CLOUD_AGENT_ENGINE_ID" ),
776- )
778+ if is_version_sufficient ("1.18.0" ):
779+ self ._tmpl_attrs ["session_service" ] = VertexAiSessionService (
780+ project = project ,
781+ location = location ,
782+ agent_engine_id = os .environ .get ("GOOGLE_CLOUD_AGENT_ENGINE_ID" ),
783+ express_mode_api_key = express_mode_api_key ,
784+ )
785+ else :
786+ self ._tmpl_attrs ["session_service" ] = VertexAiSessionService (
787+ project = project ,
788+ location = location ,
789+ agent_engine_id = os .environ .get ("GOOGLE_CLOUD_AGENT_ENGINE_ID" ),
790+ )
777791 except (ImportError , AttributeError ):
778792 from google .adk .sessions .vertex_ai_session_service_g3 import (
779793 VertexAiSessionService ,
780794 )
781795
782- self ._tmpl_attrs ["session_service" ] = VertexAiSessionService (
783- project = project ,
784- location = location ,
785- agent_engine_id = os .environ .get ("GOOGLE_CLOUD_AGENT_ENGINE_ID" ),
786- )
796+ if is_version_sufficient ("1.18.0" ):
797+ self ._tmpl_attrs ["session_service" ] = VertexAiSessionService (
798+ project = project ,
799+ location = location ,
800+ agent_engine_id = os .environ .get ("GOOGLE_CLOUD_AGENT_ENGINE_ID" ),
801+ express_mode_api_key = express_mode_api_key ,
802+ )
803+ else :
804+ self ._tmpl_attrs ["session_service" ] = VertexAiSessionService (
805+ project = project ,
806+ location = location ,
807+ agent_engine_id = os .environ .get ("GOOGLE_CLOUD_AGENT_ENGINE_ID" ),
808+ )
787809
788810 else :
789811 self ._tmpl_attrs ["session_service" ] = InMemorySessionService ()
@@ -799,11 +821,19 @@ def tracing_enabled() -> bool:
799821 VertexAiMemoryBankService ,
800822 )
801823
802- self ._tmpl_attrs ["memory_service" ] = VertexAiMemoryBankService (
803- project = project ,
804- location = location ,
805- agent_engine_id = os .environ .get ("GOOGLE_CLOUD_AGENT_ENGINE_ID" ),
806- )
824+ if is_version_sufficient ("1.18.0" ):
825+ self ._tmpl_attrs ["memory_service" ] = VertexAiMemoryBankService (
826+ project = project ,
827+ location = location ,
828+ agent_engine_id = os .environ .get ("GOOGLE_CLOUD_AGENT_ENGINE_ID" ),
829+ express_mode_api_key = express_mode_api_key ,
830+ )
831+ else :
832+ self ._tmpl_attrs ["memory_service" ] = VertexAiMemoryBankService (
833+ project = project ,
834+ location = location ,
835+ agent_engine_id = os .environ .get ("GOOGLE_CLOUD_AGENT_ENGINE_ID" ),
836+ )
807837 except (ImportError , AttributeError ):
808838 # TODO(ysian): Handle this via _g3 import for google3.
809839 pass
@@ -878,9 +908,12 @@ async def async_stream_query(
878908 Yields:
879909 Event dictionaries asynchronously.
880910 """
911+ import os
881912 from vertexai .agent_engines import _utils
882913 from google .genai import types
883914
915+ os .environ ["GOOGLE_API_KEY" ] = self ._tmpl_attrs .get ("express_mode_api_key" , "" )
916+
884917 if isinstance (message , Dict ):
885918 content = types .Content .model_validate (message )
886919 elif isinstance (message , str ):
0 commit comments