We are introducing tool retrieval in the Gemini API.

Models 0 views

Gemini API Tool Retrieval defers schemas to cut token costs, preserves prefix caching, and supports server-side and client-side MCP tool selection.

Key Takeaways

  • Gemini API now supports Tool Retrieval, allowing developers to defer large tool schemas instead of loading all of them into every prompt.
  • Server-side retrieval lets Gemini search tools without developers building an index, reducing token costs while keeping frequently used tools loaded upfront.
  • Tool Retrieval works well with prefix caching and remote MCP servers, since deferred schemas can be loaded later without changing the cached prompt prefix.
  • Client-side retrieval supports custom tool registries, embeddings, and permission filters, but adds an extra round trip for each tool search.
  • Teams should weigh token savings against added latency, choosing server-side retrieval for simplicity and client-side retrieval for more control.

The Gemini API now supports Tool Retrieval, a mechanism that lets developers defer tool definitions instead of loading every schema into the prompt upfront. The feature matters because large tool libraries inflate token costs and can crowd out the context a model needs to reason. By moving tool selection to the server or the client, Gemini keeps the starting prompt lean while still making the long tail of tools reachable.

We are introducing tool retrieval in the Gemini API.

Background: why tool schemas became a context problem

Function calling in the Gemini API requires the model to see tool definitions before it can invoke them. As integrations multiply, so do schemas. The result is a prompt that carries every tool a developer might use, even when a given turn needs only one or two. Tool Retrieval changes that arrangement by separating the tools loaded at the start of a conversation from those fetched later, when the model decides it needs them.

How server-side retrieval works

With the server-side path, there is no index to build or host. Gemini runs the search on the server, so the only changes to application code are the new tool and a flag on the tools a developer wants to defer. The pattern allows keeping the most-used tools loaded up front while deferring the long tail.

Once retrieval returns a match, execution follows normal function calling: the application's code runs the refund and sends back a `function_result`.

Tool Retrieval also pairs with prefix caching. Deferred schemas stay out of the start of the prompt, and the schemas the model loads are added later in the conversation, so the cached prefix stays the same from turn to turn. That stability is the point: caching depends on an unchanged prefix, and deferred schemas do not disturb it.

The feature extends to remote MCP servers in the Gemini API. Setting `defer_loading: true` on an `mcp_server` tool loads every tool that server exposes on demand, so a developer can connect a large server without listing its tools one by one.

How client-side retrieval differs

Developers who maintain their own tool registry, embedding index, or per-user permission filter can declare `tool_search` with `"execution": "client"` and define their own search parameters. Client-side retrieval adds one round trip per search, because the application runs the lookup. The trade-off buys flexibility: tools do not need to be declared upfront, so new tools can be exposed mid-conversation when a user connects an integration.

What to watch next

The split between server-side and client-side retrieval maps onto two kinds of teams: those who want the search handled for them and those who already own a registry or permission layer. The open question is how deferred schemas interact with prefix caching across longer conversations, since the cached prefix only stays stable if loaded schemas are appended rather than inserted. Developers evaluating the feature should compare token savings against the extra round trip that client-side retrieval introduces.

Tags: Gemini APITool RetrievalFunction CallingMCPAI Developers

Comments

No comments yet. Be the first to comment.

Leave a comment