Skip to content

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 into
mainfrom
fix-remaining-anthropic-code-execution-dynamic-tool-call-errors
May 22, 2026
Merged

fix(provider/anthropic): fix remaining errors with Anthropic code_execution tool dynamic calls from latest web_fetch or web_search#15566
felixarntz merged 6 commits into
mainfrom
fix-remaining-anthropic-code-execution-dynamic-tool-call-errors

Conversation

@felixarntz
Copy link
Copy Markdown
Collaborator

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

  • 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)
  • 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)

@felixarntz felixarntz added the backport Admins only: add this label to a pull request in order to backport it to the prior version label May 22, 2026
@felixarntz felixarntz requested a review from aayush-kapoor May 22, 2026 20:41
Copy link
Copy Markdown
Collaborator

@aayush-kapoor aayush-kapoor left a comment

Choose a reason for hiding this comment

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

might be nice to add some unit tests so that this doesn't regress in the future?

Comment thread packages/anthropic/src/anthropic-language-model.ts Outdated
Comment thread packages/anthropic/src/anthropic-language-model.ts Outdated
Comment thread packages/anthropic/src/anthropic-language-model.ts
@felixarntz felixarntz merged commit 648705c into main May 22, 2026
48 checks passed
@felixarntz felixarntz deleted the fix-remaining-anthropic-code-execution-dynamic-tool-call-errors branch May 22, 2026 21:29
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)
@github-actions github-actions Bot removed the backport Admins only: add this label to a pull request in order to backport it to the prior version label May 22, 2026
@github-actions
Copy link
Copy Markdown
Contributor

✅ Backport PR created: #15569

@github-actions
Copy link
Copy Markdown
Contributor

🚀 Published in:

Package Version
@ai-sdk/amazon-bedrock 5.0.0-canary.69 github npm
@ai-sdk/anthropic 4.0.0-canary.59 github npm
@ai-sdk/anthropic-aws 1.0.0-canary.0 github npm
@ai-sdk/google-vertex 5.0.0-canary.93 github npm

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants