Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: add stop reason object (#2783)
cthomasa43be2b377db
diff --git a/letta/__init__.py b/letta/__init__.pyindex 1d620eb76..6cc0e81b9 100644--- a/letta/__init__.py+++ b/letta/__init__.py@@ -17,6 +17,7 @@ from letta.schemas.enums import JobStatusfrom letta.schemas.file import FileMetadatafrom letta.schemas.job import Jobfrom letta.schemas.letta_message import LettaMessage+from letta.schemas.letta_stop_reason import LettaStopReasonfrom letta.schemas.llm_config import LLMConfigfrom letta.schemas.memory import ArchivalMemorySummary, BasicBlockMemory, ChatMemory, Memory, RecallMemorySummaryfrom letta.schemas.message import Messagediff --git a/letta/schemas/letta_stop_reason.py b/letta/schemas/letta_stop_reason.pynew file mode 100644index 000000000..e5c65a3bd--- /dev/null+++ b/letta/schemas/letta_stop_reason.py@@ -0,0 +1,44 @@+from enum import Enum+from typing import Literal++from pydantic import BaseModel, Field+++class StopReasonType(str, Enum):+ end_turn = "end_turn"+ error = "error"+ invalid_tool_call = "invalid_tool_call"+ max_steps = "max_steps"+ no_tool_call = "no_tool_call"+++class LettaStopReason(BaseModel):+ """+ The stop reason from letta used during streaming response.+ """++ message_type: Literal["stop_reason"] = "stop_reason"+ stop_reason: StopReasonType = Field(..., description="The type of the message.")+++def create_letta_stop_reason_schema():+ return {+ "properties": {+ "message_type": {+ "type": "string",+ "const": "stop_reason",+ "title": "Message Type",+ "description": "The type of the message.",+ "default": "stop_reason",+ },+ "stop_reason": {+ "type": "string",+ "enum": list(StopReasonType.__members__.keys()),+ "title": "Stop Reason",+ },+ },+ "type": "object",+ "required": ["stop_reason"],+ "title": "LettaStopReason",+ "description": "Letta provided stop reason for why agent loop ended.",+ }diff --git a/letta/server/rest_api/app.py b/letta/server/rest_api/app.pyindex 7c249087b..5d166c67a 100644--- a/letta/server/rest_api/app.py+++ b/letta/server/rest_api/app.py@@ -24,6 +24,7 @@ from letta.schemas.letta_message_content import (create_letta_message_content_union_schema,create_letta_user_message_content_union_schema,)+from letta.schemas.letta_stop_reason import create_letta_stop_reason_schemafrom letta.server.constants import REST_DEFAULT_PORT# NOTE(charles): these are extra routes that are not part of v1 but we still need to mount to pass tests@@ -68,6 +69,7 @@ def generate_openapi_schema(app: FastAPI):letta_docs["components"]["schemas"]["LettaMessageContentUnion"] = create_letta_message_content_union_schema()letta_docs["components"]["schemas"]["LettaAssistantMessageContentUnion"] = create_letta_assistant_message_content_union_schema()letta_docs["components"]["schemas"]["LettaUserMessageContentUnion"] = create_letta_user_message_content_union_schema()+ letta_docs["components"]["schemas"]["LettaStopReason"] = create_letta_stop_reason_schema()# Update the app's schema with our modified versionapp.openapi_schema = letta_docs