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(agent): preserve separators in streamed inline reasoning
yixi ninged8143f7d0da
diff --git a/nanobot/utils/helpers.py b/nanobot/utils/helpers.pyindex 0af917472..08e8d8d51 100644--- a/nanobot/utils/helpers.py+++ b/nanobot/utils/helpers.py@@ -288,9 +288,9 @@ class IncrementalThinkExtractor:thinking, _ = extract_think(buf)if not thinking or thinking == self._emitted:return False- new = thinking[len(self._emitted) :].strip()+ new = thinking[len(self._emitted) :]self._emitted = thinking- if not new:+ if not new.strip():return Falseawait emit(new)return Truediff --git a/tests/agent/test_progress_inline_reasoning.py b/tests/agent/test_progress_inline_reasoning.pynew file mode 100644index 000000000..a0417e37c--- /dev/null+++ b/tests/agent/test_progress_inline_reasoning.py@@ -0,0 +1,32 @@+"""Inline reasoning should not change when a provider splits its stream."""++import pytest++from nanobot.agent.hook import AgentHookContext+from nanobot.agent.progress_hook import AgentProgressHook+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>"],+])+async def test_inline_reasoning_preserves_paragraph_separators(chunks: list[str]) -> None:+ events: list[AgentEvent] = []++ async def publish(event: AgentEvent) -> None:+ events.append(event)++ hook = AgentProgressHook(EventSink(publish=publish), streaming=True)+ context = AgentHookContext(iteration=0, messages=[])++ for chunk in chunks:+ await hook.on_stream(context, chunk)++ reasoning = "".join(+ event.content for event in events+ if isinstance(event, ProgressEvent) and event.reasoning_delta+ )+ assert reasoning == "first paragraph\n\nsecond paragraph"+ assert context.streamed_reasoning is True