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.

remove lettaresponse spec hardcode and add references to pydantic

Caren Thomas7141e5909dca
diff --git a/letta/schemas/letta_response.py b/letta/schemas/letta_response.py
index c6a1e8be5..d12b2dc7a 100644
--- a/letta/schemas/letta_response.py
+++ b/letta/schemas/letta_response.py
@@ -23,8 +23,32 @@ class LettaResponse(BaseModel):
usage (LettaUsageStatistics): The usage statistics
"""
- messages: List[LettaMessageUnion] = Field(..., description="The messages returned by the agent.")
- usage: LettaUsageStatistics = Field(..., description="The usage statistics of the agent.")
+ messages: List[LettaMessageUnion] = Field(
+ ...,
+ description="The messages returned by the agent.",
+ json_schema_extra={
+ "items": {
+ "oneOf": [
+ {"x-ref-name": "SystemMessage"},
+ {"x-ref-name": "UserMessage"},
+ {"x-ref-name": "ReasoningMessage"},
+ {"x-ref-name": "ToolCallMessage"},
+ {"x-ref-name": "ToolReturnMessage"},
+ {"x-ref-name": "AssistantMessage"}
+ ],
+ "discriminator": {
+ "propertyName": "message_type"
+ }
+ }
+ }
+ )
+ usage: LettaUsageStatistics = Field(
+ ...,
+ description="The usage statistics of the agent.",
+ json_schema_extra={
+ "x-ref-name": "LettaUsageStatistics"
+ }
+ )
def __str__(self):
return json_dumps(
diff --git a/letta/server/rest_api/app.py b/letta/server/rest_api/app.py
index 8e2b7fb74..a8d31df49 100644
--- a/letta/server/rest_api/app.py
+++ b/letta/server/rest_api/app.py
@@ -68,9 +68,6 @@ def generate_openapi_schema(app: FastAPI):
openai_docs["info"]["title"] = "OpenAI Assistants API"
letta_docs["paths"] = {k: v for k, v in letta_docs["paths"].items() if not k.startswith("/openai")}
letta_docs["info"]["title"] = "Letta API"
- letta_docs["components"]["schemas"]["LettaResponse"] = {
- "properties": LettaResponse.model_json_schema(ref_template="#/components/schemas/LettaResponse/properties/{model}")["$defs"]
- }
# Split the API docs into Letta API, and OpenAI Assistants compatible API
for name, docs in [