From 35bd1be1098f2c9a844818f8735a50dccc9be9cd Mon Sep 17 00:00:00 2001 From: Zhou <32321321@qq.com> Date: Wed, 24 Jun 2026 13:46:05 +0800 Subject: [PATCH] fix: ignore non-string reasoning wrappers --- nanobot/utils/helpers.py | 4 +++- tests/utils/test_strip_think.py | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/nanobot/utils/helpers.py b/nanobot/utils/helpers.py index bb0f5e55..99863c33 100644 --- a/nanobot/utils/helpers.py +++ b/nanobot/utils/helpers.py @@ -130,8 +130,10 @@ def strip_think(text: str) -> str: return text.strip() -def strip_reasoning_tags(text: str) -> str: +def strip_reasoning_tags(text: object) -> str: """Remove wrapper tags from text that is already known to be reasoning.""" + if not isinstance(text, str): + return "" text = re.sub(r"^\s*<(?:think|thinking|thought)/>\s*", "", text) text = re.sub(r"\s*<(?:think|thinking|thought)/>\s*$", "", text) text = re.sub(r"^\s*<(?:think|thinking|thought)>\s*", "", text) diff --git a/tests/utils/test_strip_think.py b/tests/utils/test_strip_think.py index cbcc65f5..351c1ca6 100644 --- a/tests/utils/test_strip_think.py +++ b/tests/utils/test_strip_think.py @@ -327,3 +327,6 @@ class TestStripReasoningTags: assert strip_reasoning_tags("Preparing final response") == ( "Preparing final response" ) + + def test_non_string_reasoning_ignored(self): + assert strip_reasoning_tags(object()) == ""