2026年7月28日
|
3 分钟阅读
Gemini API 中的托管代理现已默认使用 Gemini 3.6 Flash。新的环境钩子允许你在沙箱内阻止、检查或审计工具调用。此外,我们还增加了预算控制、定时触发器和免费套餐访问权限。
Philipp Schmid
Google DeepMind 技术团队成员
Mariano Cocirio
Google DeepMind 产品经理

收听文章
[[时长]] 分钟
此内容由 Google AI 生成。生成式 AI 处于实验阶段。
Gemini API 中的托管代理 现在支持环境钩子、模型选择和免费套餐访问。这些功能建立在我们之前发布的后台任务和远程 MCP 服务器集成基础之上。
通过 Gemini Interactions API 中的托管代理,一次 API 调用即可在隔离的云沙箱内协调推理、代码执行、包安装、文件管理和网络检索。
如果你正在使用 AI 编码助手,请在终端中运行以下命令,使其能够使用 Interactions API 技能:npx skills add google-gemini/gemini-skills --skill gemini-interactions-api。
以下是使用 @google/genai TypeScript/JavaScript SDK 的示例。对于 Python 或 cURL,请查看反重力代理文档。
npm install @google/genai
Gemini 3.6 Flash 现已成为默认模型
antigravity-preview-05-2026 代理现在默认运行 Gemini 3.6 Flash。无需更改代码。你的下一次交互将自动使用它。
你也可以在创建交互或托管代理时通过传递 agent_config.model 来显式选择模型。使用 Gemini 3.5 Flash-Lite 以降低成本,或固定为你偏好的模型。
支持的模型包括:
- Gemini 3.6 Flash(
gemini-3.6-flash,默认):适用于推理、编码和工具使用的均衡模型。 - Gemini 3.5 Flash(
gemini-3.5-flash):适用于通用代理工作流程的上一代模型。 - Gemini 3.5 Flash-Lite(
gemini-3.5-flash-lite):Gemini 3.5 系列中延迟最低、成本最低的模型。
环境钩子:在沙箱内阻止、检查和审计工具调用
环境钩子允许你在代理在其沙箱内进行每次工具调用之前或之后运行自定义脚本。在你的环境中添加一个 .agents/hooks.json 文件,运行时将在 pre_tool_execution 或 post_tool_execution 事件上执行你的处理程序。
matcher 字段支持正则表达式,允许你使用 | 定位多个工具,或使用 * 捕获所有工具:
在此配置中:
security-gate组在每次code_execution或write_file调用之前运行gate.py。如果脚本返回{"decision": "deny", "reason": "..."},则跳过该工具调用,并将拒绝原因传递到模型的上下文中。auto-format组在每个工具完成后运行auto_lint.py,以强制执行代码样式。- 钩子还支持
http类型的处理程序,可直接 POST 到外部端点。
有关完整的 HTTP 钩子定义和故障处理语义,请参阅钩子文档。
团队已经在使用钩子构建生产级验证管道。例如,AI 原生投资银行 Offdeal 使用 post_tool_execution 钩子在远程沙箱内运行自动图像验证。
“OffDeal 是一家 AI 原生的投资银行,Archie 是我们的银行家每天使用的 AI 分析师。银行家级演示文稿的一个要求是公司徽标:买方表格、赞助商列、墓碑网格,通常一个演示文稿中有 30 多个徽标,每个徽标都必须是正确的公司、合适的尺寸和宽高比、包含名称、具有透明背景,并且在放置在白色幻灯片上时具有高对比度。
在代理钩子出现之前,我们无法在 Gemini 的托管代理上做到这一点:沙箱是远程的,因此我们的验证代码无处运行。有了钩子,当 Archie 写入其公司列表时,一个
post_tool_execution钩子会在沙箱内触发我们的管道,获取候选者,强制执行像素级质量检查,使用 Gemini 视觉验证每个徽标,并发布一个包含仅允许进入演示文稿的图像的已批准文件清单。”
- Alston Lin,OffDeal 创始人兼 CTO
成本控制和自动化功能
免费套餐可用性
托管代理现在可在免费套餐项目中使用。开发者可以使用来自未激活计费项目的 API 密钥来试验代理工作流程。
预算控制
由于托管代理执行多轮自主循环,复杂任务可能会消耗大量令牌预算。为了防止任务失控,你可以在 agent_config 中传递 max_total_tokens 来限制总消耗量(输入 + 输出 + 思考)。
当代理达到限制时,执行会安全暂停,交互返回 status: "incomplete"。环境状态得以保留,使你能够通过传递 previous_interaction_id 和新的预算来从中断处继续。
使用触发器进行定时执行
使用定时触发器自动化重复的代理任务。触发器将代理、环境、提示和 cron 计划绑定到一个持久资源中,无需手动干预即可触发。每次运行都重用同一个沙箱,因此文件在多次执行之间得以保留。
环境 API
环境 API 允许你通过代码列出、检查和删除沙箱会话。在断开连接后恢复环境 ID,或在管道完成后清理沙箱,而无需等待 7 天的 TTL。
开始使用托管代理
这些更新将托管代理转变为成本可控、按计划运行的自动化工作者,能够在真实开发环境中自主运作,既不会超出预算,也无需外部编排。
请参阅 Gemini 交互 API 概述 和 托管代理快速入门,探索自定义代理定义、环境配置、网络规则以及高级流式处理模式。
Jul 28, 2026
|
3 min read
Managed Agents in Gemini API now default to Gemini 3.6 Flash. New environment hooks let you block, lint, or audit tool calls inside the sandbox. Also, we’ve added budget controls, scheduled triggers, and free tier access.
Philipp Schmid
Member of the Technical Staff, Google DeepMind
Mariano Cocirio
Product Manager, Google DeepMind

