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: fix manual summarization (#6466)

Sarah Wooders90e2030f4131
diff --git a/letta/agents/letta_agent_v2.py b/letta/agents/letta_agent_v2.py
index 7b2723b30..3969a8f1d 100644
--- a/letta/agents/letta_agent_v2.py
+++ b/letta/agents/letta_agent_v2.py
@@ -1208,6 +1208,7 @@ class LettaAgentV2(BaseAgentV2):
total_tokens: int | None = None,
force: bool = False,
) -> list[Message]:
+ self.logger.warning("Running deprecated v2 summarizer. This should be removed in the future.")
# always skip summarization if last message is an approval request message
skip_summarization = False
latest_messages = in_context_messages + new_letta_messages
diff --git a/letta/server/rest_api/routers/v1/agents.py b/letta/server/rest_api/routers/v1/agents.py
index 7e8330c98..be46a2d7e 100644
--- a/letta/server/rest_api/routers/v1/agents.py
+++ b/letta/server/rest_api/routers/v1/agents.py
@@ -16,6 +16,7 @@ from letta.agents.agent_loop import AgentLoop
from letta.agents.base_agent_v2 import BaseAgentV2
from letta.agents.letta_agent import LettaAgent
from letta.agents.letta_agent_v2 import LettaAgentV2
+from letta.agents.letta_agent_v3 import LettaAgentV3
from letta.constants import DEFAULT_MAX_STEPS, DEFAULT_MESSAGE_TOOL, DEFAULT_MESSAGE_TOOL_KWARG, REDIS_RUN_ID_PREFIX
from letta.data_sources.redis_client import get_redis_client
from letta.errors import (
@@ -2107,7 +2108,7 @@ async def summarize_messages(
]
if agent_eligible and model_compatible:
- agent_loop = LettaAgentV2(agent_state=agent, actor=actor)
+ agent_loop = LettaAgentV3(agent_state=agent, actor=actor)
in_context_messages = await server.message_manager.get_messages_by_ids_async(message_ids=agent.message_ids, actor=actor)
await agent_loop.summarize_conversation_history(
in_context_messages=in_context_messages,
diff --git a/letta/services/summarizer/summarizer_sliding_window.py b/letta/services/summarizer/summarizer_sliding_window.py
index 29c530a9d..e1f9f3504 100644
--- a/letta/services/summarizer/summarizer_sliding_window.py
+++ b/letta/services/summarizer/summarizer_sliding_window.py
@@ -80,6 +80,10 @@ async def summarize_via_sliding_window(
# Mark the approximate cutoff
message_cutoff_index = round(message_count_cutoff_percent * len(all_in_context_messages))
+ # we've reached the maximum message cutoff
+ if message_cutoff_index >= total_message_count:
+ break
+
# Walk up the list until we find the first assistant message
for i in range(message_cutoff_index, total_message_count):
if all_in_context_messages[i].role == MessageRole.assistant: