Skip to content

Conversation

@ryx2
Copy link
Contributor

@ryx2 ryx2 commented Dec 2, 2025

Summary

Adds support for dynamic tool discovery without loading all tool definitions upfront, reducing token usage for agents with many tools.

  • Add ToolSearchTool builtin tool for on-demand tool discovery
    • Supports search_type of 'regex' or 'bm25' (defaults to None = provider's default)
  • Add defer_loading field to ToolDefinition and Tool class
  • Automatically add ToolSearchTool when any tool has defer_loading=True
  • Update Anthropic model to map defer_loading to API
  • Enable advanced-tool-use-2025-11-20 beta automatically when features are used

Supported by Anthropic models.
See https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/tool-search-tool

Test plan

  • Added unit tests in tests/models/anthropic/test_tool_search.py
  • All tests pass
  • No new pyright errors introduced

Related

Split from #3550 per @DouweM's recommendation to separate the features into individual PRs.

🤖 Generated with Claude Code

Adds support for dynamic tool discovery without loading all tool definitions
upfront, reducing token usage for agents with many tools.

- Add `ToolSearchTool` builtin tool for on-demand tool discovery
  - Supports `search_type` of 'regex' or 'bm25' (defaults to None = provider's default)
- Add `defer_loading` field to `ToolDefinition` and `Tool` class
- Automatically add `ToolSearchTool` when any tool has `defer_loading=True`
- Update Anthropic model to map `defer_loading` to API
- Enable `advanced-tool-use-2025-11-20` beta automatically

Supported by Anthropic models.
See https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/tool-search-tool

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@DouweM
Copy link
Collaborator

DouweM commented Dec 8, 2025

Thanks for working on this @ryx2!

I was just talking to @t0yv0 who is going to work on adding support for this feature to Pydantic AI itself (#3590), so that it works for all models while using the provider-native functionality when available. See details on what that will look like at #3666 (comment).

He's going to use this PR as a starting point for the Anthropic side of things, so once he submits his extended PR I expect to close this one.

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