From a9c6537bf2bbe1f7edd9e2556210bc1ac2e778e6 Mon Sep 17 00:00:00 2001 From: Matthew Zhou Date: Tue, 8 Apr 2025 16:22:53 -0700 Subject: [PATCH] fix: Fix tool schema tests (#1633) --- letta/functions/helpers.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/letta/functions/helpers.py b/letta/functions/helpers.py index d23e3031..2b2cf149 100644 --- a/letta/functions/helpers.py +++ b/letta/functions/helpers.py @@ -629,8 +629,22 @@ def _get_field_type(field_schema: Dict[str, Any], nested_models: Dict[str, Type[ if nested_models and ref_type in nested_models: return nested_models[ref_type] elif "additionalProperties" in field_schema: - value_type = _get_field_type(field_schema["additionalProperties"], nested_models) - return Dict[str, value_type] + # TODO: This is totally GPT generated and I'm not sure it works + # TODO: This is done to quickly patch some tests, we should nuke this whole pathway asap + ap = field_schema["additionalProperties"] + + if ap is True: + return dict + elif ap is False: + raise ValueError("additionalProperties=false is not supported.") + else: + # Try resolving nested type + nested_type = _get_field_type(ap, nested_models) + # If nested_type is Any, fall back to `dict`, or raise, depending on how strict you want to be + if nested_type == Any: + return dict + return Dict[str, nested_type] + return dict elif field_schema.get("$ref") is not None: ref_type = field_schema["$ref"].split("/")[-1]