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.

fix: incorrect stop reasons (#6539)

cthomas2116a0770661
diff --git a/letta/agents/letta_agent_v3.py b/letta/agents/letta_agent_v3.py
index db97b15ff..9b6175bb0 100644
--- a/letta/agents/letta_agent_v3.py
+++ b/letta/agents/letta_agent_v3.py
@@ -176,6 +176,9 @@ class LettaAgentV3(LettaAgentV2):
input_messages_to_persist = []
+ if i == max_steps - 1 and self.stop_reason is None:
+ self.stop_reason = LettaStopReason(stop_reason=StopReasonType.max_steps.value)
+
# Rebuild context window after stepping (safety net)
if not self.agent_state.message_buffer_autoclear:
if self.context_token_estimate is not None:
@@ -313,9 +316,10 @@ class LettaAgentV3(LettaAgentV2):
input_messages_to_persist = []
- if self.stop_reason is None:
- self.stop_reason = LettaStopReason(stop_reason=StopReasonType.max_steps.value)
+ if i == max_steps - 1 and self.stop_reason is None:
+ self.stop_reason = LettaStopReason(stop_reason=StopReasonType.max_steps.value)
+ # Rebuild context window after stepping (safety net)
if not self.agent_state.message_buffer_autoclear:
if self.context_token_estimate is not None:
await self.summarize_conversation_history(
@@ -330,6 +334,9 @@ class LettaAgentV3(LettaAgentV2):
"No step completed successfully or usage stats were not updated."
)
+ if self.stop_reason is None:
+ self.stop_reason = LettaStopReason(stop_reason=StopReasonType.end_turn.value)
+
except Exception as e:
self.logger.warning(f"Error during agent stream: {e}", exc_info=True)