AE Agent Errors
AE-BTYX7BWF

Agent memory orders a tool result before its tool call when both share a timestamp, so the next model request is rejected

MEMORY FAILUREseverity: HIGHcause: LIKELYoutcome: RESOLVED UNVERIFIEDconfidence: MEDIUM

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

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。 但在获取上下文,排序是倒序,如果时间是一样,先结果消息,再到调用函数的消息,导致模型返回错误。third_party · github.com/camel-ai/camel · translation (derived): In _record_tool_calling, the function call and the function call's result are recorded to memory at the same time. But when retrieving the context, the order is reversed; if the timestamps are equal, the result message comes first and then the function-call message, which causes the model to return an error.

Remediation attempts (3)

SUGGESTEDworkaroundby third_party

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)third_party · github.com/camel-ai/camel · translation (derived): There is a temporary workaround: in record_tool_calling of the ChatAgent class in chat_agent.py, add sleep(0.0001) between the two messages.
FAILEDworkaroundby reporter

The reporter applied the sleep workaround as shown and still got the error.

Status basis: documented as not fixing the failure. Verification: not verified.

这样修改后还是会报错reporter · github.com/camel-ai/camel · translation (derived): After making this change it still reports the error.
APPLIEDstate_persistenceby maintainer

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/2119maintainer · github.com/camel-ai/camel · translation (derived): The latest version resolved this problem: https://github.com/camel-ai/camel/pull/2119
fix: enhance timestamp for agent memory updatemaintainer · github.com/camel-ai/camel

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.

FactorPresentMeaning
first_party_evidenceyesa quote from the affected project/vendor (or a controlled test)
fix_appliedyesa fix was merged/released
regression_testnotests changed with the fix
independent_confirmationnoreporter/maintainer/vendor confirmed the failure is gone
root_cause_verifiednocause stated by the project and addressed by the fix
reproduction_documentedyessteps or conditions to reproduce were quoted
multiple_independent_sourcesno1 independent source group(s)
failed_attempts_documentedyesunsuccessful 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)reporter · github.com/camel-ai/camel
tool在_record_tool_calling中,调用函数和调用函数的结果同时记录到memory。 但在获取上下文,排序是倒序,如果时间是一样,先结果消息,再到调用函数的消息,导致模型返回错误。third_party · github.com/camel-ai/camel · translation (derived): In _record_tool_calling, the function call and the function call's result are recorded to memory at the same time. But when retrieving the context, the order is reversed; if the timestamps are equal, the result message comes first and then the function-call message, which causes the model to return an error.
有个临时解决方案,在chat_agent.py的chatagent类的record_tool_calling中,两个消息增加sleep(0.0001)third_party · github.com/camel-ai/camel · translation (derived): There is a temporary workaround: in record_tool_calling of the ChatAgent class in chat_agent.py, add sleep(0.0001) between the two messages.
这样修改后还是会报错reporter · github.com/camel-ai/camel · translation (derived): After making this change it still reports the error.
最新的版本解决了这个问题:https://github.com/camel-ai/camel/pull/2119maintainer · github.com/camel-ai/camel · translation (derived): The latest version resolved this problem: https://github.com/camel-ai/camel/pull/2119
fix: enhance timestamp for agent memory updatemaintainer · github.com/camel-ai/camel
Calling extract_excel_content with document_pathreporter · github.com/camel-ai/camel
他们accept了我的问题,下个版本应该可以解决。 我通过sleep0.1秒可以解决。third_party · github.com/camel-ai/camel · translation (derived): They accepted my issue; it should be solved in the next version. I can solve it by sleeping 0.1 seconds.
Context truncation required (122928 > 64000), pruning low-score messages.reporter · github.com/camel-ai/camel

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.