fix(provider/anthropic): fix remaining errors with Anthropic code_execution tool dynamic calls from latest web_fetch or web_search#15566
Merged
felixarntz merged 6 commits intoMay 22, 2026
Conversation
…dynamically due to web_fetch or web_search
…ic-tool-call-errors
Collaborator
aayush-kapoor
left a comment
There was a problem hiding this comment.
might be nice to add some unit tests so that this doesn't regress in the future?
aayush-kapoor
approved these changes
May 22, 2026
github-actions Bot
added a commit
that referenced
this pull request
May 22, 2026
…ecution` tool dynamic calls from latest `web_fetch` or `web_search` (#15566) ## Background When Anthropic's `web_fetch` or `web_search` tools internally trigger code execution, the API emits `code_execution` tool calls even though the user did not register that tool. The fix from #12668 marked such calls as `dynamic: true` to bypass validation, but several code paths in the Anthropic language model still emitted unmarked calls, causing errors. The newer `code_execution_20250825` tool variant also surfaces calls under sub-names (`bash_code_execution`, `text_editor_code_execution`) that need the same treatment. ## Summary - Mark `code_execution` tool calls as `dynamic` in all remaining emission sites for the 20250825 tool variant (non-streaming `bash_code_execution`/`text_editor_code_execution` branch, streaming first-delta and end paths, and streaming `tool-call` finalization). - Normalize the streaming delta path to use the unified `code_execution` provider tool name and consistently backfill input with `"type": "programmatic-tool-call"` so downstream consumers see a consistent shape. - Only set `firstDelta: true` when no input has been buffered yet, avoiding double-prefixing. This was not surfacing in a real bug so far, but it was clearly also an oversight (per `firstDelta: true` only ever being okay if there was no input yet on that same chunk). ## Manual Verification Run the existing examples: - `examples/ai-functions/src/stream-text/anthropic/web-fetch-20260209-pdf.ts` - `examples/ai-functions/src/stream-text/anthropic/web-fetch-20260209-pdf.ts` Without this PR, they will somewhere in the stream include the error about an incompatible tool being found, most times when executing them. With this PR, this error is gone from both. ## Checklist - [x] All commits are signed (PRs with unsigned commits cannot be merged) - [ ] Tests have been added / updated (for bug fixes / features) - [ ] Documentation has been added / updated (for bug fixes / features) - [x] A _patch_ changeset for relevant packages has been added (for bug fixes / features - run `pnpm changeset` in the project root) - [x] I have reviewed this pull request (self-review)
Contributor
|
✅ Backport PR created: #15569 |
Contributor
github-actions Bot
added a commit
that referenced
this pull request
May 22, 2026
…c `code_execution` tool dynamic calls from latest `web_fetch` or `web_search` (#15569) This is an automated backport of #15566 to the release-v6.0 branch. FYI @felixarntz Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Felix Arntz <felix.arntz@vercel.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
When Anthropic's
web_fetchorweb_searchtools internally trigger code execution, the API emitscode_executiontool calls even though the user did not register that tool. The fix from #12668 marked such calls asdynamic: trueto bypass validation, but several code paths in the Anthropic language model still emitted unmarked calls, causing errors. The newercode_execution_20250825tool variant also surfaces calls under sub-names (bash_code_execution,text_editor_code_execution) that need the same treatment.Summary
code_executiontool calls asdynamicin all remaining emission sites for the 20250825 tool variant (non-streamingbash_code_execution/text_editor_code_executionbranch, streaming first-delta and end paths, and streamingtool-callfinalization).code_executionprovider tool name and consistently backfill input with"type": "programmatic-tool-call"so downstream consumers see a consistent shape.firstDelta: truewhen no input has been buffered yet, avoiding double-prefixing. This was not surfacing in a real bug so far, but it was clearly also an oversight (perfirstDelta: trueonly ever being okay if there was no input yet on that same chunk).Manual Verification
Run the existing examples:
examples/ai-functions/src/stream-text/anthropic/web-fetch-20260209-pdf.tsexamples/ai-functions/src/stream-text/anthropic/web-fetch-20260209-pdf.tsWithout this PR, they will somewhere in the stream include the error about an incompatible tool being found, most times when executing them.
With this PR, this error is gone from both.
Checklist
pnpm changesetin the project root)