Skip to content

Include thinking text in Anthropic streaming chunks - #6982

Open
pengjonas wants to merge 1 commit into
spring-projects:mainfrom
pengjonas:anthropic-stream-thinking-text
Open

pengjonas wants to merge 1 commit into
spring-projects:mainfrom
pengjonas:anthropic-stream-thinking-text

Conversation

@pengjonas

Copy link
Copy Markdown

Streamed thinking deltas only carry a thinking=true marker since 9fe9f9c, which removed the text to stop it being aggregated into the assistant message. As a result, a streaming caller has no thinking text to show, and when the model calls a tool none reaches the caller at all. The per-round aggregated message holding it is consumed by the tool-calling loop.

This exposes each delta's text in a thinkingText metadata key. The chunk content stays null, so the fix from 9fe9f9c (no spurious TextBlockParam on replay) is kept.

Reproduction: ChatClient streaming, thinkingEnabled(10000), a question that makes Claude Sonnet 4.6 call two tools. 2.0.1 streams 18 thinking chunks with 0 characters of thinking text. With this change it streams the full text, and the answer text is unchanged. 1.1.x streamed thinking text in this scenario.

See spring-projects/spring-ai#6845 for the same problem in Bedrock Converse. Could this be considered for 2.0.x?

Streamed thinking deltas carry only a thinking=true marker since
9fe9f9c, so a streaming caller cannot show thinking as it arrives.
When the model calls a tool, the per-round aggregated message holding
the thinking is consumed by the tool-calling loop, so the thinking
text never reaches the caller at all.

Expose each delta's text in a thinkingText metadata key, keeping the
content null so it is still not aggregated into the assistant message
text.

Signed-off-by: pengjonas <pengjonas@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants