🐫 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
fix: Agent can't retrieve the system_msg (#2068)
Rayc55f0914cb8d
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.ymlindex 547e53089..b84140c56 100644--- a/.github/ISSUE_TEMPLATE/bug_report.yml+++ b/.github/ISSUE_TEMPLATE/bug_report.yml@@ -26,7 +26,7 @@ body:attributes:label: What version of camel are you using?description: Run command `python3 -c 'print(__import__("camel").__version__)'` in your shell and paste the output here.- placeholder: E.g., 0.2.40+ placeholder: E.g., 0.2.41validations:required: truediff --git a/camel/__init__.py b/camel/__init__.pyindex bda060103..cc3bfcfdc 100644--- a/camel/__init__.py+++ b/camel/__init__.py@@ -14,7 +14,7 @@from camel.logger import disable_logging, enable_logging, set_log_level-__version__ = '0.2.40'+__version__ = '0.2.41'__all__ = ['__version__',diff --git a/camel/memories/blocks/chat_history_block.py b/camel/memories/blocks/chat_history_block.pyindex b2f3a6dc1..aa2df6533 100644--- a/camel/memories/blocks/chat_history_block.py+++ b/camel/memories/blocks/chat_history_block.py@@ -74,9 +74,52 @@ class ChatHistoryBlock(MemoryBlock):return list()chat_records: List[MemoryRecord] = []- truncate_idx = -window_size if window_size is not None else 0- for record_dict in record_dicts[truncate_idx:]:- chat_records.append(MemoryRecord.from_dict(record_dict))+ if window_size is not None and window_size >= 0:+ # Initial preserved index: Keep first message+ # if it's SYSTEM/DEVELOPER (index 0)+ start_index = (+ 1+ if (+ record_dicts+ and record_dicts[0]['role_at_backend']+ in {OpenAIBackendRole.SYSTEM, OpenAIBackendRole.DEVELOPER}+ )+ else 0+ )++ """+ Message Processing Logic:+ 1. Preserve first system/developer message (if needed)+ 2. Keep latest window_size messages from the rest++ Examples:+ - Case 1: First message is SYSTEM, total 5 messages, window_size=2+ Input: [system_msg, user_msg1, user_msg2, user_msg3, user_msg4]+ Result: [system_msg] + [user_msg3, user_msg4]++ - Case 2: First message is USER, total 5 messages, window_size=3+ Input: [user_msg1, user_msg2, user_msg3, user_msg4, , user_msg5]+ Result: [user_msg3, user_msg4, , user_msg5]+ """+ preserved_messages = record_dicts[+ :start_index+ ] # Preserve system message (if exists)+ sliding_messages = record_dicts[+ start_index:+ ] # Messages to be truncated++ # Take last window_size messages (if exceeds limit)+ truncated_messages = sliding_messages[-window_size:]++ # Combine preserved messages with truncated window messages+ final_records = preserved_messages + truncated_messages+ else:+ # Return full records when no window restriction+ final_records = record_dicts++ chat_records = [+ MemoryRecord.from_dict(record) for record in final_records+ ]# We assume that, in the chat history memory, the closer the record is# to the current message, the more score it will be.diff --git a/camel/types/enums.py b/camel/types/enums.pyindex 0c0f657f0..8a3acf8af 100644--- a/camel/types/enums.py+++ b/camel/types/enums.py@@ -902,6 +902,7 @@ class VectorDistance(Enum):class OpenAIBackendRole(Enum):ASSISTANT = "assistant"SYSTEM = "system"+ DEVELOPER = "developer"USER = "user"FUNCTION = "function"TOOL = "tool"diff --git a/docs/conf.py b/docs/conf.pyindex 8a84770e8..627e66e6f 100644--- a/docs/conf.py+++ b/docs/conf.py@@ -27,7 +27,7 @@ sys.path.insert(0, os.path.abspath('..'))project = 'CAMEL'copyright = '2024, CAMEL-AI.org'author = 'CAMEL-AI.org'-release = '0.2.40'+release = '0.2.41'html_favicon = ('https://raw.githubusercontent.com/camel-ai/camel/master/misc/favicon.png'diff --git a/docs/key_modules/loaders.md b/docs/key_modules/loaders.mdindex 086eafbb3..532fd92d9 100644--- a/docs/key_modules/loaders.md+++ b/docs/key_modules/loaders.md@@ -340,14 +340,14 @@ response = jina_reader.read_content("https://docs.camel-ai.org/")print(response)``````markdown->>>Welcome to CAMEL’s documentation! — CAMEL 0.2.40 documentation+>>>Welcome to CAMEL’s documentation! — CAMEL 0.2.41 documentation===============[Skip to main content](https://docs.camel-ai.org/#main-content)Back to top Ctrl+K- [ CAMEL 0.2.40](https://docs.camel-ai.org/#)+ [ CAMEL 0.2.41](https://docs.camel-ai.org/#)Search Ctrl+Kdiff --git a/pyproject.toml b/pyproject.tomlindex 46a8f0294..2d0cd517c 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -4,7 +4,7 @@ build-backend = "hatchling.build"[project]name = "camel-ai"-version = "0.2.40"+version = "0.2.41"description = "Communicative Agents for AI Society Study"authors = [{ name = "CAMEL-AI.org" }]requires-python = ">=3.10,<3.13"@@ -22,6 +22,7 @@ keywords = []dependencies = ["openai>=1.68.0,<2",+ "mcp>=1.3.0","tiktoken>=0.7.0,<0.8","colorama>=0.4.6,<0.5","jsonschema>=4,<5",diff --git a/test/agents/test_chat_agent.py b/test/agents/test_chat_agent.pyindex 0f29c8e0b..dd5589943 100644--- a/test/agents/test_chat_agent.py+++ b/test/agents/test_chat_agent.py@@ -400,7 +400,8 @@ def test_chat_agent_messages_window():)openai_messages, _ = assistant.memory.get_context()- assert len(openai_messages) == 2+ # system msg does not count in the window size+ assert len(openai_messages) == 2 + 1@pytest.mark.model_backenddiff --git a/uv.lock b/uv.lockindex 1d8d1dab0..5d29b267c 100644--- a/uv.lock+++ b/uv.lock@@ -543,13 +543,14 @@ wheels = [[[package]]name = "camel-ai"-version = "0.2.40"+version = "0.2.41"source = { editable = "." }dependencies = [{ name = "colorama" },{ name = "docstring-parser" },{ name = "httpx" },{ name = "jsonschema" },+ { name = "mcp" },{ name = "openai" },{ name = "psutil" },{ name = "pydantic" },@@ -955,6 +956,7 @@ requires-dist = [{ name = "litellm", marker = "extra == 'model-platforms'", specifier = ">=1.38.1,<2" },{ name = "math-verify", marker = "extra == 'all'", specifier = ">=0.7.0,<0.8" },{ name = "math-verify", marker = "extra == 'data-tools'", specifier = ">=0.7.0,<0.8" },+ { name = "mcp", specifier = ">=1.3.0" },{ name = "mcp", marker = "extra == 'all'", specifier = ">=1.3.0" },{ name = "mcp", marker = "extra == 'dev-tools'", specifier = ">=1.3.0" },{ name = "mcp-server-fetch", marker = "extra == 'owl'", specifier = "==2025.1.17" },