From 0300af6717173f7d26d27d0f51ea66bf2bf92667 Mon Sep 17 00:00:00 2001 From: sausheong Date: Sun, 12 Jul 2026 21:01:02 +0800 Subject: [PATCH] fix: capture thinking blocks in ChatNonStreaming fallback path --- providers/anthropic/anthropic.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/providers/anthropic/anthropic.go b/providers/anthropic/anthropic.go index 9d9145b..d61bec4 100644 --- a/providers/anthropic/anthropic.go +++ b/providers/anthropic/anthropic.go @@ -335,8 +335,8 @@ func (p *AnthropicProvider) ChatStream(ctx context.Context, req llm.ChatRequest) // mid-flight; the partial output of the failed stream is discarded so // the prompt cache prefix on the next turn stays byte-identical. // -// Note: thinking blocks (when reasoning is enabled) are NOT surfaced — -// matches the streaming path which also doesn't emit thinking deltas. +// Thinking blocks are surfaced as EventThinkingBlock events so the runtime +// can store and echo them back in subsequent turns. // Tool-use input is converted to JSON via the SDK's RawJSON field. func (p *AnthropicProvider) ChatNonStreaming(ctx context.Context, req llm.ChatRequest) (<-chan llm.ChatEvent, error) { params := p.buildMessageParams(req) @@ -350,6 +350,16 @@ func (p *AnthropicProvider) ChatNonStreaming(ctx context.Context, req llm.ChatRe defer close(events) for _, block := range msg.Content { switch block.Type { + case "thinking": + if block.Thinking != "" || block.Signature != "" { + events <- llm.ChatEvent{ + Type: llm.EventThinkingBlock, + ThinkingBlock: &llm.ThinkingBlock{ + Thinking: block.Thinking, + Signature: block.Signature, + }, + } + } case "text": if block.Text != "" { events <- llm.ChatEvent{Type: llm.EventTextDelta, Text: block.Text}