fix: sleeptime agents are broken [LET-6042] (#5953)

minimal solution
This commit is contained in:
Ari Webb
2025-11-04 17:31:31 -08:00
committed by Caren Thomas
parent 546c972d2e
commit 162661457a
2 changed files with 30 additions and 24 deletions

View File

@@ -81,18 +81,21 @@ class SleeptimeMultiAgentV3(LettaAgentV2):
input_messages[i].group_id = self.group.id
# Perform foreground agent step
async for chunk in super().stream(
input_messages=input_messages,
max_steps=max_steps,
stream_tokens=stream_tokens,
run_id=run_id,
use_assistant_message=use_assistant_message,
include_return_message_types=include_return_message_types,
request_start_timestamp_ns=request_start_timestamp_ns,
):
yield chunk
await self.run_sleeptime_agents()
try:
async for chunk in super().stream(
input_messages=input_messages,
max_steps=max_steps,
stream_tokens=stream_tokens,
run_id=run_id,
use_assistant_message=use_assistant_message,
include_return_message_types=include_return_message_types,
request_start_timestamp_ns=request_start_timestamp_ns,
):
yield chunk
finally:
# For some reason, stream is throwing a GeneratorExit even though it appears the that client
# is getting the whole stream. This pattern should work to ensure sleeptime agents run despite this.
await self.run_sleeptime_agents()
@trace_method
async def run_sleeptime_agents(self):

View File

@@ -80,18 +80,21 @@ class SleeptimeMultiAgentV4(LettaAgentV3):
input_messages[i].group_id = self.group.id
# Perform foreground agent step
async for chunk in super().stream(
input_messages=input_messages,
max_steps=max_steps,
stream_tokens=stream_tokens,
run_id=run_id,
use_assistant_message=use_assistant_message,
include_return_message_types=include_return_message_types,
request_start_timestamp_ns=request_start_timestamp_ns,
):
yield chunk
await self.run_sleeptime_agents()
try:
async for chunk in super().stream(
input_messages=input_messages,
max_steps=max_steps,
stream_tokens=stream_tokens,
run_id=run_id,
use_assistant_message=use_assistant_message,
include_return_message_types=include_return_message_types,
request_start_timestamp_ns=request_start_timestamp_ns,
):
yield chunk
finally:
# For some reason, stream is throwing a GeneratorExit even though it appears the that client
# is getting the whole stream. This pattern should work to ensure sleeptime agents run despite this.
await self.run_sleeptime_agents()
@trace_method
async def run_sleeptime_agents(self) -> list[str]: