Skip to content

Conversation

@sarth6
Copy link

@sarth6 sarth6 commented Nov 14, 2025

Closes #2971

  • Allows users to use the WebFetchTool builtin tool for Anthropic/Google models, which uses the (Claude WebFetch tool / Google URL Context tool) under-the-hood
  • Deprecates Pydantic AI UrlContextTool (which was Google-only) as users should now use WebFetchTool instead
  • Includes the Anthropic BetaWebFetchToolResultBlockParam Content (web fetch url / retrieved_at / source data / etc) in the Pydantic AI BuiltinToolReturnPart that arrives in the agent message history, so that Pydantic AI users have access to the full web fetch tool return object
  • Allows users to supply various tool config params to the Pydantic AI WebFetchTool that get passed to the Claude WebFetch tool under-the-hood; these params are not supported by Google's UrlContextToolDict unfortunately

@sarth6
Copy link
Author

sarth6 commented Nov 14, 2025

@DouweM would you prefer if we renamed UrlContextTool to WebFetchTool and left UrlContextTool in a google-only deprecated state?

@sarth6 sarth6 marked this pull request as ready for review November 18, 2025 05:37

| Provider | Supported | Notes |
|----------|-----------|-------|
| Anthropic || Full feature support. Uses Anthropic's [Web Fetch Tool](https://docs.claude.com/en/docs/agents-and-tools/tool-use/web-fetch-tool) internally to retrieve URL contents. |
Copy link
Collaborator

Choose a reason for hiding this comment

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

To answer your question in the comment: let's rename the entire thing to WebFetchTool, and keep UrlContextTool around only as an alias with a deprecation warning.


_(This example is complete, it can be run "as is")_

With Google, you can also use `UrlContextTool`:
Copy link
Collaborator

Choose a reason for hiding this comment

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

We just need one example as the only difference is the model name.

Per the above, let's not mention UrlContextTool anymore.

Should we support any of the options on https://docs.claude.com/en/docs/agents-and-tools/tool-use/web-fetch-tool#tool-definition? If so, that'd warrant a new section and Anthropic-specific example. But ideally Google would also support at least some of those.

Copy link
Author

Choose a reason for hiding this comment

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

Good idea! I'll look into adding those options

assert len(tool_calls) >= 1
assert len(tool_returns) >= 1
assert any(tc.tool_name == 'url_context' for tc in tool_calls)
assert any(tr.tool_name == 'url_context' for tr in tool_returns)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use full snapshots like in the other builtin tool tests

'Pydantic AI is a Python agent framework designed to help you quickly, confidently, and painlessly build production grade applications and workflows with Generative AI.'
)

messages = agent_run.result.all_messages()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above; full snapshots of messages and events please



@pytest.mark.vcr()
async def test_anthropic_url_context_tool_multi_turn(allow_model_requests: None, anthropic_api_key: str):
Copy link
Collaborator

Choose a reason for hiding this comment

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

See tests for other builtin tools: we typically check this by having 2 agent.runs in the same non-streaming test, where the second takes the history of the first to ensure that the API accepts it.

assert len(anthropic_messages) == 0 # No messages should be added


@pytest.mark.vcr()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why were these changes necessary?

Copy link
Author

Choose a reason for hiding this comment

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

Unecessary, my bad - removed 👍

)

result = await agent.run('How much is 3 * 12390?')
result = await agent.run('How much is 3 * 12390?') # pragma: lax no cover
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove all the new # pragma: lax no covers, I don't think they should be needed

@sarth6 sarth6 changed the title Add UrlContextTool support for Anthropic models Add WebFetchTool builtin tool support Nov 18, 2025
@sarth6 sarth6 requested a review from DouweM November 19, 2025 00:39
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.

Support Anthropic Web Fetch built-in tool

2 participants