Building AI agents, atomically
resolved comments
Arun Rajkumarcc3f15f35fa6
diff --git a/atomic-agents/atomic_agents/lib/components/agent_memory.py b/atomic-agents/atomic_agents/lib/components/agent_memory.pyindex d4091f6..fd7bdab 100644--- a/atomic-agents/atomic_agents/lib/components/agent_memory.py+++ b/atomic-agents/atomic_agents/lib/components/agent_memory.py@@ -112,9 +112,9 @@ class AgentMemory:"""return self.current_turn_id- def delete_turn_id(self, turn_id: int) -> str:+ def delete_turn_id(self, turn_id: int):"""- Delete a message from the memory by its turn ID.+ Delete messages from the memory by its turn ID.Args:turn_id (int): The turn ID of the message to delete.@@ -132,14 +132,12 @@ class AgentMemory:raise ValueError(f"Turn ID {turn_id} not found in memory.")# Update current_turn_id if necessary- if not self.history:+ if not len(self.history):self.current_turn_id = Noneelif turn_id == self.current_turn_id:# Always update to the last message's turn_idself.current_turn_id = self.history[-1].turn_id- return f"Successfully deleted message with turn ID {turn_id}."-def get_message_count(self) -> int:"""Returns the number of messages in the chat history.diff --git a/atomic-agents/tests/lib/components/test_agent_memory.py b/atomic-agents/tests/lib/components/test_agent_memory.pyindex c6eca9e..11c37ba 100644--- a/atomic-agents/tests/lib/components/test_agent_memory.py+++ b/atomic-agents/tests/lib/components/test_agent_memory.py@@ -248,10 +248,11 @@ def test_serialize_non_baseioschema():result = memory._serialize_content("Not a BaseIOSchema")assert result == "Not a BaseIOSchema"+def test_agent_memory_delete_turn_id(memory):mock_input = TestInputSchema(test_field="Test input")mock_output = TestInputSchema(test_field="Test output")-+memory = AgentMemory()initial_turn_id = "123-456"memory.current_turn_id = initial_turn_id@@ -259,10 +260,10 @@ def test_agent_memory_delete_turn_id(memory):# Add a message with a specific turn IDmemory.add_message("user",- mock_input,+ mock_input,)memory.history[-1].turn_id = initial_turn_id-+# Add another message with a different turn IDother_turn_id = "789-012"memory.add_message(@@ -270,10 +271,9 @@ def test_agent_memory_delete_turn_id(memory):mock_output,)memory.history[-1].turn_id = other_turn_id-+# Act & Assert: Delete the message with initial_turn_id and verify- success_message = memory.delete_turn_id(initial_turn_id)- assert success_message == f"Successfully deleted message with turn ID {initial_turn_id}."+ memory.delete_turn_id(initial_turn_id)# The remaining message in memory should have the other_turn_idassert len(memory.history) == 1@@ -286,4 +286,4 @@ def test_agent_memory_delete_turn_id(memory):# Assert: Trying to delete a non-existing turn ID should raise a ValueErrorwith pytest.raises(ValueError, match="Turn ID non-existent-id not found in memory."):- memory.delete_turn_id("non-existent-id")\ No newline at end of file+ memory.delete_turn_id("non-existent-id")