@@ -538,6 +538,12 @@ def register_operations(self) -> Dict[str, List[str]]:
538538 _genai_types .IdentityType .SERVICE_ACCOUNT
539539)
540540_TEST_AGENT_ENGINE_ENCRYPTION_SPEC = {"kms_key_name" : "test-kms-key" }
541+ _TEST_AGENT_ENGINE_KEEP_ALIVE_PROBE = {
542+ "http_get" : {
543+ "path" : "/health" ,
544+ },
545+ "max_seconds" : 60 ,
546+ }
541547_TEST_AGENT_ENGINE_SPEC = _genai_types .ReasoningEngineSpecDict (
542548 agent_framework = _TEST_AGENT_ENGINE_FRAMEWORK ,
543549 class_methods = [_TEST_AGENT_ENGINE_CLASS_METHOD_1 ],
@@ -1071,6 +1077,7 @@ def test_create_agent_engine_config_with_source_packages(
10711077 config ["spec" ]["identity_type" ]
10721078 == _TEST_AGENT_ENGINE_IDENTITY_TYPE_SERVICE_ACCOUNT
10731079 )
1080+ assert "keep_alive_probe" not in config ["spec" ].get ("deployment_spec" , {})
10741081
10751082 def test_create_agent_engine_config_with_developer_connect_source (self ):
10761083 with tempfile .TemporaryDirectory () as tmpdir :
@@ -1112,6 +1119,29 @@ def test_create_agent_engine_config_with_developer_connect_source(self):
11121119 config ["spec" ]["identity_type" ]
11131120 == _TEST_AGENT_ENGINE_IDENTITY_TYPE_SERVICE_ACCOUNT
11141121 )
1122+ assert "keep_alive_probe" not in config ["spec" ].get ("deployment_spec" , {})
1123+
1124+ @mock .patch .object (
1125+ _agent_engines_utils ,
1126+ "_create_base64_encoded_tarball" ,
1127+ return_value = "test_tarball" ,
1128+ )
1129+ def test_create_agent_engine_config_with_empty_keep_alive_probe (
1130+ self , mock_create_base64_encoded_tarball
1131+ ):
1132+ with tempfile .TemporaryDirectory () as tmpdir :
1133+ test_file_path = os .path .join (tmpdir , "test_file.txt" )
1134+ with open (test_file_path , "w" ) as f :
1135+ f .write ("test content" )
1136+ config = self .client .agent_engines ._create_config (
1137+ mode = "create" ,
1138+ source_packages = [test_file_path ],
1139+ class_methods = _TEST_AGENT_ENGINE_CLASS_METHODS ,
1140+ entrypoint_module = "main" ,
1141+ entrypoint_object = "app" ,
1142+ keep_alive_probe = {},
1143+ )
1144+ assert "keep_alive_probe" not in config ["spec" ].get ("deployment_spec" , {})
11151145
11161146 def test_create_agent_engine_config_with_agent_config_source_and_requirements_file (
11171147 self ,
@@ -1321,6 +1351,33 @@ def test_create_agent_engine_config_with_container_spec(self):
13211351 config ["spec" ]["identity_type" ]
13221352 == _TEST_AGENT_ENGINE_IDENTITY_TYPE_SERVICE_ACCOUNT
13231353 )
1354+ assert "keep_alive_probe" not in config ["spec" ].get ("deployment_spec" , {})
1355+
1356+ def test_create_agent_engine_config_with_container_spec_and_keep_alive_probe (
1357+ self ,
1358+ ):
1359+ container_spec = {"image_uri" : "gcr.io/test-project/test-image" }
1360+ config = self .client .agent_engines ._create_config (
1361+ mode = "create" ,
1362+ display_name = _TEST_AGENT_ENGINE_DISPLAY_NAME ,
1363+ description = _TEST_AGENT_ENGINE_DESCRIPTION ,
1364+ container_spec = container_spec ,
1365+ class_methods = _TEST_AGENT_ENGINE_CLASS_METHODS ,
1366+ identity_type = _TEST_AGENT_ENGINE_IDENTITY_TYPE_SERVICE_ACCOUNT ,
1367+ keep_alive_probe = _TEST_AGENT_ENGINE_KEEP_ALIVE_PROBE ,
1368+ )
1369+ assert config ["display_name" ] == _TEST_AGENT_ENGINE_DISPLAY_NAME
1370+ assert config ["description" ] == _TEST_AGENT_ENGINE_DESCRIPTION
1371+ assert config ["spec" ]["container_spec" ] == container_spec
1372+ assert config ["spec" ]["class_methods" ] == _TEST_AGENT_ENGINE_CLASS_METHODS
1373+ assert (
1374+ config ["spec" ]["identity_type" ]
1375+ == _TEST_AGENT_ENGINE_IDENTITY_TYPE_SERVICE_ACCOUNT
1376+ )
1377+ assert (
1378+ config ["spec" ]["deployment_spec" ]["keep_alive_probe" ]
1379+ == _TEST_AGENT_ENGINE_KEEP_ALIVE_PROBE
1380+ )
13241381
13251382 def test_create_agent_engine_config_with_container_spec_and_others_raises (self ):
13261383 container_spec = {"image_uri" : "gcr.io/test-project/test-image" }
@@ -2116,6 +2173,7 @@ def test_create_agent_engine_with_env_vars_dict(
21162173 image_spec = None ,
21172174 agent_config_source = None ,
21182175 container_spec = None ,
2176+ keep_alive_probe = None ,
21192177 )
21202178 request_mock .assert_called_with (
21212179 "post" ,
@@ -2220,6 +2278,7 @@ def test_create_agent_engine_with_custom_service_account(
22202278 image_spec = None ,
22212279 agent_config_source = None ,
22222280 container_spec = None ,
2281+ keep_alive_probe = None ,
22232282 )
22242283 request_mock .assert_called_with (
22252284 "post" ,
@@ -2323,6 +2382,7 @@ def test_create_agent_engine_with_experimental_mode(
23232382 image_spec = None ,
23242383 agent_config_source = None ,
23252384 container_spec = None ,
2385+ keep_alive_probe = None ,
23262386 )
23272387 request_mock .assert_called_with (
23282388 "post" ,
@@ -2495,6 +2555,7 @@ def test_create_agent_engine_with_class_methods(
24952555 image_spec = None ,
24962556 agent_config_source = None ,
24972557 container_spec = None ,
2558+ keep_alive_probe = None ,
24982559 )
24992560 request_mock .assert_called_with (
25002561 "post" ,
@@ -2593,6 +2654,7 @@ def test_create_agent_engine_with_agent_framework(
25932654 image_spec = None ,
25942655 agent_config_source = None ,
25952656 container_spec = None ,
2657+ keep_alive_probe = None ,
25962658 )
25972659 request_mock .assert_called_with (
25982660 "post" ,
@@ -2795,6 +2857,109 @@ def test_update_agent_engine_env_vars(
27952857 None ,
27962858 )
27972859
2860+ @mock .patch .object (_agent_engines_utils , "_prepare" )
2861+ @mock .patch .object (_agent_engines_utils , "_await_operation" )
2862+ def test_update_agent_engine_with_empty_keep_alive_probe (
2863+ self , mock_await_operation , mock_prepare
2864+ ):
2865+ mock_await_operation .return_value = _genai_types .AgentEngineOperation (
2866+ response = _genai_types .ReasoningEngine (
2867+ name = _TEST_AGENT_ENGINE_RESOURCE_NAME ,
2868+ spec = _TEST_AGENT_ENGINE_SPEC ,
2869+ )
2870+ )
2871+ with mock .patch .object (
2872+ self .client .agent_engines ._api_client , "request"
2873+ ) as request_mock :
2874+ request_mock .return_value = genai_types .HttpResponse (body = "" )
2875+ self .client .agent_engines .update (
2876+ name = _TEST_AGENT_ENGINE_RESOURCE_NAME ,
2877+ agent = self .test_agent ,
2878+ config = _genai_types .AgentEngineConfig (
2879+ staging_bucket = _TEST_STAGING_BUCKET ,
2880+ keep_alive_probe = {},
2881+ ),
2882+ )
2883+ update_mask = "," .join (
2884+ [
2885+ "spec.package_spec.pickle_object_gcs_uri" ,
2886+ "spec.package_spec.requirements_gcs_uri" ,
2887+ "spec.class_methods" ,
2888+ "spec.deployment_spec.keep_alive_probe" ,
2889+ "spec.agent_framework" ,
2890+ ]
2891+ )
2892+ query_params = {"updateMask" : update_mask }
2893+ request_mock .assert_called_with (
2894+ "patch" ,
2895+ f"{ _TEST_AGENT_ENGINE_RESOURCE_NAME } ?{ urlencode (query_params )} " ,
2896+ {
2897+ "_url" : {"name" : _TEST_AGENT_ENGINE_RESOURCE_NAME },
2898+ "spec" : {
2899+ "agent_framework" : _TEST_AGENT_ENGINE_FRAMEWORK ,
2900+ "class_methods" : mock .ANY ,
2901+ "package_spec" : {
2902+ "python_version" : _TEST_PYTHON_VERSION ,
2903+ "pickle_object_gcs_uri" : _TEST_AGENT_ENGINE_GCS_URI ,
2904+ "requirements_gcs_uri" : _TEST_AGENT_ENGINE_REQUIREMENTS_GCS_URI ,
2905+ },
2906+ "deployment_spec" : {"keep_alive_probe" : {}},
2907+ },
2908+ "_query" : {"updateMask" : update_mask },
2909+ },
2910+ None ,
2911+ )
2912+
2913+ @mock .patch .object (_agent_engines_utils , "_await_operation" )
2914+ def test_update_agent_engine_with_container_spec_and_keep_alive_probe (
2915+ self , mock_await_operation
2916+ ):
2917+ mock_await_operation .return_value = _genai_types .AgentEngineOperation (
2918+ response = _genai_types .ReasoningEngine (
2919+ name = _TEST_AGENT_ENGINE_RESOURCE_NAME ,
2920+ spec = _TEST_AGENT_ENGINE_SPEC ,
2921+ )
2922+ )
2923+ container_spec = {"image_uri" : "gcr.io/test-project/test-image" }
2924+ with mock .patch .object (
2925+ self .client .agent_engines ._api_client , "request"
2926+ ) as request_mock :
2927+ request_mock .return_value = genai_types .HttpResponse (body = "" )
2928+ self .client .agent_engines .update (
2929+ name = _TEST_AGENT_ENGINE_RESOURCE_NAME ,
2930+ config = _genai_types .AgentEngineConfig (
2931+ container_spec = container_spec ,
2932+ keep_alive_probe = _TEST_AGENT_ENGINE_KEEP_ALIVE_PROBE ,
2933+ class_methods = _TEST_AGENT_ENGINE_CLASS_METHODS ,
2934+ ),
2935+ )
2936+ update_mask = "," .join (
2937+ [
2938+ "spec.class_methods" ,
2939+ "spec.container_spec" ,
2940+ "spec.deployment_spec.keep_alive_probe" ,
2941+ "spec.agent_framework" ,
2942+ ]
2943+ )
2944+ query_params = {"updateMask" : update_mask }
2945+ request_mock .assert_called_with (
2946+ "patch" ,
2947+ f"{ _TEST_AGENT_ENGINE_RESOURCE_NAME } ?{ urlencode (query_params )} " ,
2948+ {
2949+ "_url" : {"name" : _TEST_AGENT_ENGINE_RESOURCE_NAME },
2950+ "spec" : {
2951+ "agent_framework" : "custom" ,
2952+ "container_spec" : container_spec ,
2953+ "deployment_spec" : {
2954+ "keep_alive_probe" : _TEST_AGENT_ENGINE_KEEP_ALIVE_PROBE ,
2955+ },
2956+ "class_methods" : mock .ANY ,
2957+ },
2958+ "_query" : {"updateMask" : update_mask },
2959+ },
2960+ None ,
2961+ )
2962+
27982963 @mock .patch .object (_agent_engines_utils , "_await_operation" )
27992964 def test_update_agent_engine_display_name (self , mock_await_operation ):
28002965 mock_await_operation .return_value = _genai_types .AgentEngineOperation (
0 commit comments