-
Notifications
You must be signed in to change notification settings - Fork 460
feat(agents-extensions): #628 Add support for Anthropic extended thin… #640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…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 detectedLatest commit: 5820f19 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
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 |
There was a problem hiding this 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".
| totalTokens: usagePromptTokens + usageCompletionTokens, | ||
| }, | ||
| output: outputs, | ||
| reasoning: reasoningText, | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 👍 / 👎.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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!