Skip to content

Conversation

@aayush-kapoor
Copy link
Contributor

Background

when using anthropic's extended thinking with tool calls, we drop the thinking blocks from previous turns.

#11602

based on the reproduction provided, the issue turned out to be in smoothStream, where smoothStream was stripping providerMetadata from reasoning-delta chunks. this signature is required when sending thinking blocks back to the API in subsequent turns

Summary

pass providerMetadata through smoothStream

Manual Verification

the reproduction code given here was run before and after the fix, and was resolved

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Related Issues

Fixes #11602

@aayush-kapoor aayush-kapoor changed the title fix(ai): pass providerMetadata in smooth stream to preserve thinking tag fix(ai): pass providerMetadata in smooth stream Jan 9, 2026
if (chunk.providerMetadata != null) {
providerMetadata = chunk.providerMetadata;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

providerMetadata is lost when buffered text is fully consumed by the while loop and a metadata-carrying empty delta arrives afterwards

Fix on Vercel

Comment on lines +147 to +149
if (chunk.providerMetadata != null) {
providerMetadata = chunk.providerMetadata;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need some merge algorithm here?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Anthropic extended thinking: reasoning blocks lost during multi-step tool calls

3 participants