Skip to content

Anthropic provider: the thinking blocks of a turn are not sent back with the tool results #76

Backlog

Description

@alexey-milovidov

The Anthropic provider keeps only the text and the tool_use blocks of a response, so a turn of the assistant that calls a tool goes back, with the result of the tool, without the thinking blocks that it had.

What happens

  • AnthropicResponseParser (src/providers/anthropic/anthropic_response_parser.cpp) reads the text and tool_use blocks of content. A thinking or a redacted_thinking block is not kept anywhere.
  • The request builder of the provider writes an assistant turn from the text and the tool calls, and has nothing to write such a block back from. The next request, the one with the tool_result, has the turn of the assistant as text and tool_use only.

Why it matters

The current Claude models think when the request says nothing about it. From https://platform.claude.com/docs/en/build-with-claude/thinking: with no thinking field, Claude Opus 5.5, Claude Sonnet 5.5, Claude Haiku 5.5, Claude Fable 5.2 and the other models of the table there run with adaptive thinking, and "display defaults to "omitted" on these models", so the response has thinking blocks with an empty thinking field and a signature. The provider does not send a thinking field, so this is what an ordinary request to the default models gets.

The same page says what to do with these blocks: "Preserving thinking blocks: when you return tool results, you must pass the thinking blocks from the assistant message back to the API, complete and unmodified", and "Required: within a tool-use turn, pass thinking blocks back."

What is not known

What the API does with a turn that lacks its thinking blocks was not checked against the API. The page says "To preserve model quality, the API might strip thinking blocks that would create an invalid turn structure, or disable thinking when the conversation history is incompatible with thinking being enabled", so it may be that the request is answered and the model continues without the reasoning that led to the call, and not that it is refused.

A way to fix it

The same as in #75 for the Bedrock provider, and as the Gemini and the OpenAI Responses providers do with their thought signatures and reasoning items: the parser returns a turn that has thinking blocks in GenerateResult::response_messages with the blocks as ProviderContentParts in their place, and the request builder writes them back as they came. The multi-step loop and the applications that append response_messages to the conversation then replay them without a change. The stream needs a look as well: whether a tool loop over a stream has a place to keep the blocks.

Where it was found

In the review of the Bedrock provider for ClickHouse, which found the defect in that provider: ClickHouse/ClickHouse#137792 (comment). The Anthropic provider has it since before that pull request; when it was introduced was not determined.

Related: #75
Related: ClickHouse/ClickHouse#137792

Activity

  1. alexey-milovidov commented on Dec 6, 2026

    @alexey-milovidov
    MemberAuthor

    One more thing for whoever fixes this, found in the same review (ClickHouse/ClickHouse#137792 (comment)).

    A thinking block is valid only in the conversation that it was made in: "A prefix check fails if system, tools, or an earlier message changed after Claude produced a block" (https://platform.claude.com/docs/en/build-with-claude/preserved-thinking/prefix-checks), with a 400 error for the newest models and a possible one for the others. So once the provider returns these blocks, an application that trims its history or builds the system prompt or the tools again must remove them from the messages that it keeps: "you can leave out the oldest, the newest, or all of them, but not one in between". Today the provider drops the blocks, so no application can run into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions