Add deferred tool loading and hosted tool search (OpenAI + Anthropic)#697
Draft
behzadsp wants to merge 3 commits into
Draft
Add deferred tool loading and hosted tool search (OpenAI + Anthropic)#697behzadsp wants to merge 3 commits into
behzadsp wants to merge 3 commits into
Conversation
…opic Lets agents defer tool definitions so supporting providers load them on demand via hosted tool search, reducing input tokens and improving tool-selection accuracy for agents with many tools. - #[Deferred] marks a tool for on-demand loading - #[ToolSearch(strategy:)] enables the hosted search entry on an agent (strategy selects Anthropic's regex or bm25 variant; OpenAI ignores it) - SupportsToolSearch gates by provider and model (gpt-5.4+; Sonnet/Opus 4.0+, Haiku 4.5+); unsupported providers and models silently emit tools as before - Anthropic guards against an all-deferred toolset, which the provider rejects with a 400 Backward compatible: with no opt-in, request output is unchanged.
|
Thanks for submitting a PR! Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface. Pull requests that are abandoned in draft may be closed due to inactivity. |
Member
Reworked the API around a
|
Member
|
My agent's review. Blocking
Should fix
Consider
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds opt-in deferred tool loading backed by each provider's hosted tool search, so an agent's tool definitions can be loaded on demand instead of shipped in every request. This reduces input tokens and improves tool-selection accuracy for agents with many tools, while staying fully backward compatible.
The defer flag is identical across providers (
defer_loading: true); only the search-tool entry differs. That seam is where the abstraction lives: a provider-neutral opt-in on the tool/agent, per-gateway emission of the search entry.API
#[Deferred]marks a tool for on-demand loading (mirrors the existing#[Strict]attribute).#[ToolSearch]on the agent enables the hosted search entry; itsstrategyselects Anthropic'sregex/bm25variant.Contracts\Providers\SupportsToolSearchgates by provider + model.Behavior
{"type":"tool_search"}tool_search_tool_{regex,bm25}_20251119(+name)#[ToolSearch]/#[Deferred], request output is byte-identical to today.defer_loading).LogicExceptioninstead, and never defers the search entry itself.tool_referenceexpansion is handled server-side by both providers.Tests
#[Deferred]resolution,#[ToolSearch]strategy resolution, OpenAI + Anthropic tool mapping (defer flag, search entry, silent skip, all-deferred guard), provider model gating.#[ToolSearch]+ a#[Deferred]tool emits the correct request body on both providers.Out of scope
tool_referenceresults; separate PR.mcp_toolsetdeferred loading.References