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", "")