Skip to content

Conversation

@subPTcon
Copy link

@subPTcon subPTcon commented Nov 4, 2025

Closes #628

Summary
Hi team! As requested in #628 , this PR adds support for Anthropic (Claude) models' reasoning and interleaved thinking capabilities to the JS/TS SDK, achieving feature parity with the Python SDK.

Implementation Details
This PR primarily consists of two independent changes, each with its own corresponding changeset:

🚀 Feature: Anthropic Reasoning Support

aiSdk.ts: Updates getResponse (non-streaming) and getStreamedResponse (streaming) to handle Anthropic's reasoning and reasoning-delta data chunks.

protocol.ts: Updates the Zod schema in the agents-core package to add an optional reasoning?: string field to the Response type.

aiSdk.test.ts: Adds new unit tests for both streaming and non-streaming cases.

.changeset/: Includes a minor level changeset for this feature.

Local Validation
As per the contribution guidelines (from the README), I have successfully run the following commands locally:

✅ pnpm build (and pnpm -r build-check)

✅ pnpm test

✅ pnpm lint

✅ trufflehog (via the pre-commit hook)

All checks passed. Thank you for your review!

…d thinking

Implements support for Anthropic's reasoning and interleaved thinking
capabilities, achieving parity with the Python SDK.

- Modifies `aiSdk.ts` to handle both streaming and non-streaming cases.
- `getResponse` (non-streaming) passes the `reasoning` field from the
  provider result.
- `getStreamedResponse` (streaming) captures `reasoning-delta` chunks
  and accumulates them into the `reasoning` field of the final
`response_done` event.
- Updates the core `protocol.ts` Zod schema.
- Adds new unit tests to `aiSdk.test.ts`

Closes #[Issue 628]
@changeset-bot
Copy link

changeset-bot bot commented Nov 4, 2025

🦋 Changeset detected

Latest commit: 5820f19

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

This PR includes changesets to release 5 packages
Name Type
@openai/agents-extensions Patch
@openai/agents-core Patch
@openai/agents-openai Patch
@openai/agents-realtime Patch
@openai/agents 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

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

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines 965 to 969
totalTokens: usagePromptTokens + usageCompletionTokens,
},
output: outputs,
reasoning: reasoningText,
},

Choose a reason for hiding this comment

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

P1 Badge Reasoning text is not emitted as an output item

The new reasoning support only stores Anthropic thinking in a standalone reasoning field when returning responses (reasoning: (result as any).reasoning and finalEvent.response.reasoning). Downstream code that persists or renders agent output (e.g. RunState.toJSON and guardrails) iterates exclusively over modelResponse.output, which still contains only messages and tool calls. Because no protocol.ReasoningItem is appended to that array, the collected reasoning never reaches the agent history or serialization and is effectively dropped. To keep the reasoning visible and consistent with other providers, push a ReasoningItem into output (or include it in the existing message content) before returning.

Useful? React with 👍 / 👎.

Copy link
Member

Choose a reason for hiding this comment

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

yeah, i agree with this

Copy link
Author

Choose a reason for hiding this comment

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

Okay, I will make improvements based on the feedback. Thank you for your review.

@seratch seratch marked this pull request as draft November 5, 2025 01:03
@seratch seratch added this to the 0.3.x milestone Nov 5, 2025
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