@@ -63,6 +63,21 @@ def _ReasoningEngineSpec_to_vertex(
63
63
return to_object
64
64
65
65
66
+ def _ReasoningEngineContextSpec_to_vertex (
67
+ from_object : Union [dict [str , Any ], object ],
68
+ parent_object : Optional [dict [str , Any ]] = None ,
69
+ ) -> dict [str , Any ]:
70
+ to_object : dict [str , Any ] = {}
71
+ if getv (from_object , ["memory_bank_config" ]) is not None :
72
+ setv (
73
+ to_object ,
74
+ ["memoryBankConfig" ],
75
+ getv (from_object , ["memory_bank_config" ]),
76
+ )
77
+
78
+ return to_object
79
+
80
+
66
81
def _CreateAgentEngineConfig_to_vertex (
67
82
from_object : Union [dict [str , Any ], object ],
68
83
parent_object : Optional [dict [str , Any ]] = None ,
@@ -82,6 +97,15 @@ def _CreateAgentEngineConfig_to_vertex(
82
97
_ReasoningEngineSpec_to_vertex (getv (from_object , ["spec" ]), to_object ),
83
98
)
84
99
100
+ if getv (from_object , ["context_spec" ]) is not None :
101
+ setv (
102
+ parent_object ,
103
+ ["contextSpec" ],
104
+ _ReasoningEngineContextSpec_to_vertex (
105
+ getv (from_object , ["context_spec" ]), to_object
106
+ ),
107
+ )
108
+
85
109
return to_object
86
110
87
111
@@ -550,6 +574,15 @@ def _UpdateAgentEngineConfig_to_vertex(
550
574
_ReasoningEngineSpec_to_vertex (getv (from_object , ["spec" ]), to_object ),
551
575
)
552
576
577
+ if getv (from_object , ["context_spec" ]) is not None :
578
+ setv (
579
+ parent_object ,
580
+ ["contextSpec" ],
581
+ _ReasoningEngineContextSpec_to_vertex (
582
+ getv (from_object , ["context_spec" ]), to_object
583
+ ),
584
+ )
585
+
553
586
if getv (from_object , ["update_mask" ]) is not None :
554
587
setv (
555
588
parent_object ,
@@ -1976,6 +2009,10 @@ def create(
1976
2009
"config must be a dict or AgentEngineConfig, but got"
1977
2010
f" { type (config )} ."
1978
2011
)
2012
+ context_spec = config .context_spec
2013
+ if context_spec is not None :
2014
+ # Conversion to a dict for _create_config
2015
+ context_spec = context_spec .model_dump ()
1979
2016
api_config = self ._create_config (
1980
2017
mode = "create" ,
1981
2018
agent_engine = agent_engine ,
@@ -1986,6 +2023,7 @@ def create(
1986
2023
gcs_dir_name = config .gcs_dir_name ,
1987
2024
extra_packages = config .extra_packages ,
1988
2025
env_vars = config .env_vars ,
2026
+ context_spec = context_spec ,
1989
2027
)
1990
2028
operation = self ._create (config = api_config )
1991
2029
# TODO: Use a more specific link.
@@ -2029,6 +2067,7 @@ def _create_config(
2029
2067
gcs_dir_name : Optional [str ] = None ,
2030
2068
extra_packages : Optional [Sequence [str ]] = None ,
2031
2069
env_vars : Optional [dict [str , Union [str , Any ]]] = None ,
2070
+ context_spec : Optional [dict [str , Any ]] = None ,
2032
2071
):
2033
2072
import sys
2034
2073
from vertexai .agent_engines import _agent_engines
@@ -2049,6 +2088,8 @@ def _create_config(
2049
2088
if description is not None :
2050
2089
update_masks .append ("description" )
2051
2090
config ["description" ] = description
2091
+ if context_spec is not None :
2092
+ config ["context_spec" ] = context_spec
2052
2093
if agent_engine is not None :
2053
2094
sys_version = f"{ sys .version_info .major } .{ sys .version_info .minor } "
2054
2095
gcs_dir_name = gcs_dir_name or _agent_engines ._DEFAULT_GCS_DIR_NAME
@@ -2307,6 +2348,10 @@ def update(
2307
2348
"config must be a dict or AgentEngineConfig, but got"
2308
2349
f" { type (config )} ."
2309
2350
)
2351
+ context_spec = config .context_spec
2352
+ if context_spec is not None :
2353
+ # Conversion to a dict for _create_config
2354
+ context_spec = context_spec .model_dump ()
2310
2355
api_config = self ._create_config (
2311
2356
mode = "update" ,
2312
2357
agent_engine = agent_engine ,
@@ -2317,6 +2362,7 @@ def update(
2317
2362
gcs_dir_name = config .gcs_dir_name ,
2318
2363
extra_packages = config .extra_packages ,
2319
2364
env_vars = config .env_vars ,
2365
+ context_spec = context_spec ,
2320
2366
)
2321
2367
operation = self ._update (name = name , config = api_config )
2322
2368
logger .info (
0 commit comments