From 464352c664c0c059457b8cceafbaa3844011a1d9 Mon Sep 17 00:00:00 2001 From: Nikolas de Hor Date: Wed, 18 Feb 2026 21:29:10 -0300 Subject: [PATCH 1/3] fix: allow one retry for models that send interim text before tool calls Some LLM providers (MiniMax, Gemini Flash, GPT-4.1, etc.) send an initial text-only response like "Let me investigate..." before actually making tool calls. The agent loop previously broke immediately on any text response without tool calls, preventing these models from ever using tools. Now, when the model responds with text but hasn't used any tools yet, the loop forwards the text as progress to the user and gives the model one additional iteration to make tool calls. This is limited to a single retry to prevent infinite loops. Closes #705 --- nanobot/agent/loop.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/nanobot/agent/loop.py b/nanobot/agent/loop.py index e5a5183..6acbb38 100644 --- a/nanobot/agent/loop.py +++ b/nanobot/agent/loop.py @@ -183,6 +183,7 @@ class AgentLoop: iteration = 0 final_content = None tools_used: list[str] = [] + text_only_retried = False while iteration < self.max_iterations: iteration += 1 @@ -226,6 +227,21 @@ class AgentLoop: ) else: final_content = self._strip_think(response.content) + # Some models (MiniMax, Gemini Flash, GPT-4.1, etc.) send an + # interim text response (e.g. "Let me investigate...") before + # making tool calls. If no tools have been used yet and we + # haven't already retried, forward the text as progress and + # give the model one more chance to use tools. + if not tools_used and not text_only_retried and final_content: + text_only_retried = True + logger.debug(f"Interim text response (no tools used yet), retrying: {final_content[:80]}") + if on_progress: + await on_progress(final_content) + messages = self.context.add_assistant_message( + messages, response.content, + reasoning_content=response.reasoning_content, + ) + continue break return final_content, tools_used From 1b49bf96021eba1bfc95e3c0a1ab6cae36271973 Mon Sep 17 00:00:00 2001 From: Nikolas de Hor Date: Thu, 19 Feb 2026 10:26:49 -0300 Subject: [PATCH 2/3] fix: avoid duplicate messages on retry and reset final_content Address review feedback: - Remove on_progress call for interim text to prevent duplicate messages when the model simply answers a direct question - Reset final_content to None before continue to avoid stale interim text leaking as the final response on empty retry Closes #705 --- nanobot/agent/loop.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/nanobot/agent/loop.py b/nanobot/agent/loop.py index 6acbb38..532488f 100644 --- a/nanobot/agent/loop.py +++ b/nanobot/agent/loop.py @@ -230,17 +230,18 @@ class AgentLoop: # Some models (MiniMax, Gemini Flash, GPT-4.1, etc.) send an # interim text response (e.g. "Let me investigate...") before # making tool calls. If no tools have been used yet and we - # haven't already retried, forward the text as progress and - # give the model one more chance to use tools. + # haven't already retried, add the text to the conversation + # and give the model one more chance to use tools. + # We do NOT forward the interim text as progress to avoid + # duplicate messages when the model simply answers directly. if not tools_used and not text_only_retried and final_content: text_only_retried = True logger.debug(f"Interim text response (no tools used yet), retrying: {final_content[:80]}") - if on_progress: - await on_progress(final_content) messages = self.context.add_assistant_message( messages, response.content, reasoning_content=response.reasoning_content, ) + final_content = None continue break From 2383dcb3a82868162a970b91528945a84467af93 Mon Sep 17 00:00:00 2001 From: Re-bin Date: Fri, 20 Feb 2026 08:31:48 +0000 Subject: [PATCH 3/3] style: use loguru native format and trim comments in interim retry --- README.md | 2 +- nanobot/agent/loop.py | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 289ff28..21c5491 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ ⚡️ Delivers core agent functionality in just **~4,000** lines of code — **99% smaller** than Clawdbot's 430k+ lines. -📏 Real-time line count: **3,781 lines** (run `bash core_agent_lines.sh` to verify anytime) +📏 Real-time line count: **3,793 lines** (run `bash core_agent_lines.sh` to verify anytime) ## 📢 News diff --git a/nanobot/agent/loop.py b/nanobot/agent/loop.py index 3829626..a90dccb 100644 --- a/nanobot/agent/loop.py +++ b/nanobot/agent/loop.py @@ -227,16 +227,11 @@ class AgentLoop: ) else: final_content = self._strip_think(response.content) - # Some models (MiniMax, Gemini Flash, GPT-4.1, etc.) send an - # interim text response (e.g. "Let me investigate...") before - # making tool calls. If no tools have been used yet and we - # haven't already retried, add the text to the conversation - # and give the model one more chance to use tools. - # We do NOT forward the interim text as progress to avoid - # duplicate messages when the model simply answers directly. + # Some models send an interim text response before tool calls. + # Give them one retry; don't forward the text to avoid duplicates. if not tools_used and not text_only_retried and final_content: text_only_retried = True - logger.debug(f"Interim text response (no tools used yet), retrying: {final_content[:80]}") + logger.debug("Interim text response (no tools used yet), retrying: {}", final_content[:80]) messages = self.context.add_assistant_message( messages, response.content, reasoning_content=response.reasoning_content,