Skip to content

Commit 30cacc3

Browse files
authored
feat: move keepalive to an arg (#3652)
1 parent d8dd9be commit 30cacc3

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

letta/schemas/letta_request.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ class LettaStreamingRequest(LettaRequest):
4242
default=False,
4343
description="Flag to determine if individual tokens should be streamed. Set to True for token streaming (requires stream_steps = True).",
4444
)
45+
include_pings: bool = Field(
46+
default=False,
47+
description="Whether to include periodic keepalive ping messages in the stream to prevent connection timeouts.",
48+
)
4549

4650

4751
class LettaAsyncRequest(LettaRequest):

letta/server/rest_api/routers/v1/agents.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,8 +1071,8 @@ async def send_message_streaming(
10711071
request_start_timestamp_ns=request_start_timestamp_ns,
10721072
include_return_message_types=request.include_return_message_types,
10731073
)
1074-
# Conditionally wrap with keepalive based on settings
1075-
if settings.enable_keepalive:
1074+
# Conditionally wrap with keepalive based on request parameter
1075+
if request.include_pings and settings.enable_keepalive:
10761076
stream = add_keepalive_to_stream(raw_stream, keepalive_interval=settings.keepalive_interval)
10771077
else:
10781078
stream = raw_stream
@@ -1089,8 +1089,8 @@ async def send_message_streaming(
10891089
request_start_timestamp_ns=request_start_timestamp_ns,
10901090
include_return_message_types=request.include_return_message_types,
10911091
)
1092-
# Conditionally wrap with keepalive based on settings
1093-
if settings.enable_keepalive:
1092+
# Conditionally wrap with keepalive based on request parameter
1093+
if request.include_pings and settings.enable_keepalive:
10941094
stream = add_keepalive_to_stream(raw_stream, keepalive_interval=settings.keepalive_interval)
10951095
else:
10961096
stream = raw_stream

0 commit comments

Comments
 (0)