Listen to article
[[duration]] minutes
This content is generated by Google AI. Generative AI is experimental
Managed Agents in Gemini API are getting environment hooks, model selection, and free tier access. These capabilities build on our previous release introducing background tasks and remote MCP server integration.
With managed agents in the Gemini Interactions API, a single API call coordinates, reasoning, code execution, package installation, file management, and web retrieval inside an isolated cloud sandbox.
If you're using an AI coding assistant, drop this in your terminal to give it access to the Interactions API skill: npx skills add google-gemini/gemini-skills --skill gemini-interactions-api.
Below are examples using the @google/genai TypeScript/JavaScript SDK. For Python or cURL, check out the Antigravity agent documentation.
npm install @google/genai
Gemini 3.6 Flash is now the default
The antigravity-preview-05-2026 agent now runs Gemini 3.6 Flash by default. No code changes are required. Your next interaction picks it up automatically.
You can also explicitly select models by passing agent_config.model when creating an interaction or managed agent. Use Gemini 3.5 Flash-Lite for lower cost, or pin to your model of preference.
Supported models include:
- Gemini 3.6 Flash (
gemini-3.6-flash, default): Balanced model for reasoning, coding, and tool use. - Gemini 3.5 Flash (
gemini-3.5-flash): Previous generation for general agentic workflows. - Gemini 3.5 Flash-Lite (
gemini-3.5-flash-lite): Lowest latency and cost on the Gemini 3.5 family.
Environment hooks: block, lint, and audit tool calls inside the sandbox
Environment hooks let you run your custom scripts before or after every tool call the agent makes inside its sandbox. Add a .agents/hooks.json into your environment and the runtime executes your handlers on pre_tool_execution or post_tool_execution events.
The matcher field supports regular expressions, allowing you to target multiple tools with | or catch everything with *:
In this configuration:
- The
security-gategroup runsgate.pybefore everycode_executionorwrite_filecall. If the script returns{"decision": "deny", "reason": "..."}, the tool call is skipped and the rejection reason is passed into the model’s context. - The
auto-formatgroup runsauto_lint.pyafter every tool finishes to enforce code styling. - Hooks also support
httptype handlers that POST directly to an external endpoint.
For complete HTTP hook definitions and failure handling semantics, refer to the hooks documentation.
Teams are already using hooks to build production-grade validation pipelines. For example, AI-native investment bank Offdeal uses post_tool_execution hooks to run automated image verification inside the remote sandbox.
"OffDeal is an AI-native investment bank, and Archie is the AI analyst our bankers use every day. A requirement for banker-ready decks is company logos: buyer tables, sponsor columns, tombstone grids, often 30+ logos in a single deck, every one of which must be the right company, the appropriate size and aspect ratio, contain the name, have a transparent background, and have a high contrast when placed on a white slide.
Before agent hooks, we couldn’t do this on Gemini’s managed agents: the sandbox is remote, so our validation code had nowhere to run. With hooks, a post_tool_execution hook triggers our pipeline inside the sandbox the moment Archie writes its company list, fetching candidates, enforcing pixel-level quality checks, verifying each logo with Gemini vision, and publishing a manifest of approved files that are the only images allowed into the deck."
- Alston Lin, Founder & CTO of OffDeal
Cost control and automation features
Free tier availability
Managed agents are now available on free tier projects. Developers can experiment with agentic workflows using an API key from a project without active billing.
Budget controls
Because managed agents execute multi-turn autonomous loops, complex tasks can consume significant token budgets. To prevent runaway tasks, you can pass max_total_tokens inside agent_config to cap total consumption (input + output + thinking).
When the agent reaches the limit, execution safely pauses and the interaction returns status: "incomplete". The environment state is preserved, enabling you to continue where it stopped by passing previous_interaction_id with a fresh budget.
Scheduled execution with triggers
Automate recurring agent tasks with scheduled triggers. A trigger binds an agent, environment, prompt, and cron schedule into a persistent resource that fires without manual intervention. Each run reuses the same sandbox, so files persist across executions.
Environments API
The Environments API lets you list, inspect, and delete sandbox sessions from code. Recover environment IDs after a disconnect, or clean up sandboxes when your pipeline finishes instead of waiting for the 7-day TTL.
Get started with managed agents
These updates turn managed agents into cost-controlled, scheduled workers that operate autonomously inside real development environments without breaking your budget or requiring external orchestration.
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.
本文内容采集自官方网站,排版和翻译可能与原页面存在差异。
阅读官方全文