Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
fix: remove `no_commit=True` for sleeptime block patch and add client tests (#3057)
Sarah Wooders506d51bb0b52
diff --git a/letta/services/agent_manager.py b/letta/services/agent_manager.pyindex ace03bbf9..29d641fee 100644--- a/letta/services/agent_manager.py+++ b/letta/services/agent_manager.py@@ -2028,6 +2028,7 @@ class AgentManager:# Attach block to the main agentagent.core_memory.append(block)+ # await agent.update_async(session, actor=actor, no_commit=True)await agent.update_async(session)# If agent is part of a sleeptime group, attach block to the sleeptime_agent@@ -2040,7 +2041,8 @@ class AgentManager: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, no_commit=True)+ await other_agent.update_async(session, actor=actor)except NoResultFound:# Agent might not exist anymore, skipcontinuediff --git a/tests/test_client.py b/tests/test_client.pyindex 7fbfe6e64..d873dd7bb 100644--- a/tests/test_client.py+++ b/tests/test_client.py@@ -686,3 +686,34 @@ def test_timezone(client: Letta):or "PDT" in response.messages[1].contentor "PST" in response.messages[1].content)+++def test_attach_sleeptime_block(client: Letta):++ agent = client.agents.create(+ memory_blocks=[{"label": "human", "value": ""}, {"label": "persona", "value": ""}],+ model="letta/letta-free",+ embedding="letta/letta-free",+ enable_sleeptime=True,+ )++ # get the sleeptime agent+ # get the multi-agent group+ group_id = agent.multi_agent_group.id+ group = client.groups.retrieve(group_id=group_id)+ agent_ids = group.agent_ids+ sleeptime_id = [id for id in agent_ids if id != agent.id][0]++ # attach a new block+ block = client.blocks.create(label="test", value="test")+ client.agents.blocks.attach(agent_id=agent.id, block_id=block.id)++ # verify block is attached to both agents+ blocks = client.agents.blocks.list(agent_id=agent.id)+ assert block.id in [b.id for b in blocks]++ blocks = client.agents.blocks.list(agent_id=sleeptime_id)+ assert block.id in [b.id for b in blocks]++ # cleanup+ client.agents.delete(agent.id)