Skip to content

Your lightweight open-source personal agent.

fix(agent): retain skipped inline reasoning separators

Xubin Rend0a1423ccf43
diff --git a/nanobot/utils/helpers.py b/nanobot/utils/helpers.py
index 08e8d8d51..1573f7d6a 100644
--- a/nanobot/utils/helpers.py
+++ b/nanobot/utils/helpers.py
@@ -289,9 +289,9 @@ class IncrementalThinkExtractor:
if not thinking or thinking == self._emitted:
return False
new = thinking[len(self._emitted) :]
- self._emitted = thinking
if not new.strip():
return False
+ self._emitted = thinking
await emit(new)
return True
diff --git a/tests/agent/test_progress_inline_reasoning.py b/tests/agent/test_progress_inline_reasoning.py
index a0417e37c..7a0706ad0 100644
--- a/tests/agent/test_progress_inline_reasoning.py
+++ b/tests/agent/test_progress_inline_reasoning.py
@@ -8,11 +8,17 @@ from nanobot.bus.outbound_events import ProgressEvent
from nanobot.events import AgentEvent, EventSink
[email protected]("chunks", [
- ["<think>first paragraph</think><thought>second paragraph</thought>"],
- ["<think>first paragraph</think>", "<thought>second paragraph</thought>"],
[email protected]("chunks, expected", [
+ (["<think>first paragraph</think><thought>second paragraph</thought>"],
+ "first paragraph\n\nsecond paragraph"),
+ (["<think>first paragraph</think>", "<thought>second paragraph</thought>"],
+ "first paragraph\n\nsecond paragraph"),
+ (["<think>first paragraph</think><think></think><thought>second paragraph</thought>"],
+ "first paragraph\n\n\n\nsecond paragraph"),
+ (["<think>first paragraph</think>", "<think></think>", "<thought>second paragraph</thought>"],
+ "first paragraph\n\n\n\nsecond paragraph"),
])
-async def test_inline_reasoning_preserves_paragraph_separators(chunks: list[str]) -> None:
+async def test_inline_reasoning_preserves_paragraph_separators(chunks: list[str], expected: str) -> None:
events: list[AgentEvent] = []
async def publish(event: AgentEvent) -> None:
@@ -28,5 +34,5 @@ async def test_inline_reasoning_preserves_paragraph_separators(chunks: list[str]
event.content for event in events
if isinstance(event, ProgressEvent) and event.reasoning_delta
)
- assert reasoning == "first paragraph\n\nsecond paragraph"
+ assert reasoning == expected
assert context.streamed_reasoning is True