Skip to content

fix(anthropic): resolve toolset_name for tools named like Object.prototype members - #25380

Open
yqecea wants to merge 1 commit into
vercel:mainfrom
yqecea:fix/anthropic-toolset-name-prototype-keys
Open

yqecea wants to merge 1 commit into
vercel:mainfrom
yqecea:fix/anthropic-toolset-name-prototype-keys

Conversation

@yqecea

@yqecea yqecea commented Nov 23, 2026

Copy link
Copy Markdown

Fixes #25360.

Summary

getAnthropicToolsetName resolved the toolset with toolsetNames[toolName] on a plain {} map, so a tool named like an Object.prototype member (constructor, toString) looked up the inherited function instead of falling through to the providerOptions.anthropic.toolsetName metadata fallback. The function was then dropped by JSON.stringify and the request carried no toolset_name at all. The lookup now uses hasOwnProperty, matching the pattern the codebase uses elsewhere for tool-name-keyed maps. Same class as #25354/#25355; that PR covers createToolNameMapping, this covers the separate toolsetNames site the issue names.

End-to-End Verification

Reproduction (issue's own snippet, run via stdin from examples/ai-functions so it resolves workspace packages):

pnpm exec turbo build --filter=@ai-sdk/anthropic...
cd examples/ai-functions
node --input-type=module < /tmp/ai-sdk-25360.mjs

Before the fix: lookup → toolset_name = "computer", constructor/toString → undefined.
After the fix: all three → toolset_name = "computer".

Regression test

it.each(['constructor', 'toString']) in convert-to-anthropic-prompt.test.ts asserts the metadata fallback emits toolset_name: 'computer' on both the tool_use and tool_result blocks; fails before the fix, passes after. pnpm vitest run convert-to-anthropic-prompt: 138/138.

@vercel

vercel Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

@yqecea is attempting to run Vercel CI for a fork pull request of the Vercel Team on Vercel.

A member of the Team first needs to approve it.

@vercel

vercel Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

@aipay-ai is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

@surlymochan surlymochan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verified the root cause for #25360: toolsetNames['constructor'] returns the inherited Object constructor (truthy), so the old code returned it as the toolset name and the provider-metadata fallback never ran; same for 'toString'. The hasOwnProperty check fixes both. Tests cover constructor/toString on tool-call and tool-result messages with metadata toolsetName 'computer'. Changeset included.

This branch has not been deployed

No deployments
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.

@ai-sdk/anthropic: toolset_name is dropped for tools named like Object.prototype members (constructor, toString)

3 participants