Getting Started with Tool Retrieval in the Gemini API
Gemini API introduces Tool Retrieval in preview, loading tool parameter schemas on demand to reduce input tokens and latency while improving tool selection accuracy. This guide covers enabling the feature, inspecting interaction steps, and client-side retrieval.
Open the official reference| Item | Details |
|---|---|
| Provider | |
| Level | Beginner |
| Published | 2026-11-19 |
| Official source | |
| Topics | #llm · #engineering |
What Is Tool Retrieval
Tool Retrieval is now available in preview in the Gemini API, within the Interactions API. When an agent connects to dozens or even hundreds of tools, sending every full parameter schema on every request adds up fast: it inflates input token counts, adds latency, and lowers tool-selection accuracy as the candidate list grows. Tool Retrieval lets your agent keep its full tool library on standby and load parameter schemas only when the current task needs them.
How to Enable Tool Retrieval
To turn on Tool Retrieval, add a tool_search tool to your request and set defer_loading: true on the tools you want to hold back. The model still sees the name and description of every deferred tool, so it knows what's available, but the parameter schemas stay out of context. When the model needs a tool, it asks for it by name, the API loads the full schema, and the model calls the function, all inside the same request.
Here is a code example:
from google import genai
client = genai.Client()
tools = [
{"type": "tool_search"},
{
"type": "function",
"name": "issue_refund",
"description": "Refund an order to the original payment method.",
"defer_loading": True,
"parameters": {
"type": "object",
"properties": {
"order_id": {"type": "string"},
"amount": {"type": "number"},
},
"required": ["order_id", "amount"],
},
},
# ... 50+ other deferred functions (leave frequent tools undeferred)
]
interaction = client.interactions.create(
model="gemini-4-hydrogen",
input="Order A-1042 arrived damaged. Please refund 40 dollars.",
tools=tools,
)Inspecting Interaction Steps
Inside that single API call, the model searches for issue_refund, the API loads its schema, and the model emits the function_call. All three steps appear in interaction.steps, making it easy to inspect which tools the model considered when debugging tool names or descriptions. Example steps:
"steps": [
{
"type": "tool_search_call",
"id": "tsc_7f2a",
"arguments": {"function_names": ["issue_refund"]},
"signature": "..."
},
{
"type": "tool_search_result",
"call_id": "tsc_7f2a",
"result": [{"type": "function", "name": "issue_refund", "parameters": {...}}],
"signature": "..."
},
{
"type": "function_call",
"id": "fc_91c3",
"name": "issue_refund",
"arguments": {"order_id": "A-1042", "amount": 40}
}
]From here it's normal function calling: your code runs the refund and sends back a function_result. There's no index to build or host. Gemini runs the search on the server, so the only changes to your code are the new tool and a flag on the tools you want to defer. You can keep your most-used tools loaded up front and defer the long tail.
Working with Prefix Caching and Remote MCP Servers
Tool Retrieval also plays well 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.
Tool Retrieval also works with remote MCP servers in the Gemini API. Set defer_loading: true on an mcp_server tool and every tool that server exposes is loaded on demand, so you can connect a large server without listing its tools one by one.
How Client-Side Retrieval Works
If you maintain your own tool registry, embedding index, or per-user permission filter, declare the tool_search with "execution": "client" and define your search parameters. Client-side retrieval adds one round trip per search, because your app runs the lookup. Tools do not need to be declared upfront, so you can also expose new tools mid-conversation when a user connects an integration:
tools = [{
"type": "tool_search",
"execution": "client",
"name": "search_tools",
"description": "Search the internal tool registry for functions.",
"parameters": {
"type": "object",
"properties": {"query": {"type": "string"}},
"required": ["query"],
},
}]
# When the model emits a function_call for "search_tools",
# return matching {"type": "function", ...} schemas in function_result:
followup = client.interactions.create(
model="gemini-4-hydrogen",
previous_interaction_id=interaction.id,
tools=tools,
input=[{
"type": "function_result",
"name": "search_tools",
"call_id": step.id,
"result": my_registry.search(**step.arguments),
}],
)Pricing and Supported Models
Tool Retrieval has no separate charge. Input and output tokens are billed at the standard rates. The feature works with Gemini 3.6 and later models.
Limitations and Scope
- The feature is in preview and may change.
- Client-side retrieval adds one round trip per search.
- Requires Gemini 3.6 or later models.
- Deferred tool parameter schemas stay out of context, but names and descriptions remain visible.
- This guide is based solely on official documentation and does not include performance benchmarks or specific cost-saving figures.
Sources & Further Reading
This page is grounded in the authoritative sources below — verifiable and citable by AI engines and readers.
- 🔗 Official source
- # Topic: LLMsLLM capabilities, products and best practices
- # Topic: EngineeringAPIs, prompting and system design
Citation: Please attribute Laojin Global (laojinchuhai.com) and keep the original link.
Made by Laojin · AI that ships
AllModelsAPIOne key for many models
AllModelsAPI is a multi-model API gateway: one key reaches many models through an OpenAI-compatible interface — point your existing code at a new base URL and you're migrated. It's not a demo: our own production workloads run on it every day.
Related
Linked by topic, people and hubs