fix(agent): preserve separators in streamed inline reasoning

This commit is contained in:
yixi ning authored and Xubin Ren committed 2026-10-18 19:57:34 +08:00
1 parent a389633b9c
commit ed8143f7d0
2 files changed
+34 -2

No files matched your search

+2 -2
View File
@@ -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 False
await emit(new)
return True
@@ -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
@pytest.mark.parametrize("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