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: enhance timestamp for agent memory update (#2119)

Wendong-Fan3f0ff7e5b0ec
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml
index b84140c56..6baa4a87b 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.41
+ placeholder: E.g., 0.2.42
validations:
required: true
diff --git a/camel/__init__.py b/camel/__init__.py
index cc3bfcfdc..2d28429e3 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.41'
+__version__ = '0.2.42'
__all__ = [
'__version__',
diff --git a/camel/agents/chat_agent.py b/camel/agents/chat_agent.py
index 020ae8bc3..64405469d 100644
--- a/camel/agents/chat_agent.py
+++ b/camel/agents/chat_agent.py
@@ -327,7 +327,10 @@ class ChatAgent(BaseAgent):
return False
def update_memory(
- self, message: BaseMessage, role: OpenAIBackendRole
+ self,
+ message: BaseMessage,
+ role: OpenAIBackendRole,
+ timestamp: Optional[float] = None,
) -> None:
r"""Updates the agent memory with a new message.
@@ -335,12 +338,19 @@ class ChatAgent(BaseAgent):
message (BaseMessage): The new message to add to the stored
messages.
role (OpenAIBackendRole): The backend role type.
+ timestamp (Optional[float], optional): Custom timestamp for the
+ memory record. If None, current timestamp will be used.
+ (default: :obj:`None`)
"""
+ from datetime import timezone
+
self.memory.write_record(
MemoryRecord(
message=message,
role_at_backend=role,
- timestamp=datetime.now().timestamp(),
+ timestamp=timestamp
+ if timestamp is not None
+ else datetime.now(timezone.utc).timestamp(),
agent_id=self.agent_id,
)
)
@@ -1331,8 +1341,18 @@ class ChatAgent(BaseAgent):
tool_call_id=tool_call_id,
)
- self.update_memory(assist_msg, OpenAIBackendRole.ASSISTANT)
- self.update_memory(func_msg, OpenAIBackendRole.FUNCTION)
+ # Use slightly different timestamps to ensure correct ordering
+ # This ensures the assistant message (tool call) always appears before
+ # the function message (tool result) in the conversation context
+ current_time = datetime.now().timestamp()
+ self.update_memory(
+ assist_msg, OpenAIBackendRole.ASSISTANT, timestamp=current_time
+ )
+ self.update_memory(
+ func_msg,
+ OpenAIBackendRole.FUNCTION,
+ timestamp=current_time + 0.001,
+ )
# Record information about this tool call
tool_record = ToolCallingRecord(
diff --git a/docs/conf.py b/docs/conf.py
index 627e66e6f..481041ff7 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.41'
+release = '0.2.42'
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.md
index 532fd92d9..4081200e0 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.41 documentation
+>>>Welcome to CAMEL’s documentation! — CAMEL 0.2.42 documentation
===============
[Skip to main content](https://docs.camel-ai.org/#main-content)
Back to top Ctrl+K
- [![Image 1](https://raw.githubusercontent.com/camel-ai/camel/master/misc/logo_light.png) ![Image 2](https://raw.githubusercontent.com/camel-ai/camel/master/misc/logo_light.png)CAMEL 0.2.41](https://docs.camel-ai.org/#)
+ [![Image 1](https://raw.githubusercontent.com/camel-ai/camel/master/misc/logo_light.png) ![Image 2](https://raw.githubusercontent.com/camel-ai/camel/master/misc/logo_light.png)CAMEL 0.2.42](https://docs.camel-ai.org/#)
Search Ctrl+K
diff --git a/pyproject.toml b/pyproject.toml
index 2d0cd517c..956c31f39 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project]
name = "camel-ai"
-version = "0.2.41"
+version = "0.2.42"
description = "Communicative Agents for AI Society Study"
authors = [{ name = "CAMEL-AI.org" }]
requires-python = ">=3.10,<3.13"
diff --git a/uv.lock b/uv.lock
index 5d29b267c..72b7df9e0 100644
--- a/uv.lock
+++ b/uv.lock
@@ -543,7 +543,7 @@ wheels = [
[[package]]
name = "camel-ai"
-version = "0.2.41"
+version = "0.2.42"
source = { editable = "." }
dependencies = [
{ name = "colorama" },