Agent memory orders a tool result before its tool call when both share a timestamp, so the next model request is rejected
In a role-playing agent society using an Excel toolkit with a DeepSeek model, each step failed with a 400 error saying an assistant message with tool_calls must be followed by tool messages. A commenter traced it to the agent recording the tool call and its result in memory with the same timestamp, after which context retrieval could place the result before the call. A maintainer said a merged PR that changed memory-update timestamps fixed it.
- Framework / agent
- CAMEL · role-playing multi-agent society with toolkits
- Remediation attempts
- SUGGESTEDFAILEDAPPLIED
- Recurrence
- not documented
- Source languages
- en, zh
- Updated
- 2026-09-30
Sources
- GITHUB ISSUE [Question] 使用exceltoolkits工具,总是报错,大语言模型输出结果不符合格式,无法调用工具 — github.com/camel-ai/camel, retrieved 2026-09-29
- GITHUB PULL REQUEST fix: enhance timestamp for agent memory update — github.com/camel-ai/camel, retrieved 2026-09-29
Public sample: the full evidence record is free.
Symptoms
- The model provider rejects the request with a 400 invalid_request_error about missing tool messages after tool_calls REPORTED CLAIM
- Just before the failing request, the agent logs that its context exceeds the limit and prunes low-score messages REPORTED CLAIM
Error messages (verbatim)
An assistant message with 'tool_calls' must be followed by tool messages responding to each 'tool_call_id'. (insufficient tool messages following tool_calls message)
Context and trigger
- Agent type
- role-playing multi-agent society with toolkits
- Component
- ChatAgent tool-call recording in agent memory (context ordering by timestamp)
- Framework
- CAMEL
- Model
- deepseek-chat
- Task
- reading and summarizing an Excel file with a tool
- Tools
- ExcelToolkit, FileWriteToolkit
- A tool call and its result are written to memory at the same timestamp REPORTED CLAIM
- The Excel tool output is large enough that the context creator must truncate and prune messages REPORTED CLAIM
Open questions
- The fix PR has no description; its exact change beyond 'enhance timestamp for agent memory update' is not stated in the sources.
- The original reporter did not confirm that the released fix resolved their case.
- Whether context pruning (logged right before the error) contributed to the orphaned tool call was not discussed in the thread.
Root cause LIKELY
Tool call and tool result messages were recorded to memory at the same time; context retrieval sorts by time in reverse, and with equal timestamps the result message could come before the call message, producing an invalid message sequence.
cause reported, not confirmed by the project
tool在_record_tool_calling中,调用函数和调用函数的结果同时记录到memory。
但在获取上下文,排序是倒序,如果时间是一样,先结果消息,再到调用函数的消息,导致模型返回错误。Remediation attempts (3)
Workaround: add a tiny sleep between recording the tool-call message and the tool-result message in ChatAgent's tool-call recording so timestamps differ.
Status basis: proposed; no evidence it was applied. Verification: not verified.
有个临时解决方案,在chat_agent.py的chatagent类的record_tool_calling中,两个消息增加sleep(0.0001)The reporter applied the sleep workaround as shown and still got the error.
Status basis: documented as not fixing the failure. Verification: not verified.
这样修改后还是会报错Maintainer fix: merged PR enhancing timestamps for agent memory updates; the maintainer states the latest version resolves the issue.
Status basis: fix merged. Verification: not verified.
Change: https://github.com/camel-ai/camel/pull/2119 · merged
Excerpt of the change (.github/ISSUE_TEMPLATE/bug_report.yml, Apache-2.0):
@@ -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
最新的版本解决了这个问题:https://github.com/camel-ai/camel/pull/2119fix: enhance timestamp for agent memory update
Outcome outcome: RESOLVED UNVERIFIED
fix applied; not independently verified (2025-04-06)
Recurrence
Not documented in the sources (absence of reports is not evidence of absence).
Confidence MEDIUM
The project itself documents the failure and its cause or remediation, but the fix is not fully verified.
| Factor | Present | Meaning |
|---|---|---|
| first_party_evidence | yes | a quote from the affected project/vendor (or a controlled test) |
| fix_applied | yes | a fix was merged/released |
| regression_test | no | tests changed with the fix |
| independent_confirmation | no | reporter/maintainer/vendor confirmed the failure is gone |
| root_cause_verified | no | cause stated by the project and addressed by the fix |
| reproduction_documented | yes | steps or conditions to reproduce were quoted |
| multiple_independent_sources | no | 1 independent source group(s) |
| failed_attempts_documented | yes | unsuccessful remediation recorded |
All evidence (9 verified quotes)
An assistant message with 'tool_calls' must be followed by tool messages responding to each 'tool_call_id'. (insufficient tool messages following tool_calls message)tool在_record_tool_calling中,调用函数和调用函数的结果同时记录到memory。
但在获取上下文,排序是倒序,如果时间是一样,先结果消息,再到调用函数的消息,导致模型返回错误。有个临时解决方案,在chat_agent.py的chatagent类的record_tool_calling中,两个消息增加sleep(0.0001)这样修改后还是会报错最新的版本解决了这个问题:https://github.com/camel-ai/camel/pull/2119fix: enhance timestamp for agent memory update
Calling extract_excel_content with document_path
他们accept了我的问题,下个版本应该可以解决。
我通过sleep0.1秒可以解决。Context truncation required (122928 > 64000), pruning low-score messages.
Categories: MEMORY FAILURE TOOL FAILURECONCURRENCY FAILURE · extraction curated, gate-2026-09-29-v1
Similarity to your system is not implied. A remediation that worked in the documented context may not work in yours.