Skip to content

Conversation

habema
Copy link
Contributor

@habema habema commented Sep 10, 2025

Fixes #1704

Problem:
The SDK was dropping reasoning items when converting conversation history to API messages, causing Anthropic to reject requests with:

messages.1.content.0.type: Expected `thinking` or `redacted_thinking`, but found `tool_use`

Root cause:
Converter.items_to_messages() was skipping reasoning items entirely, violating Anthropic's requirement that assistant messages with tool calls must start with thinking blocks.

Technical changes:

  1. Enhanced InternalChatCompletionMessage to carry thinking_blocks alongside reasoning_content

  2. Updated LitellmConverter.convert_message() to extract full thinking blocks from LiteLLM responses:

    • Handles both dict and object formats of thinking blocks
    • Preserves the cryptographic signature field from Anthropic
    • Safely converts to dict format for storage
  3. Modified Converter.message_to_output_items() to store complete thinking block structure:

    • Stores thinking blocks in ResponseReasoningItem.content as Content objects
    • Maintains backward compatibility with existing reasoning content

Repro script available in original issue.

@habema
Copy link
Contributor Author

habema commented Sep 10, 2025

make old_versions_tests is not failing locally

@seratch seratch merged commit 581111c into openai:main Sep 12, 2025
5 checks passed
@seratch seratch changed the title Fix: Preserve thinking blocks in Anthropic conversations with tool calls fix: #1704 Preserve thinking blocks in Anthropic conversations with tool calls Sep 12, 2025
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.

Bug: Thinking blocks not preserved in Anthropic conversations with tool calls

2 participants