[PR #10474] fix(anthropic): ensure reasoning blocks precede tool_use in assistant messages #13455

Closed
opened 2026-02-16 18:18:18 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/10474

State: closed
Merged: No


Fixes #9364

Problem

When using Claude models with Extended Thinking enabled, multi-turn conversations with tool use fail with:

messages.X.content.0.type: Expected 'thinking' or 'redacted_thinking', but found 'tool_use'

Root Cause

The normalizeMessages function filters empty content but does not reorder parts to ensure reasoning blocks come before tool-call blocks 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: 1
  • tool-call: 2
  • everything else: 3

This ensures compliance with Anthropic's Extended Thinking API requirements.

References

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/10474 **State:** closed **Merged:** No --- Fixes #9364 ## Problem When using Claude models with Extended Thinking enabled, multi-turn conversations with tool use fail with: ``` messages.X.content.0.type: Expected 'thinking' or 'redacted_thinking', but found 'tool_use' ``` ## Root Cause The `normalizeMessages` function filters empty content but does not reorder parts to ensure `reasoning` blocks come before `tool-call` blocks 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`: 1 - `tool-call`: 2 - everything else: 3 This ensures compliance with Anthropic's Extended Thinking API requirements. ## References - https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking - Related: #2599, #3077
yindo added the pull-request label 2026-02-16 18:18:18 -05:00
yindo closed this issue 2026-02-16 18:18:18 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13455