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: preserve interim content as fallback when retry produces empty response
Nikolas de Hor4eb07c44b982
diff --git a/nanobot/agent/loop.py b/nanobot/agent/loop.pyindex 3016d92ff..d81781527 100644--- a/nanobot/agent/loop.py+++ b/nanobot/agent/loop.py@@ -185,6 +185,7 @@ class AgentLoop:final_content = Nonetools_used: list[str] = []text_only_retried = False+ interim_content: str | None = None # Fallback if retry produces nothingwhile iteration < self.max_iterations:iteration += 1@@ -231,9 +232,11 @@ class AgentLoop:else:final_content = self._strip_think(response.content)# Some models send an interim text response before tool calls.- # Give them one retry; don't forward the text to avoid duplicates.+ # Give them one retry; save the content as fallback in case+ # the retry produces nothing useful (e.g. model already answered).if not tools_used and not text_only_retried and final_content:text_only_retried = True+ interim_content = final_contentlogger.debug("Interim text response (no tools used yet), retrying: {}", final_content[:80])messages = self.context.add_assistant_message(messages, response.content,@@ -241,6 +244,9 @@ class AgentLoop:)final_content = Nonecontinue+ # Fall back to interim content if retry produced nothing+ if not final_content and interim_content:+ final_content = interim_contentbreakreturn final_content, tools_used