跪拜 Guibai
← Back to the summary

Gemini's Tool Retrieval: Load Agent Tool Schemas On Demand to Cut Tokens and Latency

You've probably run into a frustrating scenario when building AI Agents.

You want the Agent to actually do work, so you hook up a CRM, a ticketing system, email, a database, and a few MCP servers. The tool count quickly passes a few dozen or even a hundred. When the system runs, before users have said much, the input token bill spikes, first-token latency visibly worsens, and the model frequently picks the wrong tool at critical moments.

The problem often isn't the model's intelligence; it's that every request requires stuffing the complete JSON parameter specifications of all tools into the context.

On November 19, 2026, Google introduced a preview of Tool Retrieval in the Gemini API to address this pain point. It's currently built into Gemini's Interactions API (v1beta) and supports all models from Gemini 3.6 onward, including the entire Gemini 4 line.

image.png

Leave the parameter specs outside

In the past, with Function Calling, regardless of whether the tools were used in a turn, developers' code had to pass the full parameter names, types, and validation rules for all tools to the model. As tools multiplied, the context became like a book with hundreds of pages of table of contents and appendices before the main text even began.

Google's approach here is restrained; the change is just two lines of configuration.

Developers add {"type": "tool_search"} to the tools array in the request, and then add the flag "defer_loading": true to the functions or tools that don't need to appear every time. High-frequency core tools can stay resident in the foreground; long-tail tools are all set to lazy loading.

In the initial state, the model can only see the names and short descriptions of these deferred tools. The full parameters structure stays outside the context, on standby.

When a user issues a specific instruction, such as "Order A-1042 is damaged, please refund $40," the entire call automatically runs through three steps within a single API request. The model first makes a tool_search_call to retrieve issue_refund by name, the server returns a tool_search_result and loads the full parameter schema, then the model issues a standard function_call with the order number and amount.

All three steps are fully logged in interaction.steps. When debugging, developers can clearly see which tools the model searched and why it selected them. And server-side search is automatically managed by Gemini, so developers don't need to build or maintain a vector index.

image.png

Why multi-turn conversations and MCP especially need it

Many teams previously tried building RAG-based tool search at the application layer, only to find that multi-turn conversation caches all become invalid.

Because once you dynamically modify the tool list at the beginning of the Prompt in each request, the system prefix changes, and the prefix caching that could save money and speed things up fails to hit.

Tool Retrieval reverses the order. The lazily loaded schemas don't sit at the beginning of the Prompt; the tool definitions the model retrieves on demand are appended in the latter part of the conversation. As a result, the fixed system prompt and core tool prefix remain unchanged throughout multi-turn conversations, and prefix caching continues to hit normally.

For teams integrating remote MCP servers, this change is also practical. Previously, connecting to a large MCP service often meant facing dozens of exposed endpoints. Now you can simply set "defer_loading": true on the mcp_server tool definition, and all tools under that server automatically enter the on-demand loading pool, without manually declaring or trimming the list one by one.

If a team has its own permission system, or the tool list may dynamically change during a conversation as users authorize new integrations, Gemini leaves an opening. Set the tool_search execution mode to "execution": "client", and the search request is handed back to your own backend. You can filter tools locally according to the current user's permissions, then return the matching schema to the model.

The costs to count before writing code

Google hasn't charged separately for Tool Retrieval; input and output tokens are still billed at the standard rate of the selected model.

But whether to switch everything over immediately requires a few things to be clear first.

Enabling tool_search itself consumes a small fixed amount of input tokens, and once the model retrieves and loads a tool's schema, it continues to count as input tokens in subsequent conversations like an ordinary tool. Google's official blog is also blunt: only when you have more "schemas you never use" than "schemas you actually load" will you truly save tokens, and they recommend testing with your real traffic. If an Agent only has five or six tools total, or if each task almost always uses all tools, enabling lazy loading isn't worth it.

There are also clear API constraints. Tool Retrieval currently only works with the newer Interactions API; the older generateContent endpoint can't use it. And each request only allows one tool_search definition; if you write only defer_loading: true but forget tool_search, the API returns a 400 error.

If you choose "execution": "client" for custom client-side retrieval, you also pay a price: each tool search adds an extra network round-trip latency, unlike server-side retrieval which stays within a single request.

One more thing is easy to overlook. With lazy loading, the model initially sees only tool names and descriptions. If your function names are vague or descriptions are sloppy, the model may fail to find the right tool during the retrieval stage, and no matter how accurate the later parameter filling is, it's useless. Writing clear tool descriptions is more important than before.

For teams stuffing hundreds of business endpoints and MCP services into an Agent, Tool Retrieval at least saves the effort of hand-rolling tool routing and repositioning indexes. You can keep core high-frequency tools in the foreground, mark all long-tail endpoints as defer_loading: true, first run a set of typical business conversations to check the token bill and call accuracy, then decide how fine-grained to make the split.