Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix: prevent session poisoning from null/error LLM responses
Nikolas de Hor66063abb8cc6
diff --git a/nanobot/agent/loop.py b/nanobot/agent/loop.pyindex 6fe37e910..6cd8e56b3 100644--- a/nanobot/agent/loop.py+++ b/nanobot/agent/loop.py@@ -224,6 +224,12 @@ class AgentLoop:)else:clean = self._strip_think(response.content)+ # Don't persist error responses to session history — they can+ # poison the context and cause permanent 400 loops (#1303).+ if response.finish_reason == "error":+ logger.error("LLM returned error: {}", (clean or "")[:200])+ final_content = clean or "Sorry, I encountered an error calling the AI model."+ breakmessages = self.context.add_assistant_message(messages, clean, reasoning_content=response.reasoning_content,)diff --git a/nanobot/providers/base.py b/nanobot/providers/base.pyindex eb1599a70..f52a95171 100644--- a/nanobot/providers/base.py+++ b/nanobot/providers/base.py@@ -51,6 +51,14 @@ 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)"