🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
Python agentai-societiesartificial-intelligencecommunicative-aicooperative-aideep-learninglarge-language-modelsmulti-agent-systemsnatural-language-processing
chore: Remove warning for ChatAgent empty memory (#3301)
Wendong-Fan552c82b1236b
diff --git a/camel/agents/chat_agent.py b/camel/agents/chat_agent.pyindex df7f9157f..4aeed3111 100644--- a/camel/agents/chat_agent.py+++ b/camel/agents/chat_agent.py@@ -71,7 +71,6 @@ from camel.memories import (MemoryRecord,ScoreBasedContextCreator,)-from camel.memories.blocks.chat_history_block import EmptyMemoryWarningfrom camel.messages import (BaseMessage,FunctionCallingMessage,@@ -877,9 +876,7 @@ class ChatAgent(BaseAgent):[message.to_openai_message(role)])- with warnings.catch_warnings():- warnings.filterwarnings("ignore", category=EmptyMemoryWarning)- _, ctx_tokens = self.memory.get_context()+ _, ctx_tokens = self.memory.get_context()remaining_budget = max(0, token_limit - ctx_tokens)@@ -1104,7 +1101,6 @@ class ChatAgent(BaseAgent):See Also::meth:`asummarize`: Async version for non-blocking LLM calls."""- import warningswarnings.warn("summarize() is synchronous. Consider using asummarize() "@@ -1643,7 +1639,7 @@ class ChatAgent(BaseAgent):message."""self.memory.clear()- # avoid UserWarning: The `ChatHistoryMemory` is empty.+ # Write system message to memory if providedif self.system_message is not None:self.memory.write_record(MemoryRecord(diff --git a/camel/memories/__init__.py b/camel/memories/__init__.pyindex f8b60fb45..44dbae405 100644--- a/camel/memories/__init__.py+++ b/camel/memories/__init__.py@@ -18,7 +18,7 @@ from .agent_memories import (VectorDBMemory,)from .base import AgentMemory, BaseContextCreator, MemoryBlock-from .blocks.chat_history_block import ChatHistoryBlock, EmptyMemoryWarning+from .blocks.chat_history_block import ChatHistoryBlockfrom .blocks.vectordb_block import VectorDBBlockfrom .context_creators.score_based import ScoreBasedContextCreatorfrom .records import ContextRecord, MemoryRecord@@ -35,5 +35,4 @@ __all__ = ['ChatHistoryBlock','VectorDBBlock','LongtermAgentMemory',- 'EmptyMemoryWarning',]diff --git a/camel/memories/blocks/chat_history_block.py b/camel/memories/blocks/chat_history_block.pyindex 502d1dbb6..8beaa909e 100644--- a/camel/memories/blocks/chat_history_block.py+++ b/camel/memories/blocks/chat_history_block.py@@ -11,7 +11,6 @@# See the License for the specific language governing permissions and# limitations under the License.# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========-import warningsfrom typing import List, Optionalfrom camel.memories.base import MemoryBlock@@ -21,17 +20,6 @@ from camel.storages.key_value_storages.in_memory import InMemoryKeyValueStoragefrom camel.types import OpenAIBackendRole-class EmptyMemoryWarning(UserWarning):- """Warning raised when attempting to access an empty memory.-- This warning is raised when operations are performed on memory- that contains no records. It can be safely caught and suppressed- in contexts where empty memory is expected.- """-- pass--class ChatHistoryBlock(MemoryBlock):r"""An implementation of the :obj:`MemoryBlock` abstract base class formaintaining a record of chat histories.@@ -81,11 +69,8 @@ class ChatHistoryBlock(MemoryBlock):"""record_dicts = self.storage.load()if len(record_dicts) == 0:- warnings.warn(- "The `ChatHistoryMemory` is empty.",- EmptyMemoryWarning,- stacklevel=1,- )+ # Empty memory is a valid state (e.g., during initialization).+ # Users can check if memory is empty by checking the returned list.return list()if window_size is not None and window_size >= 0: