AI coding agents

Gemini API Tool Retrieval: load agent tool schemas on demand

In short

On 19 November 2026 Google released Tool Retrieval in preview in the Gemini Interactions API. Add a tool_search tool and mark function or MCP tools with defer_loading, and the model sees only their names and descriptions until it needs one. Google says this cuts input tokens and improves tool selection with large tool sets.

Google added Tool Retrieval to the Gemini API on 19 November 2026, in preview. Instead of sending every tool's full JSON schema with every request, you mark tools as deferred, and the model sees only their names and descriptions until it decides it needs one. For agents wired to several MCP servers, where tool definitions can take up a large share of the prompt before the user has said anything, this is a direct way to cut input tokens and, Google says, make tool selection more accurate as the tool count grows.

How it works

You add one extra tool of type tool_search to the request, and set defer_loading: true on the function tools you want to hold back. According to the setup guide and the announcement:

  1. The model receives the name and description of each deferred tool, but not its parameter schema.
  2. When it needs a deferred tool, it asks for it by name. The API loads the schema and the model emits the function call, all inside the same request.
  3. Your code runs the function and returns a function_result, exactly as with ordinary function calling.

The search runs on Google's side, so there is no index for you to build or host. Each lookup shows up in interaction.steps as a tool_search_call, a tool_search_result and then the function_call, which helps when a tool isn't being found because its name or description is vague.

A minimal request looks like this (field names from the guide; check it for the current shape, since the API is in preview):

python
from google import genai

client = genai.Client(http_options={"api_version": "v1beta"})

tools = [
    {"type": "tool_search"},
    {
        "type": "function",
        "name": "get_order_status",
        "description": "Look up the shipping status of an order.",
        "defer_loading": True,
        "parameters": {
            "type": "object",
            "properties": {"order_id": {"type": "string"}},
            "required": ["order_id"],
        },
    },
]

interaction = client.interactions.create(
    model="gemini-3.6-flash",
    input="Where is order A1234?",
    tools=tools,
)

Google's advice is to leave frequently used tools undeferred and defer the long tail. Because deferred schemas stay out of the prompt prefix, prefix caching still works across turns.

MCP servers

For remote MCP servers, setting defer_loading: true on the mcp_server tool defers every tool that server exposes. That is the case most coding agents care about: a GitHub, issue tracker or observability server can expose dozens of tools each, and most of them go unused in any given task.

Client-side retrieval

If you already have a tool registry, an embedding index or per-user permissions, you can run the search yourself. Declare tool_search with "execution": "client" and give it your own name, description and parameters (for example a query string). When the model calls it, your app returns the matching function schemas in a function_result. This costs one extra round trip per search, but it lets you filter tools by permission or add new tools part-way through a conversation. You can't combine it with defer_loading.

Limits and gotchas

The guide lists several constraints that are easy to trip over:

  • Interactions API only. Tool Retrieval is not available through generateContent, and it needs the v1beta API version.
  • Model support. The announcement says Gemini 3.6 and later, including the Gemini 4 models. The guide lists gemini-4-hydrogen, gemini-4-argon, gemini-3.8-flash and gemini-3.6-flash, and says defer_loading on other models returns a 400 error. If you were planning to use it with Gemini 4 Neon, confirm support in the guide first.
  • One tool_search per request, and you must resend the full tools array on every request, including function_result turns. Tool declarations do not carry over.
  • No unloading. Once a schema is retrieved it stays in context, and is billed as input, for the rest of the conversation.
  • Stateless conversations must send tool_search_call and tool_search_result steps back unchanged, including their signature values, or the request fails with a 400.
  • Don't defer tools you name elsewhere. If the system instructions or another tool's output mention a deferred tool by name, the model may call it without searching, and the request fails.
  • Misses are text. A search that matches nothing returns text rather than a structured error, so don't rely on tool_search_result to detect failures.

What it costs

There is no separate charge; standard token rates apply. Enabling tool_search adds a small fixed block of input tokens, each server-side search adds an extra model pass billed as input, and every loaded schema counts as input for the rest of the conversation. Whether you save money depends on how many schemas would otherwise have been sent and never used. Google's own advice is to measure on your traffic, and that is the right approach: log input tokens per task with and without deferral on a sample of real sessions before switching over.

What this means for agent builders

The pattern itself is not new. Agents have been trimming tool lists by hand, or routing between smaller toolsets, for as long as tool lists have been long. What changes here is that the provider does the retrieval server-side, inside one request, with traces you can inspect.

The practical consequence is that tool descriptions become the interface. A deferred tool is found only by its name and description, so "Search issues" will lose to "Search Linear issues by text, assignee or label; returns id, title and state". The same principle applies to any agent that chooses tools from text. In CodeBeast, for example, the description you give a custom API integration is what the agent reads to decide how to call that API, so being specific about endpoints pays off there too.

Things to try:

  • Audit your current tool list. Count how many schemas you send per request and how many are called in a typical session.
  • Defer whole MCP servers that are used occasionally, and keep the two or three tools you use on nearly every turn loaded.
  • Rewrite vague tool descriptions before turning deferral on, then read the tool_search_call steps to see what the model searched for.

Open questions

The guide doesn't state a maximum number of deferred tools, or how retrieval quality changes with very large registries. As a preview, field names and behaviour may change before general availability.

Sources

FAQ

What is Tool Retrieval in the Gemini API?

It is a preview feature of the Gemini Interactions API that lets an agent keep many tools available while loading each tool's parameter schema only when the model needs it. You enable it by adding a tool_search tool and setting defer_loading: true on function or MCP server tools.

Which Gemini models support tool retrieval?

Google's announcement says Gemini 3.6 and later. The setup guide lists gemini-4-hydrogen, gemini-4-argon, gemini-3.8-flash and gemini-3.6-flash, and requests using defer_loading on other models return a 400 error.

Does Gemini tool retrieval cost extra?

There is no separate fee, but it is not free. Enabling tool_search adds a fixed block of input tokens, each server-side search adds a billed model pass, and every loaded schema stays in context as input. Savings depend on how many schemas you avoid sending.

Can I use tool retrieval with my own tool registry?

Yes. Declare tool_search with "execution": "client" and your own parameters, and return matching function schemas when the model calls it. This adds a round trip per search but lets you apply your own ranking or permission filters.

Written by the CodeBeast Team with AI assistance. Spotted a mistake? Email support@codebeast.ai.