From 2985ca2ca892902cfda3fc478019f82e4f89be37 Mon Sep 17 00:00:00 2001 From: cthomas Date: Thu, 24 Apr 2025 13:27:05 -0700 Subject: [PATCH] fix: recompile system message in agent loop (#1875) --- letta/agent.py | 7 +++---- letta/services/agent_manager.py | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/letta/agent.py b/letta/agent.py index a6742b25..3960ade6 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 aa94dae6..e68ac443 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