fix(backends,markdown): stream turn events live, no blank lines for tool blocks

This commit is contained in:
hh
2026-08-28 17:27:35 +02:00
parent 5d2ce68f6b
commit 5fc58e3bc7
4 changed files with 121 additions and 15 deletions
@@ -33,7 +33,9 @@ __all__ = [
# Empty ``### User:`` block appended after each assistant reply so the
# human has an obvious place to type the next turn. Parser drops empty
# user blocks, so this doesn't re-trigger dispatch on its own.
USER_SCAFFOLD = "### User:\n"
# Blank line after the header, like every rendered turn - the file stays
# symmetric whether the human or the gateway wrote the marker.
USER_SCAFFOLD = "### User:\n\n"
# Default 4-backtick fence so tool results that contain literal ```` ``` ````
@@ -73,7 +75,12 @@ def render_assistant_message(message: Message) -> str:
"""
parts: list[str] = ["### Assistant:", ""]
for block in message.content:
parts.extend(_render_block(block))
lines = list(_render_block(block))
if not lines:
# Tool calls render to nothing - no separator for them either,
# or every tool leaves a blank line behind.
continue
parts.extend(lines)
parts.append("")
return "\n".join(parts).rstrip() + "\n"