fix(agent): retain skipped inline reasoning separators

This commit is contained in:
Xubin Ren committed 2026-10-18 19:57:34 +08:00
1 parent ed8143f7d0
commit d0a1423ccf
2 files changed
+12 -6

No files matched your search

+1 -1
View File
@@ -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
+11 -5
View File
@@ -8,11 +8,17 @@ 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>"],
@pytest.mark.parametrize("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