Google 在 2026 年 7 月 7 日宣布擴充 Gemini API 的 Managed Agents,重點是加入背景任務(background tasks)與遠端 MCP(Model Context Protocol)支援。對正在把 agent 放進產品的人來說,這不是單純的功能列表,而是基礎設施的轉變:agent 不再只是「問答機器」,而是可以長時間、跨系統工作的執行單元。
背景任務:把 agent 從同步對話中解放
過去呼叫 Gemini API 的 agent,多半是同步的:你送一個請求,等回應,然後結束。但真實產品裡,很多工作不是幾秒鐘能完成的,例如批次處理文件、爬取網站、生成報告。Google 這次加入的背景任務,讓 agent 可以在伺服器端非同步執行,開發者不需要一直保持連線等待結果。
對產品建構者來說,這意味著你可以把 agent 當作「非同步 worker」來設計。例如,使用者上傳一份合約,系統可以啟動一個背景任務去分析條款,完成後再通知使用者。這改變了 agent 的互動模型,也讓架構更接近傳統的 job queue 模式。不過,背景任務也帶來新的考量:你需要管理任務的生命週期、錯誤處理,以及如何把結果傳回給使用者。Google 的文件提到,這些任務可以透過 API 查詢狀態,但具體的輪詢或 webhook 機制,官方部落格沒有詳細說明。
官方部落格提供了以 @google/genai JavaScript SDK 撰寫的簡化範例:建立 interaction 時帶上 background: true,API 會立即回傳 ID,之後再用 client.interactions.get() 輪詢狀態:
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
// 1. Start a long-running analysis in the background
const interaction = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: "Clone https://github.com/googleapis/js-genai, find all TODO comments in the source code, and categorize them by module and priority in a markdown report.",
environment: "remote",
background: true,
});
console.log(`Background task started. Interaction ID: ${interaction.id}`);
// 2. Poll asynchronously without blocking an open HTTP socket
let result = interaction;
while (result.status === "in_progress") {
await new Promise((resolve) => setTimeout(resolve, 5000));
result = await client.interactions.get(interaction.id);
}
if (result.status === "completed") {
console.log("Task Completed:\n", result.output_text);
} else {
console.error(`Task ended with status: ${result.status}`);
}
遠端 MCP:把工具連線延伸到 agent 之外
MCP 已經成為 agent 連接外部工具的主流協定,但過去大多用在本地或同一環境內。Google 這次加入的遠端 MCP 支援,讓 agent 可以透過網路連接到其他伺服器上的 MCP 工具。這對企業特別有用,因為工具往往分散在不同部門或雲端環境。
實務上,這代表你可以把內部的 CRM、資料庫或第三方服務,透過 MCP server 暴露給 Gemini agent,而不需要把所有邏輯塞進同一個程式碼庫。Google 的公告強調這是「remote MCP」,但沒有深入討論認證或安全細節。對於要上線的產品,這反而是最需要自己補足的環節:遠端連線的授權、流量加密、以及防止 prompt injection 的防護,都必須在 agent 設計時一併考慮。
官方部落格的範例是在建立 interaction 時傳入 mcp_server 工具,讓 agent 從安全的沙盒中查詢內部 observability server,並將延遲尖峰與 git commits 做關聯:
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: "Check our internal observability server for recent latency spikes in the auth service and correlate them with git commits.",
environment: "remote",
tools: [
{ type: "google_search" },
{ type: "code_execution" },
{
type: "mcp_server",
name: "internal_telemetry",
url: "https://mcp.internal.example.com/mcp",
},
],
});
console.log(interaction.output_text);
同一批更新也加入了自訂函式呼叫(custom function calling):內建的沙盒工具在伺服器端自動執行,自訂函式則會讓 interaction 進入 requires_action 狀態,交由你的客戶端執行本地商業邏輯。官方部落格以 get_weather 函式為例:
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
// 1. Define a custom domain function
const getWeatherTool = {
type: "function",
name: "get_weather",
description: "Gets the current weather for a given location.",
parameters: {
type: "object",
properties: {
location: {
type: "string",
description: "The city and country, e.g. San Francisco, USA",
},
},
required: ["location"],
},
};
// 2. Invoke the agent with both built-in code execution and custom functions
const interaction = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: "Check the weather in Tokyo, write a Python script to convert the temperature to Fahrenheit, and save the result to weather.txt.",
environment: "remote",
tools: [
{ type: "code_execution" },
getWeatherTool,
],
});
// 3. Handle custom function execution cleanly
if (interaction.status === "requires_action") {
// Filesystem and sandbox tools execute automatically and produce a result
}
對產品架構的實際影響
把這兩項更新放在一起看,Google 顯然在推動 agent 從「單次對話」走向「持續運行的服務」。這對產品建構者有三個直接影響:
- 非同步優先的設計:如果 agent 要處理長時間任務,你需要重新思考使用者體驗。與其讓使用者等待,不如設計「任務已提交,完成後通知」的流程。
- 工具連線的標準化:遠端 MCP 讓工具整合更模組化,但也要求你更嚴格地管理連線設定與權限。
- 監控與除錯:背景任務和遠端連線都增加了系統複雜度。你需要更完整的 logging 和追蹤機制,才能知道 agent 到底在做什麼。
這些改變不是「加了新功能」那麼簡單,而是 agent 基礎設施的成熟化。對開發者來說,好消息是這些能力直接整合在 Gemini API 中,不需要自己搭建排程器或連線層。但壞消息是,抽象層越高,你越難理解底層行為,除錯時也越需要依賴平台提供的工具。
限制與下一步
Google 的公告提供了方向,但細節仍然有限。官方部落格沒有說明背景任務的執行時間上限、並發限制,或是遠端 MCP 的認證方式。如果你打算採用,建議先閱讀完整的 API 文件,並做小規模的概念驗證,特別是在安全性和可靠性方面。
對於正在評估 agent 平台的團隊,這次更新讓 Gemini API 成為更完整的選項,但最終的成敗還是取決於你如何設計 agent 的任務流程與錯誤處理。工具只是基礎,真正的產品價值來自於你怎麼用它解決使用者的問題。
參考來源
本文由 AI 協助自上述來源整理,經人工審核後發布。
