Skip to content

test(provider/anthropic): add fixture-based tests and examples for context editing#12547

Merged
felixarntz merged 8 commits intomainfrom
fa-add-tests-for-anthropic-context-editing
Feb 20, 2026
Merged

test(provider/anthropic): add fixture-based tests and examples for context editing#12547
felixarntz merged 8 commits intomainfrom
fa-add-tests-for-anthropic-context-editing

Conversation

@felixarntz
Copy link
Copy Markdown
Collaborator

Background

Anthropic context management support (clear_tool_uses, clear_thinking) was added in #10540 (with a related fix in #12154), and compaction support (compact) was added in #12384.

Summary

With the complexities of handling these features correctly (including how clear_tool_uses and clear_thinking can be combined), I think it makes sense to add some more tests and also examples around this.

  • Adds fixture based tests for context editing (tool uses, thinking, and both combined), each for generateText and streamText
  • Adds examples for thinking, compaction, and thinking and tool uses combined (there already was an example for tool uses alone, which I renamed for consistency)
  • Expands docs, adding "Context Editing" grouping section for both clear_thinking and clear_tool_uses

Manual Verification

All examples were run against the live Anthropic API to verify correct behavior, and the fixture data was captured from those real API responses.

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)

Future Work

N/A

Related Issues

N/A

@vercel-ai-sdk vercel-ai-sdk bot added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label documentation Improvements or additions to documentation provider/anthropic Issues related to the @ai-sdk/anthropic provider labels Feb 13, 2026
Comment on lines +4498 to +4501
expect(result.usage).toMatchObject({
inputTokens: { total: 859 },
outputTokens: { total: 132 },
});
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

instead of .toMatchObject(), can we use toMatchInlineSnapshot()? That will make it much easier when we re-record the fixtures in future

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

thanks, updated in 2377abe

@felixarntz felixarntz merged commit 6f687ac into main Feb 20, 2026
17 checks passed
@felixarntz felixarntz deleted the fa-add-tests-for-anthropic-context-editing branch February 20, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label documentation Improvements or additions to documentation provider/anthropic Issues related to the @ai-sdk/anthropic provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants