From 1e8e0533fda80776221e07bd6a72d622d2d61868 Mon Sep 17 00:00:00 2001 From: "DESKTOP-72TV0V4\\caoxiaozhu" Date: Sun, 15 Mar 2026 19:52:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20AgentLoop=20?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E4=BF=9D=E5=AD=98=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 同时保存 assistant 消息的 content 和 tool_calls - 修复多轮工具调用场景下的消息丢失问题 Co-Authored-By: Claude Opus 4.6 --- core/agents/agent/loop.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/core/agents/agent/loop.py b/core/agents/agent/loop.py index 54a0d28..47a2e0f 100644 --- a/core/agents/agent/loop.py +++ b/core/agents/agent/loop.py @@ -509,13 +509,14 @@ class AgentLoop: if role == "user" and content: self.memory.add_to_history("user", str(content)[:1000], session_key) - elif role == "assistant" and content: - self.memory.add_to_history("assistant", str(content)[:1000], session_key) - # Save tool_calls for assistant messages (needed for multi-turn tool calls) - elif role == "assistant" and m.get("tool_calls"): - # Save the assistant message with tool_calls - tool_calls_str = json.dumps(m.get("tool_calls", [])) - self.memory.add_to_history("assistant", f"[tool_calls]{tool_calls_str}", session_key) + elif role == "assistant": + # Save assistant message content + if content: + self.memory.add_to_history("assistant", str(content)[:1000], session_key) + # Save tool_calls if present (needed for multi-turn tool calls) + if m.get("tool_calls"): + tool_calls_str = json.dumps(m.get("tool_calls", [])) + self.memory.add_to_history("assistant", f"[tool_calls]{tool_calls_str}", session_key) # Save tool results (needed for multi-turn conversations) elif role == "tool": tool_call_id = m.get("tool_call_id", "")