Skip to content

Commit ddbc4d2

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
fix: Support ref and def for memory schemas
PiperOrigin-RevId: 940680657
1 parent 7f7c40f commit ddbc4d2

4 files changed

Lines changed: 820 additions & 278 deletions

File tree

agentplatform/_genai/agent_engines.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,6 +2272,27 @@ def _set_package_spec(
22722272
for class_method_spec in class_methods_spec_list
22732273
]
22742274

2275+
def _resolve_context_spec(
2276+
self, *, context_spec: Optional[types.ReasoningEngineContextSpecDict] = None
2277+
) -> Optional[types.ReasoningEngineContextSpecDict]:
2278+
if context_spec is None:
2279+
return None
2280+
context_spec_obj = types.ReasoningEngineContextSpec(**context_spec)
2281+
if context_spec_obj.memory_bank_config is None:
2282+
return context_spec
2283+
for schema in context_spec_obj.memory_bank_config.structured_memory_configs:
2284+
for schema_config in schema.schema_configs:
2285+
if not schema_config.memory_json_schema:
2286+
continue
2287+
# `from_json_schema` handles the resolution of `$ref` paths.
2288+
schema_config.memory_schema = genai_types.Schema.from_json_schema(
2289+
json_schema=genai_types.JSONSchema(
2290+
**schema_config.memory_json_schema
2291+
)
2292+
)
2293+
2294+
return json.loads(context_spec_obj.model_dump_json())
2295+
22752296
def _create_config(
22762297
self,
22772298
*,
@@ -2338,6 +2359,7 @@ def _create_config(
23382359
config["description"] = description
23392360
if context_spec is not None:
23402361
update_masks.append("context_spec")
2362+
context_spec = self._resolve_context_spec(context_spec=context_spec)
23412363
config["context_spec"] = context_spec
23422364
if encryption_spec is not None:
23432365
update_masks.append("encryption_spec")
@@ -2720,6 +2742,9 @@ def update(
27202742
IOError: If `config.requirements` is a string that corresponds to a
27212743
nonexistent file.
27222744
"""
2745+
# Access context spec if available and convert to dict.
2746+
# "Fix" context spec if needed.
2747+
# Then run model_validate.
27232748
if isinstance(config, dict):
27242749
config = types.AgentEngineConfig.model_validate(config)
27252750
elif not isinstance(config, types.AgentEngineConfig):

0 commit comments

Comments
 (0)