fix: structured reasoning no longer breaks chat consumers
Normalize incoming reasoning at the shared heading boundary and completed extraction, and flatten auxiliary content and reasoning before accumulation. Reuse the existing text flattener with no implicit fragment separators. Combine the earliest related work from zsuroy (#85791), the diagnosis and patch from 2025hcsmile2010-hue (#104711, #104848), and completed extraction work from liuhao1024 (#104717) as a slim redo, not a verbatim cherry-pick. Two invariant tests exercise the real SDK and local HTTP fixture across main streaming, Relay collection, auxiliary sync/async and completed output. The standalone matrix improves from 32/84 to 84/84, preserving answers. Co-authored-by: suroy <suroy@qq.com> Co-authored-by: 2025hcsmile2010-hue <2025hcsmile2010@gmail.com> Co-authored-by: liuhao1024 <sunsky.lau@gmail.com>
This commit is contained in:
@@ -6422,12 +6422,15 @@ class _ChatStreamAccumulator:
|
||||
if delta is None:
|
||||
return
|
||||
made_progress = False
|
||||
piece = getattr(delta, "content", None)
|
||||
from agent.message_content import flatten_message_text
|
||||
|
||||
piece = flatten_message_text(getattr(delta, "content", None), sep="")
|
||||
if piece:
|
||||
self.content_parts.append(piece)
|
||||
made_progress = True
|
||||
reasoning_piece = getattr(delta, "reasoning", None) or getattr(delta, "reasoning_content", None)
|
||||
if reasoning_piece and isinstance(reasoning_piece, str):
|
||||
reasoning_piece = flatten_message_text(reasoning_piece, sep="")
|
||||
if reasoning_piece:
|
||||
self.reasoning_parts.append(reasoning_piece)
|
||||
made_progress = True
|
||||
# Evaluate both unconditionally: they accumulate state, not just progress.
|
||||
|
||||
Reference in New Issue
Block a user