Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: add LettaPing to streaming response (#3647)
cthomas047065d6436e
diff --git a/letta/__init__.py b/letta/__init__.pyindex 0ec0749e5..7e32864f3 100644--- a/letta/__init__.py+++ b/letta/__init__.py@@ -24,6 +24,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_ping import LettaPingfrom letta.schemas.letta_stop_reason import LettaStopReasonfrom letta.schemas.llm_config import LLMConfigfrom letta.schemas.memory import ArchivalMemorySummary, BasicBlockMemory, ChatMemory, Memory, RecallMemorySummarydiff --git a/letta/schemas/letta_ping.py b/letta/schemas/letta_ping.pynew file mode 100644index 000000000..05ba9c65a--- /dev/null+++ b/letta/schemas/letta_ping.py@@ -0,0 +1,28 @@+from typing import Literal++from pydantic import BaseModel, Field+++def create_letta_ping_schema():+ return {+ "properties": {+ "message_type": {+ "type": "string",+ "const": "ping",+ "title": "Message Type",+ "description": "The type of the message.",+ "default": "ping",+ }+ },+ "type": "object",+ "required": ["message_type"],+ "title": "LettaPing",+ "description": "Ping messages are a keep-alive to prevent SSE streams from timing out during long running requests.",+ }+++class LettaPing(BaseModel):+ message_type: Literal["ping"] = Field(+ "ping",+ description="The type of the message. Ping messages are a keep-alive to prevent SSE streams from timing out during long running requests.",+ )diff --git a/letta/schemas/letta_stop_reason.py b/letta/schemas/letta_stop_reason.pyindex ab37ef192..8a0955f72 100644--- a/letta/schemas/letta_stop_reason.py+++ b/letta/schemas/letta_stop_reason.py@@ -38,3 +38,28 @@ class LettaStopReason(BaseModel):message_type: Literal["stop_reason"] = Field("stop_reason", description="The type of the message.")stop_reason: StopReasonType = Field(..., description="The reason why execution stopped.")+++def create_letta_ping_schema():+ return {+ "properties": {+ "message_type": {+ "type": "string",+ "const": "ping",+ "title": "Message Type",+ "description": "The type of the message.",+ "default": "ping",+ }+ },+ "type": "object",+ "required": ["message_type"],+ "title": "LettaPing",+ "description": "Ping messages are a keep-alive to prevent SSE streams from timing out during long running requests.",+ }+++class LettaPing(BaseModel):+ message_type: Literal["ping"] = Field(+ "ping",+ description="The type of the message. Ping messages are a keep-alive to prevent SSE streams from timing out during long running requests.",+ )diff --git a/letta/server/rest_api/app.py b/letta/server/rest_api/app.pyindex c12b722b0..b66afe5f4 100644--- a/letta/server/rest_api/app.py+++ b/letta/server/rest_api/app.py@@ -28,6 +28,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_ping import create_letta_ping_schemafrom letta.server.constants import REST_DEFAULT_PORTfrom letta.server.db import db_registry@@ -67,6 +68,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"]["LettaPing"] = create_letta_ping_schema()# Update the app's schema with our modified versionapp.openapi_schema = letta_docs