fix: 修复 AgentLoop 消息保存逻辑
- 同时保存 assistant 消息的 content 和 tool_calls - 修复多轮工具调用场景下的消息丢失问题 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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", "")
|
||||
|
||||
Reference in New Issue
Block a user