Skip to content

Your lightweight open-source personal agent.

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

Re-bin0036116e0ba9
diff --git a/nanobot/agent/loop.py b/nanobot/agent/loop.py
index 6cd8e56b3..9bca0a2d0 100644
--- a/nanobot/agent/loop.py
+++ b/nanobot/agent/loop.py
@@ -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":
diff --git a/nanobot/providers/base.py b/nanobot/providers/base.py
index f52a95171..eb1599a70 100644
--- a/nanobot/providers/base.py
+++ b/nanobot/providers/base.py
@@ -51,14 +51,6 @@ class LLMProvider(ABC):
for msg in messages:
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:
clean = dict(msg)
clean["content"] = None if (msg.get("role") == "assistant" and msg.get("tool_calls")) else "(empty)"