Skip to content

Conversation

@AryanBagade
Copy link
Contributor

@AryanBagade AryanBagade commented Dec 9, 2025

Summary

Fixes #628
This PR adds support for capturing Claude's extended thinking (reasoning) blocks when using the AI SDK adapter with Anthropic models.

Changes

  • Non-streaming: Extract reasoning parts from AI SDK responses and output them as ReasoningItem objects
  • Streaming: Handle reasoning-start, reasoning-delta, reasoning-end events to accumulate thinking content
  • Signature preservation: Store Anthropic's thinking signature in providerData for multi-turn conversation support
  • Ordering: Reasoning items are output FIRST, before tool calls (required by Anthropic API)

Test plan

  • Added 6 comprehensive unit tests covering all scenarios
  • All 671 tests pass
  • Verified with real Anthropic API call - signature captured successfully. Tested with my own APIs

References for this Issue

…openai#628 Add support for capturing Claude's extended thinking (reasoning) blocks when using the AI SDK adapter with Anthropic models.
@changeset-bot
Copy link

changeset-bot bot commented Dec 9, 2025

🦋 Changeset detected

Latest commit: d82623f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@openai/agents-extensions Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@seratch seratch changed the title feat(agents-extensions): add Anthropic extended thinking support feat(agents-extensions): #628 add Anthropic extended thinking support Dec 9, 2025
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 1035 to 1039
if (reasoningBlock.text) {
outputs.push({
type: 'reasoning',
id: reasoningId !== 'default' ? reasoningId : undefined,
content: [{ type: 'input_text', text: reasoningBlock.text }],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve reasoning metadata even when no text streamed

In the streamed path we only emit a reasoning item when reasoningBlock.text is truthy. For streams where Anthropic returns a reasoning signature but redacts the thinking text (no deltas before the reasoning-end event), this branch is skipped and the reasoning item is omitted, so the signature in providerMetadata is dropped and cannot be echoed back on the next turn despite the PR’s goal of preserving it. Consider emitting a reasoning item even when the text is empty so providerData survives redacted thinking streams.

Useful? React with 👍 / 👎.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me update a code to preserve the signature even with empty text.

@seratch seratch added this to the 0.3.x milestone Dec 9, 2025
AryanBagade and others added 3 commits December 8, 2025 20:53
@AryanBagade AryanBagade requested a review from seratch December 9, 2025 04:54
@seratch
Copy link
Member

seratch commented Dec 9, 2025

@codex review again

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. What shall we delve into next?

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've confirmed this change enables ai-sdk layer to work with the thinking mode. Example model settings:

  const modelSettings = {
    providerData: {
      providerOptions: {
        anthropic: {
          thinking: { type: 'enabled', budgetTokens: 32000 },
        },
      },
    },
  };

@seratch seratch merged commit 9e1549a into openai:main Dec 9, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Anthropic extended thinking and interleaved thinking

2 participants