feat(anthropic): add web_fetch_20260209 and web_search_20260209#12668
feat(anthropic): add web_fetch_20260209 and web_search_20260209#12668felixarntz merged 16 commits intovercel:mainfrom
Conversation
felixarntz
left a comment
There was a problem hiding this comment.
@MehediH Thank you, this looks great!
Just one thing we should add to the Bedrock provider.
If possible, could you add examples for using these tools in examples/ai-functions? Not a blocker (since we don't have examples for the old versions of the tools either), but would be great to have for quick manual verification and for the future.
could be 4 examples:
- 1 for new
web_fetch, 1 for newweb_searchinexamples/ai-functions/src/generate-text - 1 for new
web_fetch, 1 for newweb_searchinexamples/ai-functions/src/stream-text
|
@MehediH Hmm, when I run the new I was wondering whether that's a model problem, but not entirely sure. It's strange it tries to use |
examples/ai-functions/src/generate-text/anthropic/web-fetch-20260209-wikipedia.ts
Show resolved
Hide resolved
felixarntz
left a comment
There was a problem hiding this comment.
OK, after further investigation, I've found the caveat with the examples not working as expected.
With examples/ai-functions/src/stream-text/anthropic/anthropic-web-fetch-tool-20260209.ts, the tool call results in errors like this:
Model tried to call unavailable tool 'code_execution'. Available tools: web_fetch.
This happens because the new web_fetch_2026* and web_search_2026* tools internally rely on Anthropic's code_execution_* tool. On the API level this is solved automatically, but the AI SDK has a validation mechanism that ensures only tools that are explicitly provided are considered valid, as part of packages/ai/src/generate-text/parse-tool-call.ts (line 16).
The model ends up making a code_execution tool call which is rejected with an error by the AI SDK.
It then makes a web_fetch tool call, which results in this error:
Invalid input for tool web_fetch: Type validation failed: Value: {}.\nError message: [\n {\n \"expected\": \"string\",\n \"code\": \"invalid_type\",\n \"path\": [\n \"url\"\n ],\n \"message\": \"Invalid input: expected string, received undefined\"\n }\n]
At the end, it somehow works and the content from the Wikipedia page is successfully fetched. But there are a few problems happening on the way, which are probably bugs that we need to fix.
This will require further investigation. I'll look into it.
…0260209 Adds generate-text and stream-text examples for the new webFetch_20260209 and webSearch_20260209 provider tools in the anthropic subfolder following the updated examples structure.
…t-4-6 and add missing schema types Updates examples to use claude-sonnet-4-6 model (required for 20260209 web tools) and adds encrypted_code_execution_result and server_tool_use caller schemas needed for programmatic tool calling responses.
felixarntz
left a comment
There was a problem hiding this comment.
@MehediH This looks almost good to go, but the original problem of the AI SDK blocking those code_execution tool calls that Anthropic automatically injects still persists.
Since the validation happens centrally in the ai package, we can't easily bypass it just for this particular Anthropic consideration.
I can think of two options here:
- Either, for now we require explicitly passing
code_execution: anthropic.tools.codeExecution_20260120()every time you use the newweb_fetchorweb_searchtools.- This would obviously be a workaround, not an actual fix. Not ideal, but would allow us to unblock this and think about a proper solution decoupled from this PR.
- Or, we somehow relax the conditions in the
parseToolCallfunction in theaipackage.- Currently, we only allow tool calls to go through that are
providerExecutedanddynamic. However, thecode_executiontool calls returned here are only marked withproviderExecuted, but notdynamic. This is where the validation fails. - We could allow
providerExecutedtool calls to go through in a similar way, even when they're notdynamic. That would fix this problem. - But this needs careful consideration, because obviously reducing strictness of validation increases a risk of a security gap.
- For reference: This logic was originally implemented in 81d4308 (cc @lgrammel).
- Currently, we only allow tool calls to go through that are
Please feel free to share your thoughts. I hope we can get to a decision to unblock this PR by tomorrow.
…les and warn when missing the 20260209 web tools (web_search, web_fetch) require code_execution_20260120 to work correctly in streaming mode. added the tool to stream-text examples and a warning when users use web tools without it.
|
hey @felixarntz thank you for looking into this! as discussed, I went ahead and opted for the workaround for now 28855c8 to unblock this PR; added a warning so users know the need for the new code execution tool when using these new web tools. Lmk what you think |
…rch tools where Anthropic injects it
|
@MehediH I found a cleaner solution that doesn't require the workaround of passing I also found then another bug where we were ignoring I'm going to add some more testing here, mostly focused on E2E including UI, and then we should be good to go 🎉 |
felixarntz
left a comment
There was a problem hiding this comment.
I added UI examples for this, which surface a few follow up errors which affect UI specifically:
- UI tool validation does not support dynamic tools. This leads to an error when sending any follow-up messages. While problematic here, this is an existing bug that is best fixed in its own PR.
- The error is:
No tool schema found for tool part code_execution - While this is somewhat expected because we don't include
code_executionexplicitly in the agent, it should be possible to bypass this because we treat it as an internal tool.
- The error is:
- The types in the UI break because they infer tools from the agent, but that doesn't work because the
code_executiontool is not explicitly set.
Since this implementation works for a non-interactive example, I think this is acceptable to merge as a first pass. We will need to follow up on the two remaining problems - neither of which are trivial enough to address as part of this.
|
OK, I found one more fix (see 9df88f3): We were not yet using the injected Doing that allows us to avoid the UI type errors, by properly treating the injected calls as dynamic tool calls, since that's what they are in these circumstances. What remains is the error that there's no tool result included for the I find this one confusing, because what would even that result be? As far as I understand, that code just calls the Let's look into this one separately. |
Background
Anthropic introduced new web tool versions (
web_search_20260209andweb_fetch_20260209) that include dynamic filtering capabilities, but those versions were not yet available in AI SDK.Summary
This PR adds support for
web_search_20260209andweb_fetch_20260209in the Anthropic provider.Checklist
pnpm changesetin the project root)