Defer selected tools behind provider-native tool search.
Instead of sending every tool schema on every turn, this middleware marks
selected tools as deferred (via extras["defer_loading"]) and injects the
provider's server-side tool search tool. The provider then retrieves the
full schema of a deferred tool only when the model needs it, which keeps the
request payload small when many tools are bound.
A tool is deferred when its name (or instance) is passed in searchable_tools,
or when it already carries extras["defer_loading"] is True.
Only providers with server-side tool search are supported (currently
Anthropic and OpenAI). The provider is inferred from the bound model.
Warning
This relies on provider-native tool search and only takes effect for
supported providers. If a tool is deferred but the model's provider
cannot be identified or does not support tool search, the model call
raises ValueError. When no tool is deferred, the middleware passes the
request through unchanged regardless of provider.