跳到正文
aihot(aihot.news)· noreply@aihot.news (Google Blog:AI)·· 3 天前精選品質評分68

Google 在 Gemini API 預覽 Tool Retrieval,按需要載入工具資料

Google 在 Gemini API 推出 Tool Retrieval 預覽

重點導讀

AI 助理接上很多工具時,每次都帶上完整設定資料,會增加輸入 token,也讓挑選工具更不容易。

  • Google 在 Gemini API 的 Interactions API 推出預覽版 Tool Retrieval,讓模型先看到工具名稱和說明,需要某項工具時再載入完整設定,並在同一次請求中接著呼叫。它也支援遠端 MCP 伺服器。
  • 若由應用程式自行搜尋工具,每次搜尋則會多一次往返。功能不另收費,但 token 仍按所用模型的標準費率計算。

AI 伴隨問答

自備 Key 深度分析

針對這篇報導有疑問?可直接點選快捷問題或向 AI 追問背景脈絡與技術細節:

推薦理由

原文說明延後載入工具引數的做法與計費方式,能幫助開發者評估大型工具庫的 token 開銷。

正文

Google Blog:AI·2026-11-20 02:00· 2 小時前精選AI 評分62

Introducing Tool Retrieval in the Gemini API

AI 導讀

Google 在 Gemini API 的 Interactions API 中以預覽形式推出 Tool Retrieval,讓AI 助理按需載入工具引數 schema,而不是每次請求都發送完整工具庫,以減少輸入 token 並在工具數量擴大時保持選擇準確。

推薦理由

原文給出按需載入工具 schema 的機制、程式碼示例和計費方式,可幫助開發者評估大型工具庫下的 token 與準確性取捨。

2026年11月19日

|

Tool Retrieval 現已在 Gemini Interactions API 中開放預覽。按需載入工具引數 schema,無需在每次提示詞中傳送完整的工具庫,旨在減少輸入 token,並在AI 助理規模擴大時保持工具選擇的準確性。


Lucia Loher

Gemini API 產品經理

Nora Kassner

Google DeepMind 研究科學家


Gemini spark on a space background

您的瀏覽器不支援音訊元素。

收聽文章

[[duration]] 分鐘

本內容由 Google AI 生成。生成式 AI 仍處於實驗階段

今天我們推出 Gemini API 中的 Tool Retrieval,現已在 Interactions API 中開放預覽。

當AI 助理接入幾十甚至上百個工具時,每次請求都發送完整的引數 schema,開銷會迅速累積:輸入 token 數被推高、延遲增加,而且候選列表越長,工具選擇的準確性越低。Tool Retrieval 讓AI 助理把完整的工具庫放在待命狀態,只在當前任務需要時才載入引數 schema。

工作原理

要啟用 Tool Retrieval,在請求中新增一個 tool_search 工具,並在你希望暫緩載入的工具上設定 defer_loading: true。模型仍然能看到每個延遲工具的 name 和 description,因此知道有哪些工具可用,但引數 schema 不會進入上下文。當模型需要某個工具時,它會按名稱請求,API 載入完整 schema,模型再呼叫該函式,整個過程都在同一個請求內完成。

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,
)

在這單次 API 呼叫中,模型搜尋 issue_refund,API 載入其 schema,模型發出 function_call。這三個步驟都會出現在 interaction.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}
 }
]

接下來就是常規的函式呼叫:你的程式碼執行退款,並返回一個 function_result。

無需構建或託管索引。Gemini 在伺服器端執行搜尋,因此你的程式碼只需改動兩處:新增的工具,以及在你想要延遲載入的工具上新增一個標誌。你可以把最常用的工具預先載入,把長尾工具延遲載入。

Tool Retrieval 也能與字首快取良好配合。延遲的 schema 不會出現在提示詞開頭,模型載入的 schema 是在對話中稍後加入的,因此快取的字首在各輪之間保持不變。

Tool Retrieval 還支援 Gemini API 中的遠端 MCP 伺服器。在 mcp_server 工具上設定 defer_loading: true,該伺服器暴露的每個工具都會按需載入,這樣你就能連線一個大型伺服器,而無需逐個列出其中的工具。

客戶端檢索如何工作

如果你維護自己的工具登錄檔、嵌入索引或按使用者許可權過濾,可以用 "execution": "client" 宣告 tool_search 並定義搜尋引數。客戶端檢索每次搜尋會多一次往返,因為查詢由你的應用執行。工具無需預先宣告,因此當用戶連線某個整合時,你也可以在對話中途暴露新工具:

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),
    }],
)

定價與支援的模型

Tool Retrieval 不單獨收費。輸入和輸出 token 按你所呼叫模型的標準費率計費。開啟 tool_search 會增加一小塊固定的輸入 token,模型載入的每個 schema 在後續對話中都會作為輸入計費,與預先宣告的工具相同。當從未載入的 schema 多於實際載入的 schema 時,你就能節省 token,對於大型工具庫來說這通常是常態。請結合你自己的流量進行衡量。

工具檢索功能可在 Interactions API 中配合 Gemini 3.6 及更高版本模型使用,包括所有 Gemini 4 模型。

如何開始

在收件箱中獲取 Google 最新資訊

訂閱我們的新聞郵件,獲取產品更新、活動資訊、特別優惠等更多內容。

你的資訊將按照Google 隱私政策使用。你可以隨時退訂。

來源:Google Blog:AI · blog.google

來源: aihot (aihot.news)
開啟原文

讀者討論

理性交流 · 即時討論