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.

feat: move keepalive to an arg (#3652)

Charles Packera13c6c78bb53
diff --git a/letta/schemas/letta_request.py b/letta/schemas/letta_request.py
index cdaf27c18..5f16380a8 100644
--- a/letta/schemas/letta_request.py
+++ b/letta/schemas/letta_request.py
@@ -42,6 +42,10 @@ class LettaStreamingRequest(LettaRequest):
default=False,
description="Flag to determine if individual tokens should be streamed. Set to True for token streaming (requires stream_steps = True).",
)
+ include_pings: bool = Field(
+ default=False,
+ description="Whether to include periodic keepalive ping messages in the stream to prevent connection timeouts.",
+ )
class LettaAsyncRequest(LettaRequest):
diff --git a/letta/server/rest_api/routers/v1/agents.py b/letta/server/rest_api/routers/v1/agents.py
index 387732cf9..b146585de 100644
--- a/letta/server/rest_api/routers/v1/agents.py
+++ b/letta/server/rest_api/routers/v1/agents.py
@@ -1071,8 +1071,8 @@ async def send_message_streaming(
request_start_timestamp_ns=request_start_timestamp_ns,
include_return_message_types=request.include_return_message_types,
)
- # Conditionally wrap with keepalive based on settings
- if settings.enable_keepalive:
+ # Conditionally wrap with keepalive based on request parameter
+ if request.include_pings and settings.enable_keepalive:
stream = add_keepalive_to_stream(raw_stream, keepalive_interval=settings.keepalive_interval)
else:
stream = raw_stream
@@ -1089,8 +1089,8 @@ async def send_message_streaming(
request_start_timestamp_ns=request_start_timestamp_ns,
include_return_message_types=request.include_return_message_types,
)
- # Conditionally wrap with keepalive based on settings
- if settings.enable_keepalive:
+ # Conditionally wrap with keepalive based on request parameter
+ if request.include_pings and settings.enable_keepalive:
stream = add_keepalive_to_stream(raw_stream, keepalive_interval=settings.keepalive_interval)
else:
stream = raw_stream