fix(anthropic): ensure reasoning blocks precede tool_use in assistant messages#10474
fix(anthropic): ensure reasoning blocks precede tool_use in assistant messages#10474riftzen-bit wants to merge 1 commit intoanomalyco:devfrom
Conversation
… messages Fixes #9364 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found one potentially related PR: Related PR:
This could be relevant context for understanding how thinking blocks are handled across the codebase, though it may not be a direct duplicate since your PR specifically addresses the ordering issue in |
|
When did you encounter this issue? Can you share the session? Run |
|
I encountered this problem this afternoon and it hasn't been fixed yet. I'm trying to figure it out, but it doesn't seem to be working. Because I don't know where the problem is coming from. |
|
The provided session has no such errors? |
|
I don't know, but I've been encountering it constantly in recent chat messages. |
|
Sorry if I wasn't clear, can you export the session in which you encountered this error? Because the sessions you are linking aren't relevant |
|
I've fixed it now, it was due to plugins. |
00637c0 to
71e0ba2
Compare
f1ae801 to
08fa7f7
Compare
Fixes #9364
Problem
When using Claude models with Extended Thinking enabled, multi-turn conversations with tool use fail with:
Root Cause
The
normalizeMessagesfunction filters empty content but does not reorder parts to ensurereasoningblocks come beforetool-callblocks in assistant messages.Solution
Added sorting logic for assistant messages in the Anthropic-specific block. Parts are now ordered by priority:
reasoning: 0 (first)text: 1tool-call: 2This ensures compliance with Anthropic's Extended Thinking API requirements.
References
thinkingorredacted_thinking, but foundtext." #2599, Expectedthinkingorredacted_thinking, but foundtool_use#3077