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: prevent duplicate block attachment in sleeptime agents (#9150)

Kian Jones42b1e741dc69
diff --git a/letta/services/agent_manager.py b/letta/services/agent_manager.py
index f78744751..c8c656a8b 100644
--- a/letta/services/agent_manager.py
+++ b/letta/services/agent_manager.py
@@ -2042,10 +2042,12 @@ class AgentManager:
if other_agent_id != agent_id:
try:
other_agent = await AgentModel.read_async(db_session=session, identifier=other_agent_id, actor=actor)
- if other_agent.agent_type == AgentType.sleeptime_agent and block not in other_agent.core_memory:
- other_agent.core_memory.append(block)
- # await other_agent.update_async(session, actor=actor, no_commit=True)
- await other_agent.update_async(session, actor=actor)
+ if other_agent.agent_type == AgentType.sleeptime_agent:
+ # Check if block with same label already exists
+ existing_block = next((b for b in other_agent.core_memory if b.label == block.label), None)
+ if not existing_block:
+ other_agent.core_memory.append(block)
+ await other_agent.update_async(session, actor=actor)
except NoResultFound:
# Agent might not exist anymore, skip
continue