fix: yield thinking tag boundaries in content='all' mode#297
Merged
Conversation
Previously `<thinking>\n` and `\n</thinking>\n\n` boundary strings were only yielded to consumers when `content="text"`. Remove that guard so they are emitted in all modes, including `content="all"`. This is required by shinychat PR posit-dev/shinychat#210, which removes server-side thinking detection and relies on the client tag parser seeing `<thinking>` markers in the stream. Without this fix, tool-use apps (which require `content="all"`) with thinking-capable models render thinking content as regular assistant text. Both the sync and async `_submit_turns` paths are updated. Tests in `TestStreamThinkingAll` and the async `test_content_all_async` are updated to assert that tag boundary strings ARE present in the output.
cpsievert
added a commit
to cpsievert/ellmer
that referenced
this pull request
May 7, 2026
Remove the `if (!yield_as_content)` guards so that `<thinking>` and `</thinking>` boundary strings are yielded to consumers in all stream modes, not just stream='text'. Needed for posit-dev/shinychat#210, which removes server-side thinking detection and relies on the client's tag parser seeing tag boundaries in the stream. Without this, tool-use apps (stream='content') with thinking-capable models would render thinking as regular text. Companion to posit-dev/chatlas#297.
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends the
<thinking>tag boundary emission (from #294) tocontent="all"mode. Previously, tag boundary strings were only yielded to consumers incontent="text"mode. Now they're yielded in all modes.What changed
Removed the
if content_mode == "text":guards around the tag boundaryyieldstatements in both sync and async_submit_turns. Theemit()calls (internal echo) were already unconditional; this makes the consumer-facing yields match.In
content="all"mode, the stream now yields:"<thinking>\n"(string)ContentThinkingobjects (unchanged)"\n</thinking>\n\n"(string)Why
This is needed for posit-dev/shinychat#210, which removes server-side thinking detection and relies entirely on the client's tag parser seeing
<thinking>tags in the stream. Without this fix, tool-use apps (which requirecontent="all") with thinking-capable models would render thinking content as regular assistant text — the client never sees tag boundaries.Related PRs
content="text"mode. This PR extends that tocontent="all".stream="content"mode.content="all"scenarios.Test plan
TestStreamThinkingAll::test_tag_boundaries_yielded— verifies boundaries presentTestStreamThinkingAll::test_order_of_chunks— verifies exact sequenceTestStreamThinkingAsync::test_content_all_async— async equivalent