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: recompile system message in agent loop (#1875)

cthomas2985ca2ca892
diff --git a/letta/agent.py b/letta/agent.py
index a6742b257..3960ade6a 100644
--- a/letta/agent.py
+++ b/letta/agent.py
@@ -190,16 +190,15 @@ class Agent(BaseAgent):
Returns:
modified (bool): whether the memory was updated
"""
- if self.agent_state.memory.compile() != new_memory.compile():
+ system_message = self.message_manager.get_message_by_id(message_id=self.agent_state.message_ids[0], actor=self.user)
+ if new_memory.compile() not in system_message.content[0].text:
# update the blocks (LRW) in the DB
for label in self.agent_state.memory.list_block_labels():
updated_value = new_memory.get_block(label).value
if updated_value != self.agent_state.memory.get_block(label).value:
# update the block if it's changed
block_id = self.agent_state.memory.get_block(label).id
- block = self.block_manager.update_block(
- block_id=block_id, block_update=BlockUpdate(value=updated_value), actor=self.user
- )
+ self.block_manager.update_block(block_id=block_id, block_update=BlockUpdate(value=updated_value), actor=self.user)
# refresh memory from DB (using block ids)
self.agent_state.memory = Memory(
diff --git a/letta/services/agent_manager.py b/letta/services/agent_manager.py
index aa94dae6c..e68ac4432 100644
--- a/letta/services/agent_manager.py
+++ b/letta/services/agent_manager.py
@@ -931,7 +931,8 @@ class AgentManager:
modified (bool): whether the memory was updated
"""
agent_state = self.get_agent_by_id(agent_id=agent_id, actor=actor)
- if agent_state.memory.compile() != new_memory.compile():
+ system_message = self.message_manager.get_message_by_id(message_id=agent_state.message_ids[0], actor=actor)
+ if new_memory.compile() not in system_message.content[0].text:
# update the blocks (LRW) in the DB
for label in agent_state.memory.list_block_labels():
updated_value = new_memory.get_block(label).value