fix: filter empty assistant messages in _save_turn instead of patching at send time
This commit is contained in:
@@ -451,6 +451,8 @@ class AgentLoop:
|
|||||||
for m in messages[skip:]:
|
for m in messages[skip:]:
|
||||||
entry = {k: v for k, v in m.items() if k != "reasoning_content"}
|
entry = {k: v for k, v in m.items() if k != "reasoning_content"}
|
||||||
role, content = entry.get("role"), entry.get("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:
|
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)"
|
entry["content"] = content[:self._TOOL_RESULT_MAX_CHARS] + "\n... (truncated)"
|
||||||
elif role == "user":
|
elif role == "user":
|
||||||
|
|||||||
@@ -51,14 +51,6 @@ class LLMProvider(ABC):
|
|||||||
for msg in messages:
|
for msg in messages:
|
||||||
content = msg.get("content")
|
content = msg.get("content")
|
||||||
|
|
||||||
# None content on a plain assistant message (no tool_calls) crashes
|
|
||||||
# providers with "invalid message content type: <nil>".
|
|
||||||
if content is None and msg.get("role") == "assistant" and not msg.get("tool_calls"):
|
|
||||||
clean = dict(msg)
|
|
||||||
clean["content"] = "(empty)"
|
|
||||||
result.append(clean)
|
|
||||||
continue
|
|
||||||
|
|
||||||
if isinstance(content, str) and not content:
|
if isinstance(content, str) and not content:
|
||||||
clean = dict(msg)
|
clean = dict(msg)
|
||||||
clean["content"] = None if (msg.get("role") == "assistant" and msg.get("tool_calls")) else "(empty)"
|
clean["content"] = None if (msg.get("role") == "assistant" and msg.get("tool_calls")) else "(empty)"
|
||||||
|
|||||||
Reference in New Issue
Block a user