Skip to content

fix: only separate streamed text that follows earlier text and a tool result - #482

Open
pcbeingused333 wants to merge 1 commit into
posit-dev:mainfrom
pcbeingused333:fix/stream-text-separator
Open

pcbeingused333 wants to merge 1 commit into
posit-dev:mainfrom
pcbeingused333:fix/stream-text-separator

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

.stream(content="text") and .chat() ran the text before and after a tool call together, while .stream_async(content="text") and .chat_async() put a blank line between them: _chat_impl_async yielded "\n\n" after each tool result, and _chat_impl had no such branch. For a model that says "Checking." before calling a tool and "Done." after, the sync stream produced Checking.Done. and the async one Checking.\n\nDone.. The async rule also had a flaw: a response whose first round is only tool calls started with blank lines (\n\nDone.).

Both loops now share one rule (_TextSeparator): a "\n\n" goes before the first text of a round that follows tool results, only when text was already emitted. The result is Checking.\n\nDone. for text, tool, text; Done. when the first round is only tool calls; sync and async agree. content="all" is unchanged. Existing tests that compare str(chat.chat(...)) exactly (test_chat_tool_request_reject and reject2) pass unchanged.

Tests: tests/test_stream_tool_separator.py drives a fake two-round provider through .stream(), .stream_async(), .chat() and .chat_async(), with a first round of text plus a tool request, and with a first round of only a tool request. Four of the six fail on main. The rest of tests/test_chat.py is unchanged; its 5 failures in my environment (optional dependencies missing) are the same on main. A CHANGELOG entry is included.

This change was made with Claude Code; the tests above were run before opening the PR.

🤖 Generated with Claude Code

… result

The previous commit yielded "\n\n" after every tool result in the sync loop,
as the async loop did. That made a response whose first round is only tool
calls start with blank lines, in both loops, and broke tests comparing the
exact text. Drop the per-result separator in both loops and put "\n\n" before
the first text of a later round only when text was already emitted.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@pcbeingused333
pcbeingused333 force-pushed the fix/stream-text-separator branch from 375d7ee to b986b7d Compare October 21, 2026 16:44

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant