12-04 更新 实时
首页/ 模型选型/ 正文

Google 为 Gemini API 预览工具检索

模型选型 来源:MarkTechPost 2026-11-22 18:03 2 阅读 机器翻译
Google 为 Gemini API 预览工具检索

Google 已在 Gemini API 中推出 Tool Retrieval,目前已在 Interactions API 中进入预览阶段。Gemini API Tool Retrieval 让智能体可以保有一个庞大的工具库,无需在每次提示中都发送每个参数的 schema。只有当任务需要某个工具时,模型才会加载对应的 schema。对于接入了数十个函数或 MCP 服务器的智能体而言,它针对的是一项实实在在的成本:工具定义。你可以通过我们的 GPULeaderboard.com Chrome 扩展在此查看部署选项与规格。

Tool Retrieval 是 Gemini API 的一项功能,它会推迟工具参数 schema 的加载,直到模型主动请求。Google 的文档直白地指出了这一问题:几十个函数声明就可能在每次请求中消耗数万个 Token。

借助延迟加载,模型只能看到每个工具的名称和简短描述。在检索发生之前,它看不到参数 schema。

你在 tools 数组中添加 {"type": "tool_search"}。然后对每个需要延迟加载的函数设置 defer_loading: true。@googledevs 的发布帖展示了 gemini-4-hydrogen 上一个被延迟加载的 issue_refund 函数。其代码注释提到还有 50 多个其他被延迟加载的函数。

当模型需要一个被延迟加载的工具时,响应中会包含 3 个步骤:

API 会自行解析前 2 个步骤。你的应用只需执行 function_call 并返回 function_result。

被延迟加载的函数可以带一个可选的 short_description。它会在检索期间显示,且仅在 defer_loading 为 true 时有效。

服务端是默认方式。搜索由 Gemini 执行,因此无需构建或托管索引。

客户端模式使用 "execution": "client"。你的应用自行执行查找,例如嵌入索引、注册表或权限过滤器。它在 function_result.result 中返回匹配的声明。这些工具可以在对话中途加入,即使不在初始 tools 数组中也没关系。每次客户端搜索都会多消耗 1 次往返。

这两种模式不能在同一次请求中组合使用。每次请求只允许有 1 个 tool_search 条目。

两者都可以,但有一些注意事项。在 mcp_server 条目上设置 defer_loading: true 会延迟该服务器暴露的所有工具。被延迟的 MCP 工具仍通过 Gemini API 的 MCP 支持远程执行。

在缓存方面,被延迟的 schema 不会进入提示前缀。加载后的 schema 会以内联方式追加,因此隐式缓存仍然适用。文档补充了一个注意点:延迟工具可能使提示词缩小到低于最小可缓存长度。

没有单独的费用。Token 按该模型的标准输入、缓存和输出费率计费。每次服务器端搜索都会基于完整上下文触发一次额外的模型调用。这些 Token 会出现在 total_tool_use_tokens 中,按输入费率计费。

之后,每个已加载的 schema 在剩余对话中都会持续按输入计费。文档称,对于小型工具库或每轮搜索的场景,静态加载可能成本更低。

Anthropic 和 OpenAI 已经推出了类似的工具搜索功能,并公布了节省数据。

Anthropic 和 OpenAI 的数字是各自在自家测试中自行报告的,无法与任何 Gemini 的结果相比较。

查看 Google 博客文章、Tool Retrieval 文档和 MCP 函数调用文档。你可以通过我们的 GPULeaderboard.com Chrome 扩展在这里查看部署选项和规格。

需要与我们合作推广你的 GitHub 仓库或 Hugging Face 页面或产品发布或网络研讨会等?请联系我们

《Google AI 在 Gemini API 中为大型工具库预览 Tool Retrieval》一文最初发布于 MarkTechPost。

译文由英文原文机器翻译,术语按行业惯例统一,可在文末展开原文核对。

查看英文原文(Google AI Previews Tool Retrieval in the Gemini API for Large Tool Libraries)

Google has launched Tool Retrieval in the Gemini API, now in preview in the Interactions API. Gemini API Tool Retrieval lets an agent keep a large tool library available. It does not send every parameter schema in every prompt. The model loads a schema only when a task needs that tool. For agents wired to dozens of functions or MCP servers, it targets a real cost: tool definitions. You can check the deployment options and specs here through our GPULeaderboard.com chrome extension.

TL;DR

  • Tool: An API feature with no stated tool cap. Google advises static loading under 20 stable tools.
  • Runs on: Google’s servers (server-side search) or your own registry (client-side). Interactions API, v1beta only.
  • Performance: Search, schema load and function call resolve in 1 API request in server mode.
  • Best: 0 extra round trips and no index to host for server-side retrieval.

What is Gemini API Tool Retrieval?

Tool Retrieval is a Gemini API feature that defers tool parameter schemas until the model asks for them. Google’s documentation states the problem plainly. A few dozen function declarations can consume tens of thousands of tokens on every request.

With deferral, the model sees only each tool’s name and a short description. It does not see the parameter schema until retrieval.

How does defer_loading work in the Gemini Interactions API?

You add {"type": "tool_search"} to the tools array. Then you set defer_loading: true on each function to hold back. The @googledevs launch post shows a deferred issue_refund function on gemini-4-hydrogen. Its code comment mentions 50+ other deferred functions.

When the model needs a deferred tool, the response contains 3 steps:

  • tool_search_call: the model requests a tool by name.
  • tool_search_result: the API returns the full schema.
  • function_call: the model emits the call your code executes.

The API resolves the first 2 steps itself. Your app only runs the function_call and returns a function_result.

Deferred functions can carry an optional short_description. It is shown during retrieval and is valid only when defer_loading is true.

Server-side vs client-side retrieval

Server-side is the default. Gemini runs the search, so there is no index to build or host.

Client-side mode uses "execution": "client". Your app runs its own lookup, such as an embedding index, registry or permission filter. It returns matching declarations in function_result.result. Those tools can join mid-conversation, even if absent from the initial tools array. Each client-side search costs 1 extra round trip.

The 2 modes cannot be combined in 1 request. Only 1 tool_search entry is allowed per request.

Does it work with MCP servers and prefix caching?

Yes on both, with caveats. Setting defer_loading: true on an mcp_server entry defers every tool that server exposes. Deferred MCP tools still execute remotely through the Gemini API MCP support.

On caching, deferred schemas stay out of the prompt prefix. Loaded schemas append inline, so implicit caching still applies. The docs add one catch: deferring tools can shrink a prompt below the minimum cacheable size.

What does Tool Retrieval cost?

There is no separate fee. Tokens bill at the model’s standard input, cached and output rates. Each server-side search triggers an extra model call over the full context. Those tokens appear in total_tool_use_tokens, billed at the input rate.

Each loaded schema then stays billed as input for the rest of the conversation. The docs say static loading can cost less for small libraries or per-turn searches.

How does it compare with Claude and OpenAI tool search?

Anthropic and OpenAI already ship similar tool search features, with published savings numbers.

FeatureGemini API Tool RetrievalAnthropic Tool Search ToolOpenAI tool search
StatusPreview, v1betaNot disclosed on docs pageNot disclosed on docs page
API surfaceInteractions API onlyMessages API; Bedrock InvokeModelResponses API
ModelsGemini 4 Carbon, Neon, Hydrogen, Argon; 3.8 Flash; 3.6 FlashClaude 5 series, Opus 4.5+, Sonnet 4.5+, Haiku 4.5gpt-5.4 and later
Search modesServer or clientRegex, BM25 or customHosted or client-executed
Max deferred toolsNot disclosed10,000Not disclosed
Results per searchNot disclosed5 by defaultNot disclosed
MCP deferralPer mcp_server entryPer mcp_toolsetOn MCP server tool
Separate feeNoNoNot disclosed
Published token savingsNone85% (77K to 8.7K tokens)47% on 250 MCP Atlas tasks
Published accuracyNoneOpus 4.5: 79.5% to 88.1%Not disclosed

Anthropic and OpenAI figures are self-reported in their own tests. They are not comparable to any Gemini result.

Play</button><button class="btn ghost" id="gnext">Next step</button><button class="btn ghost" id="greset">Reset</button></div> <p class="note">In server-side mode all 3 steps come back in 1 API request. Source: Google blog and Tool Retrieval docs.</p> </div> <div class="pane" data-p="1"> <div class="grid2"> <div class="ctx"><h4>Static: every schema, every request</h4><div id="gstatic"></div></div> <div class="ctx"><h4>Deferred: names now, schemas on demand</h4><div id="gdef"></div></div> </div> <div class="chips" id="gchips"></div> <p class="note">Click a tool to simulate the model retrieving it. Block sizes are illustrative, not measured. Google's docs: a few dozen declarations can cost tens of thousands of tokens per request. Loaded schemas stay in context and cannot be unloaded.</p> </div> <div class="pane" data-p="2"> <div class="seg"><button class="on" data-m="s">Server-side (default)</button><button data-m="c">Client-side</button></div> <table><tbody id="gmode"></tbody></table> <p class="note">The 2 modes cannot be combined in 1 request. Only 1 tool_search entry per request. Google suggests static loading for fewer than 20 stable tools.</p> </div> <div class="pane" data-p="3"> <p class="sub" style="margin:0 0 4px">Published token savings from each vendor's own tests</p> <div class="bar"><div class="lab"><span><b>Anthropic Tool Search Tool</b> (77K to 8.7K tokens)</span><b>85%</b></div><div class="tr"><div class="fl" data-w="85" style="background:#D97757"></div></div></div> <div class="bar"><div class="lab"><span><b>OpenAI tool search</b> (250 MCP Atlas tasks, 36 servers)</span><b>47%</b></div><div class="tr"><div class="fl" data-w="47" style="background:#10A37F"></div></div></div> <div class="bar"><div class="lab"><span><b>Gemini API Tool Retrieval</b></span><b>Not published</b></div><div class="tr"><div class="na">Google asks developers to measure on their own traffic</div></div></div> <button class="btn ghost" id="greplay" style="margin-top:6px">Replay bars</button> <p class="note">All figures self-reported and measured on different workloads, so they are not directly comparable. Anthropic also reports Opus 4.5 MCP eval accuracy rising from 79.5% to 88.1%.</p> </div> <div class="pane" data-p="4"> <div class="cards"> <div class="fc"><div class="in"><div class="fa"><span class="tag" style="color:#EA4335">CAVEAT</span>Preview only</div><div class="ba">v1beta, Interactions API only. generateContent is not supported. API may change before GA.</div></div></div> <div class="fc"><div class="in"><div class="fa"><span class="tag" style="color:#EA4335">CAVEAT</span>No unloading</div><div class="ba">Each loaded schema stays in context and is billed as input for the rest of the conversation.</div></div></div> <div class="fc"><div class="in"><div class="fa"><span class="tag" style="color:#F29900">COST</span>Extra model pass</div><div class="ba">Each server-side search adds a model call, reported in total_tool_use_tokens at the input rate.</div></div></div> <div class="fc"><div class="in"><div class="fa"><span class="tag" style="color:#F29900">GOTCHA</span>Resend all tools</div><div class="ba">Tool declarations are not persisted. Send the full tools array on every request.</div></div></div> <div class="fc"><div class="in"><div class="fa"><span class="tag" style="color:#F29900">GOTCHA</span>Strict replay</div><div class="ba">Stateless mode: dropping tool_search_call or a signature returns a 400 error.</div></div></div> <div class="fc"><div class="in"><div class="fa"><span class="tag" style="color:#34A853">TIP</span>Defer the long tail</div><div class="ba">Keep core tools and tools named in system instructions loaded. Prefix names by service.</div></div></div> </div> <p class="note">Tap a card to flip it. Source: Tool Retrieval docs.</p> </div> <div class="ft"><span>Sources: <a href="https://blog.google/innovation-and-ai/technology/developers-tools/gemini-api-tool-retrieval/" target="_blank" rel="noopener">Google blog</a> · <a href="https://aistudio.google.com/docs/tool-retrieval" target="_blank" rel="noopener">Docs</a></span><span class="mtp">Built by Marktechpost</span></div> </div> <script> (function(){ var R=document.getElementById('gtr-x'); function post(){try{parent.postMessage({gtrHeight:R.offsetHeight+40},'*')}catch(e){}} var tabs=R.querySelectorAll('.tab'),panes=R.querySelectorAll('.pane'); tabs.forEach(function(t){t.onclick=function(){tabs.forEach(function(x){x.classList.remove('on')});panes.forEach(function(p){p.classList.remove('on')});t.classList.add('on');R.querySelector('[data-p="'+t.dataset.t+'"]').classList.add('on');if(t.dataset.t==='3')bars();setTimeout(post,60)}}); // flow var caps=['You send a request with tool_search plus deferred tools. Only names and short descriptions enter the prompt.','The model decides it needs issue_refund and emits tool_search_call.','The API loads the issue_refund parameter schema into context as tool_search_result.','The model emits function_call with order_id and amount. Your code runs the refund.']; var st=R.querySelectorAll('.st'),cur=-1,timer=null,cap=R.querySelector('#gcap'); function show(i){cur=i;st.forEach(function(s,j){s.classList.toggle('on',j<=i)});cap.textContent=i>=0?caps[i]:'Press Play to step through a single Tool Retrieval request.';post()} show(-1); R.querySelector('#gnext').onclick=function(){clearInterval(timer);show(cur>=3?0:cur+1)}; R.querySelector('#greset').onclick=function(){clearInterval(timer);show(-1)}; R.querySelector('#gplay').onclick=function(){clearInterval(timer);show(0);timer=setInterval(function(){if(cur>=3){clearInterval(timer);return}show(cur+1)},1400)}; // static vs deferred var tools=['issue_refund','get_order','billing_get_customer','ship_label','crm_update','calendar_book']; var got={}; function draw(){var s='',d='';tools.forEach(function(t){s+='<div class="blk full">'+t+' {full schema}</div>';d+=got[t]?'<div class="blk loaded">'+t+' {schema loaded}</div>':'<div class="blk thin">'+t+': short description</div>'});R.querySelector('#gstatic').innerHTML=s;R.querySelector('#gdef').innerHTML=d;var c='';tools.forEach(function(t){c+='<button class="chip'+(got[t]?' got':'')+'" data-tool="'+t+'">'+(got[t]?'✓ ':'+ ')+t+'</button>'});R.querySelector('#gchips').innerHTML=c;R.querySelectorAll('.chip').forEach(function(b){b.onclick=function(){got[b.dataset.tool]=true;draw()}});post()} draw(); // modes var M={s:[['Who runs the search','Gemini, on Google servers'],['Retrieval code you write','None'],['Extra round trips','None'],['Remote MCP servers','Yes, defer a whole mcp_server'],['Best for','Large known libraries and MCP servers']],c:[['Who runs the search','Your app (registry, embeddings, permission filter)'],['Retrieval code you write','Yes'],['Extra round trips','1 per search'],['Remote MCP servers','Not applicable'],['Best for','Dynamic registries, namespaces, per-user tools']]}; function mode(m){var h='';M[m].forEach(function(r){h+='<tr><th>'+r[0]+'</th><td>'+r[1]+'</td></tr>'});R.querySelector('#gmode').innerHTML=h;R.querySelectorAll('.seg button').forEach(function(b){b.classList.toggle('on',b.dataset.m===m)});post()} R.querySelectorAll('.seg button').forEach(function(b){b.onclick=function(){mode(b.dataset.m)}});mode('s'); function bars(){var f=R.querySelectorAll('.fl');f.forEach(function(x){x.style.width='0'});setTimeout(function(){f.forEach(function(x){x.style.width=x.dataset.w+'%'})},80)} R.querySelector('#greplay').onclick=bars; R.querySelectorAll('.fc').forEach(function(c){c.onclick=function(){c.classList.toggle('flip')}}); window.addEventListener('load',post);window.addEventListener('resize',post);setTimeout(post,300); })(); </script> </body></html> " style="width:100%;height:600px;border:0;display:block;" loading="lazy">

Key Takeaways

  • Gemini API Tool Retrieval defers tool schemas until the model requests them.
  • Server mode resolves search, load and call in 1 API request.
  • Client mode supports custom registries, at 1 extra round trip per search.
  • No extra fee, but loaded schemas stay billed and cannot be unloaded.
  • Google published no savings data; Anthropic reports 85%, OpenAI 47%.


Check out the Google blog post, the Tool Retrieval docs and the MCP function calling docs. You can check the deployment options and specs here through our GPULeaderboard.com chrome extension.

Also, feel free to follow us on Twitter and don’t forget to join our 150k+ML SubReddit and Subscribe to our Newsletter. Wait! are you on telegram? now you can join us on telegram as well.

Need to partner with us for promoting your GitHub Repo OR Hugging Face Page OR Product Release OR Webinar etc.? Connect with us

The post Google AI Previews Tool Retrieval in the Gemini API for Large Tool Libraries appeared first on MarkTechPost.

正文保留英文原文,标题与摘要由机器翻译。

本文由采集器自动同步

原文发布于 MarkTechPost(Google AI Previews Tool Retrieval in the Gemini API for Large Tool Libraries),标题、摘要与正文由机器翻译,术语按行业惯例统一,未经人工逐句校订。

阅读原文 ↗