fix: filter empty assistant messages in _save_turn instead of patching at send time

This commit is contained in:
Re-bin
2026-02-28 07:35:07 +00:00
parent 069f93f6f5
commit 0036116e0b
2 changed files with 2 additions and 8 deletions

View File

@@ -451,6 +451,8 @@ class AgentLoop:
for m in messages[skip:]:
entry = {k: v for k, v in m.items() if k != "reasoning_content"}
role, content = entry.get("role"), entry.get("content")
if role == "assistant" and not content and not entry.get("tool_calls"):
continue # skip empty assistant messages — they poison session context
if role == "tool" and isinstance(content, str) and len(content) > self._TOOL_RESULT_MAX_CHARS:
entry["content"] = content[:self._TOOL_RESULT_MAX_CHARS] + "\n... (truncated)"
elif role == "user":