feat: use StreamingChunk.reasoning field for Anthropic thinking content#2849
Merged
anakin87 merged 4 commits intodeepset-ai:mainfrom Feb 18, 2026
Merged
Conversation
Migrate Anthropic streaming to use the dedicated reasoning field instead of storing thinking content in StreamingChunk.meta.
1f46ed9 to
1e5dc54
Compare
Member
|
@yaowubarbara, thanks for the contribution.
|
Contributor
Author
|
Thanks for the review! I've signed the CLA. Just a heads-up — I opened #2850 for the Ollama side before seeing your comment. Happy to hold off on any further PRs until we're aligned on the approach here. Let me know if there's anything you'd like me to change, or if you have a different direction in mind for the reasoning field migration. |
Member
|
Thank you. I'll take a look... |
anakin87
reviewed
Feb 17, 2026
Member
anakin87
left a comment
There was a problem hiding this comment.
I left some initial comments.
integrations/anthropic/src/haystack_integrations/components/generators/anthropic/chat/utils.py
Show resolved
Hide resolved
integrations/anthropic/src/haystack_integrations/components/generators/anthropic/chat/utils.py
Show resolved
Hide resolved
integrations/anthropic/src/haystack_integrations/components/generators/anthropic/chat/utils.py
Show resolved
Hide resolved
- Restore mypy comment for reasoning_text type inference - Add parameter descriptions to _finalize_reasoning_group docstring - Add unit tests for _finalize_reasoning_group - Add check to skip chunks with empty reasoning content
anakin87
reviewed
Feb 18, 2026
integrations/anthropic/src/haystack_integrations/components/generators/anthropic/chat/utils.py
Outdated
Show resolved
Hide resolved
Signature-only chunks now accumulate without triggering new content groups, matching the previous behavior more closely.
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.
Related Issues
reasoningfield inStreamingChunkhaystack#10479Proposed Changes:
Right now the Anthropic integration dumps the entire stream event into
StreamingChunk.metaviachunk.model_dump(), which means thinking/reasoning content ends up buried inmeta["delta"]["thinking"]instead of being accessible through the dedicatedStreamingChunk.reasoningfield that was added in Haystack 2.18.0.This PR updates
_convert_anthropic_chunk_to_streaming_chunkto populateStreamingChunk.reasoningwith a properReasoningContentobject when it encounters thinking-related events:content_block_startwith typethinkingorredacted_thinkingcontent_block_deltawith typethinking_deltaorsignature_deltaAlso updated
_process_reasoning_contentsto read fromchunk.reasoninginstead of digging throughchunk.meta, which simplifies the logic quite a bit. Extracted the repeated group-finalization code into a small helper (_finalize_reasoning_group).The raw event data is still available in
metafor anyone who needs it -- this just makes reasoning content properly accessible through the structured field.How did you test it?
StreamingChunk.reasoningis populated correctly for thinking block start, thinking delta, and signature delta eventsNotes for the reviewer
The non-streaming path (
_convert_chat_completion_to_chat_message) already usesReasoningContentcorrectly, so no changes needed there. This only affects the streaming code path.Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:.