Replace tag injection with ContentThinkingDelta class#299
Merged
Conversation
Providers now emit ContentThinkingDelta (with a phase property) instead
of ContentThinking._as_chunk(). The central streaming loop annotates
phase ("start", "body", "end") and suppresses thinking in content="text"
mode. In content="all" mode, typed delta objects are yielded instead of
synthetic tag strings.
This aligns chatlas with the approach taken in tidyverse/ellmer#975 and
addresses feedback from posit-dev/shinychat#210 about preferring typed
objects over string conventions.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2 tasks
- Give ContentThinkingDelta a distinct content_type ("thinking_delta")
so it won't round-trip as ContentThinking during (de)serialization.
- Construct a new ContentThinkingDelta instead of mutating phase
in-place, avoiding Pydantic validation bypass.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
ContentThinkingDelta— a streaming fragment class with aphaseproperty ("start","body", or"end") that communicates thinking block boundaries to downstream consumers.ContentThinkingDelta(thinking=text)instead ofContentThinking._as_chunk(text).content="text": thinking is suppressed entirely (not yielded).content="all":ContentThinkingDeltaobjects are yielded with phase annotations — no synthetic tag strings injected into the stream._complete/_as_chunk()fromContentThinking— it reverts to always wrapping in<thinking>tags (for complete thoughts in turn history).<thinking>tags regardless of mode.Closes #293
Closes #291
Follow up to #294 and #297
Motivation
Feedback on posit-dev/shinychat#210 identified that injecting
<thinking>tag strings into the stream couples upstream libraries to a specific string convention. Typed objects with phase metadata let downstream consumers (like shinychat) make their own rendering decisions while still getting explicit boundary signals.This aligns chatlas with the approach taken in tidyverse/ellmer#975.
Test plan
🤖 Generated with Claude Code