Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

Fix:if window_size==0 will return all the sliding_messages. (#3726)

jinghuan-Chencec314c4623e
diff --git a/camel/memories/blocks/chat_history_block.py b/camel/memories/blocks/chat_history_block.py
index ad46dedf5..0f10ff1cd 100644
--- a/camel/memories/blocks/chat_history_block.py
+++ b/camel/memories/blocks/chat_history_block.py
@@ -111,7 +111,9 @@ class ChatHistoryBlock(MemoryBlock):
] # Messages to be truncated
# Take last window_size messages (if exceeds limit)
- truncated_messages = sliding_messages[-window_size:]
+ truncated_messages = (
+ [] if window_size == 0 else sliding_messages[-window_size:]
+ )
# Combine preserved messages with truncated window messages
final_records = preserved_messages + truncated_messages
diff --git a/test/memories/test_blocks.py b/test/memories/test_blocks.py
index 785abca76..b8952b73c 100644
--- a/test/memories/test_blocks.py
+++ b/test/memories/test_blocks.py
@@ -75,6 +75,14 @@ class TestChatHistoryBlock:
assert all(isinstance(record, ContextRecord) for record in records)
assert len(records) == 5
+ def test_retrieve_with_zero_window_size(self, mock_storage):
+ mock_records = generate_mock_records(3)
+ mock_storage.load.return_value = mock_records
+ chat_history = ChatHistoryBlock(storage=mock_storage)
+
+ records = chat_history.retrieve(window_size=0)
+ assert records == []
+
def test_retrieve_without_window_size(self, mock_storage):
mock_records = generate_mock_records(10)
mock_storage.load.return_value = mock_records