Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

fix: Handle list[str] in function schema(continuation) (#1110)

palandovalex474a4d0f2126
diff --git a/memgpt/functions/schema_generator.py b/memgpt/functions/schema_generator.py
index aa1a6ac2e..189d0dfd5 100644
--- a/memgpt/functions/schema_generator.py
+++ b/memgpt/functions/schema_generator.py
@@ -1,6 +1,6 @@
import inspect
import typing
-from typing import get_args
+from typing import get_args, get_origin
from docstring_parser import parse
from pydantic import BaseModel
@@ -46,6 +46,7 @@ def type_to_json_schema_type(py_type):
str: "string",
bool: "boolean",
float: "number",
+ list[str]: "array",
# Add more mappings as needed
}
if py_type not in type_map:
@@ -121,6 +122,13 @@ def generate_schema(function):
if param.default == inspect.Parameter.empty:
schema["parameters"]["required"].append(param.name)
+ if get_origin(param.annotation) is list:
+ if get_args(param.annotation)[0] is str:
+ schema["parameters"]["properties"][param.name]["items"] = {"type": "string"}
+
+ if param.annotation == inspect.Parameter.empty:
+ schema["parameters"]["required"].append(param.name)
+
# append the heartbeat
if function.__name__ not in NO_HEARTBEAT_FUNCTIONS:
schema["parameters"]["properties"][FUNCTION_PARAM_NAME_REQ_HEARTBEAT] = {