Source: OpenAI API documentation — Tool search
Editorial note: This is an independently published companion to the official guide. It preserves the technical structure and key examples in a condensed form. The official documentation remains the canonical and most current reference.
As an agent’s tool catalog grows, loading every definition into the model context becomes expensive. Parameter schemas consume input tokens even when the associated tools are irrelevant to the current task, and changing those definitions can invalidate a cached prompt prefix.
Tool Search addresses this problem by allowing a model to discover and load only the tools it needs at runtime. Newly discovered definitions are appended to the end of the context, helping preserve the existing cache while reducing initial context usage.
In the Responses API,
tool_searchis supported bygpt-5.4and later models.
Quick start
Enabling Tool Search in the Responses API requires two changes:
- Add
{ "type": "tool_search" }to the request’stoolsarray. - Set
defer_loading: trueon each function or MCP server that should be loaded on demand.
| |
Prefer namespaces
Tool Search works with deferred functions, namespaces, and MCP servers. Namespaces and MCP servers are generally the better organization layer because the model initially sees only their top-level names and descriptions. The detailed function definitions remain outside the context until a search loads them.
An individually deferred function is different: its name and description are still visible at the start of the request, so only most of its parameter schema is deferred. This usually produces smaller token savings.
For a namespace, defer_loading belongs on its functions, not on the namespace object. Deferred and eager functions can coexist in one namespace. Functions without defer_loading: true are callable immediately.
Give every namespace a concise description that clearly identifies its business purpose. As a practical guideline, keep a namespace below roughly ten functions; split larger catalogs along meaningful domain boundaries.
Hosted and client-executed search
Tool Search has two execution models:
| Mode | Search owner | Best fit | Main characteristic |
|---|---|---|---|
| Hosted | OpenAI | The candidate inventory is known when the request is created | The API searches and returns the loaded subset in the same response |
| Client-executed | Your application | Availability depends on tenant, project, permissions, or live state | The application owns retrieval and sends the matching definitions back |
Hosted search is the simplest default. Client-executed search is appropriate when the initial request cannot practically contain or determine the complete inventory.
Hosted Tool Search
With hosted search, declare the searchable inventory, add the built-in Tool Search entry, and let the API load the relevant subset.
In this example, get_customer_profile is immediately available while list_open_orders is deferred:
| |
When the model needs a deferred function, two records appear before the eventual function call:
tool_search_callrecords the hosted discovery step.tool_search_outputcontains the subset that has become callable.
| |
Hosted search records use execution: "server" and a null search call_id. A single search can load more than one namespace or MCP server for a cross-domain task.
Client-executed Tool Search
Client execution gives the application full control over discovery. A common implementation has two turns:
- The model emits a
tool_search_callusing an argument schema defined by the application. - The application searches its registry and returns a
tool_search_outputcontaining trusted matching definitions.
| |
Two details are essential in client mode: execution must be client, and the output must echo the exact call_id received in the search call. Once loaded, a tool behaves like an ordinary function in the following model turn.
Advanced behavior and caching
Descriptions drive discovery
The model uses a namespace description to decide whether it should search that area. Keep the top-level description brief and specific. Put richer details in the deferred functions, where they enter context only after discovery.
The loaded set persists
tool_search_output.tools defines the tools the model can call in later turns. Tools outside that array remain unavailable, and already-loaded tools do not normally need to be loaded again.
Removing a tool from the output item that defined the loaded set can disable it. However, changing that historical set invalidates the model cache from that point onward.
Dynamic injection requires trust
Client-executed search may return definitions that were not present in the original request. Treat this as an advanced pattern: validate schemas carefully and expose definitions only from a trusted registry.
Why cache preservation works
Both search modes add newly loaded definitions to the end of the model context. The stable prefix can remain cached, improving speed and reducing repeated input cost.
Injecting tools at a precise point
An additional_tools input item makes tools available at a specific point in a conversation:
| |
These tools become available only after the input item appears. Applications that manually replay conversation items must preserve its position.
Using Tool Search with the Agents API
The Agents API loads function definitions eagerly by default. To defer selected functions:
- Add
{ "type": "tool_search" }toagent.tools. - Set
defer_loading: trueon each function that should be discovered on demand.
Adding Tool Search alone does not defer every function. The session request still includes each function’s complete name, description, and parameter schema; discovery controls when that definition reaches the model.
| |
Choosing a loading strategy
| Strategy | Configuration | Useful when | Tradeoff |
|---|---|---|---|
| Eager | Omit defer_loading, or set it to false | The catalog is small or a tool is needed for most tasks | Unused definitions occupy context and changes may invalidate the cached prefix |
| Deferred | Set defer_loading: true and include Tool Search | The catalog is large and each task needs only a few tools | Discovery adds a step and depends on matching the right tool |
The Agents API supports a mixture of eager and deferred functions, though extensive mixing is usually unnecessary. Evaluate completion rate, input-token usage, and end-to-end latency on representative tasks before selecting a default.
MCP and plugin tools
When the model and provider support search, the Agents API automatically discovers MCP tools. The runtime defers searchable MCP tools and adds Tool Search as necessary across remote MCPs, executor MCPs, and MCP tools supplied by plugins.
For Agents API MCP tools, you therefore do not need to add Tool Search solely for the MCP server or apply a function-level defer_loading flag to that server. Configure it through the Agents API MCP connection mechanism. This differs from the Responses API setup described earlier.
Deployment checklist
- Split large catalogs into clearly named business namespaces, ideally with fewer than ten functions each.
- Eagerly load a small set of common tools and defer the long tail.
- Use hosted search when the inventory is known; use client execution for tenant-, permission-, or project-dependent catalogs.
- In client mode, validate every dynamic schema and preserve the search
call_id. - Keep historical tool sets and conversation item ordering stable to protect cache hits.
- Measure task success, input tokens, and total latency on real workloads.