Introduction
As Artificial Intelligence agents grow more sophisticated, connecting them to dozens of APIs and Model Context Protocol (MCP) servers has become a massive bottleneck. Passing every function schema in every prompt drains token limits and inflates costs. To solve this, Google has launched Tool Retrieval in the Gemini API (currently in preview via the Interactions API). This feature allows an AI agent to dynamically load tool schemas only when a specific task requires them, transforming how developers manage large tool libraries.
Understanding Gemini API Tool Retrieval
Traditionally, developers pass all tool declarations upfront. According to Google’s documentation, a few dozen function declarations can consume tens of thousands of tokens on every single request. Gemini API Tool Retrieval addresses this structural overhead by deferring tool parameter schemas until the model explicitly requests them. Initially, the model only sees each tool’s name and a short description, preserving vital context window capacity for your core prompt.
How defer_loading Works in the Interactions API
Implementing this feature is straightforward. Developers add {"type": "tool_search"} to the tools array and specify defer_loading: true on individual functions. When a task demands a specific function, the API resolves the request in three seamless steps:
- tool_search_call: The model requests a tool by name (e.g.,
issue_refund). - tool_search_result: The API returns the corresponding full parameter schema.
- function_call: The model emits the execution call for your application to process.
In server-side mode, the API handles the first two steps automatically, ensuring zero extra round trips for the developer.
Server-Side vs. Client-Side Retrieval Modes
Developers can choose between two distinct execution modes depending on their infrastructure requirements:
- Server-Side Retrieval (Default): Gemini manages the search natively on Google’s servers. There is no index to build or host, and the entire sequence resolves within a single API request.
- Client-Side Retrieval: Using
"execution": "client", your application runs its own lookup mechanism—such as a custom embedding index or permission filter. While this adds one extra round trip, it provides granular control over dynamic registries and per-user tool availability.
Unique AI Tip: When structuring large-scale AI agent workflows, leverage server-side retrieval for stable, globally accessible enterprise tools, and reserve client-side execution strictly for user-specific dynamic namespaces to optimize latency.
FAQ
Question 1: Does Gemini API Tool Retrieval cost extra?
Answer 1: There is no separate or hidden fee for using Tool Retrieval. Tokens are billed at the model’s standard input, cached, and output rates. However, each server-side search triggers an extra model call over the full context, which appears as total_tool_use_tokens billed at the standard input rate.
Question 2: Can I use Tool Retrieval with MCP servers?
Answer 2: Yes. Setting defer_loading: true on an mcp_server entry defers every tool that the server exposes. These deferred Model Context Protocol tools will still execute remotely through native Gemini API MCP support.
Question 3: How does Gemini’s approach compare to Anthropic and OpenAI?
Answer 3: While Anthropic and OpenAI offer similar tool-searching mechanisms with self-reported token savings (such as Anthropic reporting up to 85% savings), Google’s implementation integrates deeply with the Interactions API, offering both automated server-side search and custom client-side registry execution.
Key Takeaways
- Gemini API Tool Retrieval significantly reduces token bloat by deferring tool schemas until requested.
- Server-side mode resolves search, load, and function calls within a single API request.
- Client-side mode enables custom registries and embedding searches at the cost of one extra round trip.
- Once loaded into the conversation context, schemas remain billed and cannot be dynamically unloaded.






