Skip to content

feat(ai): round-trip Anthropic redacted thinking blocks - #38614

Merged
rekram1-node merged 2 commits into
v2from
redacted-thinking
Jul 24, 2026
Merged

feat(ai): round-trip Anthropic redacted thinking blocks#38614
rekram1-node merged 2 commits into
v2from
redacted-thinking

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Problem

The Anthropic Messages protocol silently dropped redacted_thinking content blocks: they fell through every branch of the stream parser, and there was no assistant-lowering path to send them back. Anthropic requires redacted thinking blocks to round-trip verbatim, so multi-turn thinking + tool-use conversations that hit safety filtering would lose reasoning continuity (or get rejected on the follow-up request).

Solution

Model redacted thinking the same way Vercel's @ai-sdk/anthropic does:

  • Stream: a redacted_thinking content_block_start emits reasoning-start with providerMetadata: { anthropic: { redactedData } } and empty text; the existing content_block_stop handling closes the part, and response assembly carries the metadata into the final ReasoningPart.
  • Lowering: reasoning parts with a signature (part.encrypted or anthropic.signature metadata) still lower to thinking; signature-less parts carrying anthropic.redactedData lower to { type: "redacted_thinking", data } verbatim. Same precedence order as the AI SDK.
  • Schemas: new AnthropicRedactedThinkingBlock in the assistant block union; data field on the stream block schema.

Tests

  • round-trips redacted thinking as redacted_thinking blocks — mixed redacted + signed reasoning parts lower to the correct block types in order.
  • parses redacted thinking into empty reasoning with redactedData metadata — stream fixture asserts reasoning-start metadata and the assembled empty-text reasoning part.

bun test (330 pass) and bun typecheck clean from packages/ai.

@rekram1-node
rekram1-node changed the base branch from dev to v2 July 24, 2026 04:37
@rekram1-node rekram1-node changed the title feat(llm): round-trip Anthropic redacted thinking blocks feat(ai): round-trip Anthropic redacted thinking blocks Jul 24, 2026
@rekram1-node
rekram1-node merged commit 65c5c7e into v2 Jul 24, 2026
7 checks passed
@rekram1-node
rekram1-node deleted the redacted-thinking branch July 24, 2026 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant