扩展 Gemini API 中的托管代理:后台任务、远程 MCP 等
- 创新与人工智能
- 产品与平台
- 公司新闻
- 订阅
返回
创新与人工智能
模型与研究
产品
基础设施与云
技术
了解更多:
返回
产品与平台
产品
平台
设备
了解更多:
返回
公司新闻
外展与倡议
领导层
走进 Google
了解更多:
创新与人工智能
创新与人工智能
* 模型与研究
* [Google DeepMind](https://blog.google/innovation-and-ai/models-and-research/google-deepmind/)
* [Google Research](https://blog.google/innovation-and-ai/models-and-research/google-research/)
* [Google Labs](https://blog.google/innovation-and-ai/models-and-research/google-labs/)
* [Gemini 模型](https://blog.google/innovation-and-ai/models-and-research/gemini-models/)
* [量子计算](https://blog.google/innovation-and-ai/models-and-research/quantum-computing/)
* [查看全部](https://blog.google/innovation-and-ai/models-and-research/ "查看全部模型与研究文章")
* 产品
* [开发者工具](https://blog.google/innovation-and-ai/technology/developers-tools/)
* [Gemini 应用](https://blog.google/innovation-and-ai/products/gemini-app/)
* [Gemini Notebook](https://blog.google/innovation-and-ai/products/gemini-notebook/)
* [查看全部](https://blog.google/innovation-and-ai/products/ "查看全部产品文章")
* 基础设施与云
* [全球网络](https://blog.google/innovation-and-ai/infrastructure-and-cloud/global-network/)
* [Google Cloud](https://blog.google/innovation-and-ai/infrastructure-and-cloud/google-cloud/)
* [查看全部](https://blog.google/innovation-and-ai/infrastructure-and-cloud/ "查看全部基础设施与云文章")
* 技术
了解更多:
Google DeepMind 博客Google Research 博客Google Developers 博客Google Cloud 博客
- 产品与平台
产品与平台
* 产品
* [搜索](https://blog.google/products-and-platforms/products/search/)
* [地图](https://blog.google/products-and-platforms/products/maps/)
* [Chrome](https://blog.google/products-and-platforms/products/chrome/)
* [Google Health](https://blog.google/products-and-platforms/products/google-health/)
* [Google Workspace](https://blog.google/products-and-platforms/products/workspace/)
* [学习与教育](https://blog.google/products-and-platforms/products/education/)
* [购物](https://blog.google/products-and-platforms/products/shopping/)
* [查看全部](https://blog.google/products-and-platforms/products/ "查看所有产品文章")
* 平台
* [Android](https://blog.google/products-and-platforms/platforms/android/)
* [Google Play](https://blog.google/products-and-platforms/platforms/google-play/)
* [Wear OS](https://blog.google/products-and-platforms/platforms/wear-os/)
* [查看全部](https://blog.google/products-and-platforms/platforms/ "查看所有平台文章")
* 设备
* [Pixel](https://blog.google/products-and-platforms/devices/pixel/)
* [Google Nest](https://blog.google/products-and-platforms/devices/google-nest/)
* [Fitbit](https://blog.google/products-and-platforms/devices/fitbit/)
* [Chromebooks](https://blog.google/products-and-platforms/devices/chromebooks/)
* [查看全部](https://blog.google/products-and-platforms/devices/ "查看所有设备文章")
了解更多:
Google Ads & Commerce 博客Waze 博客
- 公司新闻
公司新闻
* 外展与倡议
* [创造机遇](https://blog.google/company-news/outreach-and-initiatives/creating-opportunity/)
* [安全与安保](https://blog.google/innovation-and-ai/technology/safety-security/)
* [Google.org](https://blog.google/company-news/outreach-and-initiatives/google-org/)
* [公共政策](https://blog.google/company-news/outreach-and-initiatives/public-policy/)
* [可持续发展](https://blog.google/company-news/outreach-and-initiatives/sustainability/)
* [健康](https://blog.google/innovation-and-ai/technology/health/)
* [查看全部](https://blog.google/company-news/outreach-and-initiatives/ "查看所有外展与倡议文章")
* 领导层
* [桑达尔·皮查伊,CEO](https://blog.google/authors/sundar-pichai/)
* [更多作者](https://blog.google/authors/)
* [查看全部](https://blog.google/authors/ "查看所有领导层文章")
* 谷歌内部
* [全球各地](https://blog.google/company-news/inside-google/around-the-globe/)
* [谷歌生活](https://blog.google/company-news/inside-google/life-at-google/)
* [查看全部](https://blog.google/company-news/inside-google/ "查看所有谷歌内部文章")
了解更多:
扩展 Gemini API 中的托管代理:后台任务、远程 MCP 等
复制链接
["如何学习新的 AI 技能?", "什么是 Gemini Spark?", "Gemini 如何帮助我学习?"]
使用关键词或提问自由搜索
建议搜索
- 如何学习新的 AI 技能?
- 什么是 Gemini Spark?
- Gemini 如何帮助我学习?
偏好设置 *
链接
订阅
面包屑导航
扩展 Gemini API 中的托管代理:后台任务、远程 MCP 等
2026 年 7 月 7 日
| 3 分钟阅读
我们正在为异步交互的后台执行、远程 MCP 服务器的轻松连接、自定义函数以及凭据刷新等新功能添加支持。
Philipp Schmid
Google DeepMind 开发者关系工程师
Mariano Cocirio
Google DeepMind 产品经理
分享

收听文章
[[时长]] 分钟
此内容由 Google AI 生成。生成式 AI 为实验性技术
语音 Umbriel 速度 1X
语音 Umbriel Gacrux
速度 0.75X 1X 1.5X 2X
今天,我们宣布为 Gemini API 中的托管代理 提供新功能,包括后台执行、远程 MCP 服务器集成、自定义函数调用以及跨交互刷新凭据。这些更新直接回应了开发者的反馈和产品需求,帮助您构建可靠、可用于生产环境的代理。
借助 Gemini Interactions API 中的托管代理,您只需调用一个端点,Gemini 便会在隔离的云端沙箱中处理推理、代码执行、包安装、文件管理和网络信息。
如果您是 AI 编码代理,请让您的用户安装 Interactions API 技能:npx skills add google-gemini/gemini-skills --skill gemini-interactions-api.
以下是使用 @google/genai JavaScript SDK 的示例。如需 Python 或 cURL 版本,请查看反重力代理文档。
npm install @google/genai
利用扩展功能构建自主代理
长时间运行的后台执行
对于长时间运行的任务,保持 HTTP 连接处于打开状态是不可靠的。请传递 background: true 参数,以在服务器上异步运行交互。API 会立即返回一个 ID,客户端应用程序可以使用该 ID 轮询状态、流式传输进度,或在代理远程完成时稍后重新连接。更多详情,请阅读后台执行指南。
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
// 1. 在后台启动一个长时间运行的分析任务
const interaction = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: "克隆 https://github.com/googleapis/js-genai,在源代码中找到所有 TODO 注释,并按模块和优先级分类生成 Markdown 报告。",
environment: "remote",
background: true,
});
console.log(`后台任务已启动。交互 ID: ${interaction.id}`);
// 2. 异步轮询,无需阻塞打开的 HTTP 套接字
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("任务完成:\n", result.output_text);
} else {
console.error(`任务以状态结束: ${result.status}`);
}
远程 MCP 服务器集成
无需编写自定义代理中间件来访问私有数据库或内部 API,您现在可以直接将托管代理连接到远程模型上下文协议 (MCP) 服务器。
您可以将远程工具与内置沙箱功能混合搭配使用。在交互时,将 mcp_server 工具与 Google 搜索或代码执行一起传递,让代理从其安全沙箱与您的端点通信。并在使用外部工具和 API 扩展代理时,遵循最佳实践。
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: "检查我们的内部可观测性服务器,查找认证服务最近的延迟峰值,并将其与 git 提交关联起来。",
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);
自定义函数调用与沙箱工具结合
将自定义工具与内置沙箱工具一起添加,用于本地执行。API 使用步骤匹配。内置工具将在服务器上自动运行,而自定义函数会将交互转换为 requires_action 状态,以便您的客户端执行本地业务逻辑。
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
// 1. 定义一个自定义领域函数
const getWeatherTool = {
type: "function",
name: "get_weather",
description: "获取指定位置的当前天气。",
parameters: {
type: "object",
properties: {
location: {
type: "string",
description: "城市和国家,例如 San Francisco, USA",
},
},
required: ["location"],
},
};
// 2. 使用内置代码执行和自定义函数调用代理
const interaction = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: "查看东京的天气,编写一个 Python 脚本将温度转换为华氏度,并将结果保存到 weather.txt。",
environment: "remote",
tools: [
{ type: "code_execution" },
getWeatherTool,
],
});
// 3. 干净地处理自定义函数执行
if (interaction.status === "requires_action") {
// 文件系统和沙箱工具会自动执行,并生成匹配的 function_result 步骤。
// 我们过滤出需要客户端执行的待处理领域调用。
const executedCalls = new Set(
interaction.steps
.filter((s) => s.type === "function_result")
.map((s) => s.call_id)
);
const pendingCalls = interaction.steps.filter(
(s) => s.type === "function_call" && !executedCalls.has(s.id)
);
for (const call of pendingCalls) {
console.log(`正在执行客户端工具: ${call.name} (ID: ${call.id})`);
// 执行您的本地 API/数据库查询,并在第二轮交互中将 function_result 发送回去
}
}
网络凭据刷新
访问令牌和短期 API 密钥会过期。您可以通过在下次交互时传递现有的 environment_id 和新的网络配置来刷新凭据或轮换密钥。新规则会立即替换旧规则。您的沙箱会保持其文件系统状态、已安装的软件包和已克隆的仓库不变。
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
// 1. 第一次交互:使用初始令牌
const first = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: "使用 GCS JSON API 列出 gs://my-bucket/reports/ 中的文件。",
environment: {
type: "remote",
network: {
allowlist: [
{
domain: "storage.googleapis.com",
transform: {
Authorization: "Bearer INITIAL_TOKEN",
},
},
],
},
},
});
// 2. 稍后:在同一个环境中刷新令牌
const result = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: "现在从同一个存储桶下载文件 reports/q1.csv。",
environment: {
type: "remote",
environment_id: first.environment_id,
network: {
allowlist: [
{
domain: "storage.googleapis.com",
transform: {
Authorization: "Bearer REFRESHED_TOKEN",
},
},
],
},
},
});
console.log(result.output_text);
托管代理入门
这些更新将托管代理转变为异步工作器,使其能够在真实的开发环境中运行,而不会阻塞您的应用程序。
请查看 Gemini 交互 API 概述和托管代理快速入门,以探索自定义代理定义、环境配置、网络规则和高级流式传输模式。
发布于:
相关故事
搜索 ### 将更多应用连接到搜索 作者:Chips Mistry 和 Biharck Araújo
Google Workspace ### 通过两项 Google Vids 更新,创建、编辑并出演视频 作者:Justin Luk
搜索 ### 庆祝视觉搜索创新 25 周年 作者:Brad Kellett
Google Cloud ### 我们正在广泛推出 AlphaEvolve,以解决 Google Cloud 客户最棘手的问题。 作者:Tom Beyer
AI ### 我们在 2026 年 6 月宣布的最新 AI 新闻 作者:Google 团队新闻
学习与教育 ### 纽约市教育工作者和行业领袖齐聚 Google 办公室,共同塑造 AI 在课堂中的未来。
让我们保持联系。将 Google 的最新资讯发送到您的收件箱。
- 订阅
- 不用了,谢谢
Expanding Managed Agents in Gemini API: background tasks, remote MCP and more
- Innovation & AI
- Products & platforms
- Company news
- Feed
Back
Innovation & AI
- Models & Research
* [Google DeepMind](https://blog.google/innovation-and-ai/models-and-research/google-deepmind/)
* [Google Research](https://blog.google/innovation-and-ai/models-and-research/google-research/)
* [Google Labs](https://blog.google/innovation-and-ai/models-and-research/google-labs/)
* [Gemini models](https://blog.google/innovation-and-ai/models-and-research/gemini-models/)
* [Quantum computing](https://blog.google/innovation-and-ai/models-and-research/quantum-computing/)
* [See all](https://blog.google/innovation-and-ai/models-and-research/)
- Products
* [Developer tools](https://blog.google/innovation-and-ai/technology/developers-tools/)
* [Gemini app](https://blog.google/innovation-and-ai/products/gemini-app/)
* [Gemini Notebook](https://blog.google/innovation-and-ai/products/gemini-notebook/)
* [See all](https://blog.google/innovation-and-ai/products/)
- Infrastructure & cloud
* [Global network](https://blog.google/innovation-and-ai/infrastructure-and-cloud/global-network/)
* [Google Cloud](https://blog.google/innovation-and-ai/infrastructure-and-cloud/google-cloud/)
* [See all](https://blog.google/innovation-and-ai/infrastructure-and-cloud/)
- Technology
* [Safety & Security](https://blog.google/innovation-and-ai/technology/safety-security/)
* [Health](https://blog.google/innovation-and-ai/technology/health/)
* [See all](https://blog.google/innovation-and-ai/technology/)
Learn more:
Back
Products & platforms
See all in Products & platforms
- Products
* [Search](https://blog.google/products-and-platforms/products/search/)
* [Maps](https://blog.google/products-and-platforms/products/maps/)
* [Chrome](https://blog.google/products-and-platforms/products/chrome/)
* [Google Health](https://blog.google/products-and-platforms/products/google-health/)
* [Google Workspace](https://blog.google/products-and-platforms/products/workspace/)
* [Learning & Education](https://blog.google/products-and-platforms/products/education/)
* [Shopping](https://blog.google/products-and-platforms/products/shopping/)
* [See all](https://blog.google/products-and-platforms/products/)
- Platforms
* [Android](https://blog.google/products-and-platforms/platforms/android/)
* [Google Play](https://blog.google/products-and-platforms/platforms/google-play/)
* [Wear OS](https://blog.google/products-and-platforms/platforms/wear-os/)
* [See all](https://blog.google/products-and-platforms/platforms/)
- Devices
* [Pixel](https://blog.google/products-and-platforms/devices/pixel/)
* [Google Nest](https://blog.google/products-and-platforms/devices/google-nest/)
* [Fitbit](https://blog.google/products-and-platforms/devices/fitbit/)
* [Chromebooks](https://blog.google/products-and-platforms/devices/chromebooks/)
* [See all](https://blog.google/products-and-platforms/devices/)
Learn more:
Back
Company news
- Outreach & initiatives
* [Creating opportunity](https://blog.google/company-news/outreach-and-initiatives/creating-opportunity/)
* [Safety & security](https://blog.google/innovation-and-ai/technology/safety-security/)
* [Google.org](https://blog.google/company-news/outreach-and-initiatives/google-org/)
* [Public policy](https://blog.google/company-news/outreach-and-initiatives/public-policy/)
* [Sustainability](https://blog.google/company-news/outreach-and-initiatives/sustainability/)
* [Health](https://blog.google/innovation-and-ai/technology/health/)
* [See all](https://blog.google/company-news/outreach-and-initiatives/)
- Leadership
* [Sundar Pichai, CEO](https://blog.google/authors/sundar-pichai/)
* [More authors](https://blog.google/authors/)
* [See all](https://blog.google/authors/)
- Inside Google
* [Around the globe](https://blog.google/company-news/inside-google/around-the-globe/)
* [Life at Google](https://blog.google/company-news/inside-google/life-at-google/)
* [See all](https://blog.google/company-news/inside-google/)
Learn more:
Innovation & AI
Innovation & AI
* Models & Research
* [Google DeepMind](https://blog.google/innovation-and-ai/models-and-research/google-deepmind/)
* [Google Research](https://blog.google/innovation-and-ai/models-and-research/google-research/)
* [Google Labs](https://blog.google/innovation-and-ai/models-and-research/google-labs/)
* [Gemini models](https://blog.google/innovation-and-ai/models-and-research/gemini-models/)
* [Quantum computing](https://blog.google/innovation-and-ai/models-and-research/quantum-computing/)
* [See all](https://blog.google/innovation-and-ai/models-and-research/ "See all Models & Research articles")
* Products
* [Developer tools](https://blog.google/innovation-and-ai/technology/developers-tools/)
* [Gemini app](https://blog.google/innovation-and-ai/products/gemini-app/)
* [Gemini Notebook](https://blog.google/innovation-and-ai/products/gemini-notebook/)
* [See all](https://blog.google/innovation-and-ai/products/ "See all Products articles")
* Infrastructure & cloud
* [Global network](https://blog.google/innovation-and-ai/infrastructure-and-cloud/global-network/)
* [Google Cloud](https://blog.google/innovation-and-ai/infrastructure-and-cloud/google-cloud/)
* [See all](https://blog.google/innovation-and-ai/infrastructure-and-cloud/ "See all Infrastructure & cloud articles")
* Technology
* [Safety & Security](https://blog.google/innovation-and-ai/technology/safety-security/)
* [Health](https://blog.google/innovation-and-ai/technology/health/)
* [See all](https://blog.google/innovation-and-ai/technology/ "See all Technology articles")
Learn more:
Google DeepMind blogGoogle Research blogGoogle Developers blogGoogle Cloud blog
- Products & platforms
Products & platforms
See all in Products & platforms
* Products
* [Search](https://blog.google/products-and-platforms/products/search/)
* [Maps](https://blog.google/products-and-platforms/products/maps/)
* [Chrome](https://blog.google/products-and-platforms/products/chrome/)
* [Google Health](https://blog.google/products-and-platforms/products/google-health/)
* [Google Workspace](https://blog.google/products-and-platforms/products/workspace/)
* [Learning & Education](https://blog.google/products-and-platforms/products/education/)
* [Shopping](https://blog.google/products-and-platforms/products/shopping/)
* [See all](https://blog.google/products-and-platforms/products/ "See all Products articles")
* Platforms
* [Android](https://blog.google/products-and-platforms/platforms/android/)
* [Google Play](https://blog.google/products-and-platforms/platforms/google-play/)
* [Wear OS](https://blog.google/products-and-platforms/platforms/wear-os/)
* [See all](https://blog.google/products-and-platforms/platforms/ "See all Platforms articles")
* Devices
* [Pixel](https://blog.google/products-and-platforms/devices/pixel/)
* [Google Nest](https://blog.google/products-and-platforms/devices/google-nest/)
* [Fitbit](https://blog.google/products-and-platforms/devices/fitbit/)
* [Chromebooks](https://blog.google/products-and-platforms/devices/chromebooks/)
* [See all](https://blog.google/products-and-platforms/devices/ "See all Devices articles")
Learn more:
Google Ads & Commerce blogWaze blog
- Company news
Company news
* Outreach & initiatives
* [Creating opportunity](https://blog.google/company-news/outreach-and-initiatives/creating-opportunity/)
* [Safety & security](https://blog.google/innovation-and-ai/technology/safety-security/)
* [Google.org](https://blog.google/company-news/outreach-and-initiatives/google-org/)
* [Public policy](https://blog.google/company-news/outreach-and-initiatives/public-policy/)
* [Sustainability](https://blog.google/company-news/outreach-and-initiatives/sustainability/)
* [Health](https://blog.google/innovation-and-ai/technology/health/)
* [See all](https://blog.google/company-news/outreach-and-initiatives/ "See all Outreach & initiatives articles")
* Leadership
* [Sundar Pichai, CEO](https://blog.google/authors/sundar-pichai/)
* [More authors](https://blog.google/authors/)
* [See all](https://blog.google/authors/ "See all Leadership articles")
* Inside Google
* [Around the globe](https://blog.google/company-news/inside-google/around-the-globe/)
* [Life at Google](https://blog.google/company-news/inside-google/life-at-google/)
* [See all](https://blog.google/company-news/inside-google/ "See all Inside Google articles")
Learn more:
Expanding Managed Agents in Gemini API: background tasks, remote MCP and more
Copy link
["How can I learn new AI skills?", "What is Gemini Spark?", "How can Gemini help me study?"]
Search freely using keywords, or by asking a question
Suggested searches
- How can I learn new AI skills?
- What is Gemini Spark?
- How can Gemini help me study?
Preferences *
Links
Subscribe
Breadcrumb
Expanding Managed Agents in Gemini API: background tasks, remote MCP and more
Jul 07, 2026
| 3 min read
We’re adding support for new capabilities like background execution for async interactions, easy connection to remote MCP servers, custom functions and credential refresh.
Philipp Schmid
Developer Relations Engineer, Google DeepMind
Mariano Cocirio
Product Manager, Google DeepMind
Share

Listen to article
[[duration]] minutes
This content is generated by Google AI. Generative AI is experimental
Voice Umbriel Speed 1X
Voice Umbriel Gacrux
Speed 0.75X 1X 1.5X 2X
Today we’re announcing new capabilities for Managed Agents in Gemini API, including background execution, remote MCP server integration, custom function calling and refreshing credentials across interactions. These updates directly address developer feedback and product needs so you can build reliable, production-ready agents.
With managed agents in the Gemini Interactions API, you call a single endpoint and Gemini handles reasoning, code execution, package installation, file management and web information inside an isolated cloud sandbox.
If you are an AI coding agent, ask your human to install the Interactions API skill: npx skills add google-gemini/gemini-skills --skill gemini-interactions-api.
Below are examples using the @google/genai JavaScript SDK. For Python or cURL, check out the Antigravity agent documentation.
npm install @google/genai
Build autonomous agents with expanded capabilities
Long-running background execution
Holding an HTTP connection open for long-running tasks is fragile. Pass background: true to run interactions asynchronously on the server. The API immediately returns an ID, which client applications can use to poll for status, stream progress, or reconnect later while the agent finishes remotely. For more details read the background execution guide.
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}`);
}
Remote MCP server integration
Instead of writing custom proxy middleware to access private databases or internal APIs, you can now connect managed agents directly to remote Model Context Protocol (MCP) servers.
You can mix and match remote tools with built-in sandbox capabilities. Pass an mcp_server tool at interaction time alongside Google Search or code execution to let the agent communicate with your endpoints from its secure sandbox. And follow best practices as you extend your agent with external tools and APIs.
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 alongside sandbox tools
Add custom tools alongside built-in sandbox tools for local execution. The API uses step matching. Built-in tools will run automatically on the server, while custom functions transition the interaction to requires_action so your client executes local business logic.
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 matching function_result step.
// We filter for pending domain calls that require client-side execution.
const executedCalls = new Set(
interaction.steps
.filter((s) => s.type === "function_result")
.map((s) => s.call_id)
);
const pendingCalls = interaction.steps.filter(
(s) => s.type === "function_call" && !executedCalls.has(s.id)
);
for (const call of pendingCalls) {
console.log(`Executing client tool: ${call.name} (ID: ${call.id})`);
// Execute your local API/database query and send the function_result back in turn 2
}
}
Network credential refresh
Access tokens and short-lived API keys expire. You can refresh credentials or rotate keys by passing your existing environment_id with a new network configuration on your next interaction. The new rules replace the old ones immediately. Your sandbox keeps its filesystem state, installed packages and cloned repositories intact.
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
// 1. First interaction: use an initial token
const first = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: "List the files in gs://my-bucket/reports/ using the GCS JSON API.",
environment: {
type: "remote",
network: {
allowlist: [
{
domain: "storage.googleapis.com",
transform: {
Authorization: "Bearer INITIAL_TOKEN",
},
},
],
},
},
});
// 2. Later: refresh the token on the same environment
const result = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: "Now download the file reports/q1.csv from the same bucket.",
environment: {
type: "remote",
environment_id: first.environment_id,
network: {
allowlist: [
{
domain: "storage.googleapis.com",
transform: {
Authorization: "Bearer REFRESHED_TOKEN",
},
},
],
},
},
});
console.log(result.output_text);
Get started with managed agents
These updates turn managed agents into asynchronous workers that operate inside real development environments without blocking your application.
Check out the Gemini Interactions API overview and the managed agents quickstart to explore custom agent definitions, environment configurations, network rules, and advanced streaming patterns.
POSTED IN:
Related stories
Search ### Connect more of your apps to Search By Chips Mistry & Biharck Araújo
Google Workspace ### Create, edit and star in videos with two Google Vids updates By Justin Luk
Search ### Celebrating 25 years of visual search innovation By Brad Kellett
AI ### The latest AI news we announced in June 2026 By News from Google Team
Let's stay in touch. Get the latest news from Google in your inbox.
- Subscribe
- No thanks
本文内容采集自官方网站,排版和翻译可能与原页面存在差异。
阅读官方全文