Gemini API Managed Agents: 3.6 Flash, hooks, and more
Gemini API Managed Agents: 3.6 Flash, hooks, and more
Gemini API Managed Agents: 3.6 Flash, hooks, and more Gemini API 的托管智能体(Managed Agents)现已默认使用 Gemini 3.6 Flash 模型。全新的环境钩子(environment hooks)允许你在沙盒内拦截、检查(lint)或审计工具调用。此外,我们还增加了预算控制、定时触发器以及免费层级访问权限。
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. Gemini API 中的托管智能体现已支持环境钩子、模型选择和免费层级访问。这些功能建立在我们之前发布的后台任务和远程 MCP 服务器集成基础之上。
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. 通过 Gemini Interactions API 中的托管智能体,只需一次 API 调用,即可在隔离的云沙盒内协调推理、代码执行、包安装、文件管理和网络检索。
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.
如果你正在使用 AI 编程助手,请在终端中运行以下命令,为其授予 Interactions API 技能访问权限: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
以下是使用 @google/genai TypeScript/JavaScript SDK 的示例。如需 Python 或 cURL 示例,请查阅 Antigravity 智能体文档。npm install @google/genai
Gemini 3.6 Flash is now the default
Gemini 3.6 Flash 现已成为默认模型
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.
antigravity-preview-05-2026 智能体现在默认运行 Gemini 3.6 Flash。无需更改任何代码,你的下一次交互将自动启用该模型。
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.
你也可以在创建交互或托管智能体时,通过传递 agent_config.model 来显式选择模型。使用 Gemini 3.5 Flash-Lite 可降低成本,或者将其固定为你偏好的模型。
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: "Audit all dependencies in package.json, upgrade outdated packages, and verify the build by running npm test.",
environment: "remote",
agent_config: {
type: "antigravity",
model: "gemini-3.5-flash-lite",
},
});
console.log(interaction.output_text);
Supported models include: 支持的模型包括:
- Gemini 3.6 Flash (gemini-3.6-flash, default): Balanced model for reasoning, coding, and tool use. Gemini 3.6 Flash (gemini-3.6-flash, 默认): 用于推理、编码和工具使用的平衡型模型。
- Gemini 3.5 Flash (gemini-3.5-flash): Previous generation for general agentic workflows. Gemini 3.5 Flash (gemini-3.5-flash): 用于通用智能体工作流的上一代模型。
- Gemini 3.5 Flash-Lite (gemini-3.5-flash-lite): Lowest latency and cost on the Gemini 3.5 family. Gemini 3.5 Flash-Lite (gemini-3.5-flash-lite): Gemini 3.5 系列中延迟最低、成本最低的模型。
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.
环境钩子允许你在智能体于沙盒内进行每次工具调用之前或之后运行自定义脚本。在你的环境中添加 .agents/hooks.json,运行时将在 pre_tool_execution(工具执行前)或 post_tool_execution(工具执行后)事件触发时执行你的处理程序。
The matcher field supports regular expressions, allowing you to target multiple tools with | or catch everything with *:
matcher 字段支持正则表达式,允许你使用 | 定位多个工具,或使用 * 捕获所有工具:
{
"security-gate": {
"pre_tool_execution": [
{
"matcher": "code_execution|write_file",
"hooks": [
{
"type": "command",
"command": "python3 /.agents/hooks-scripts/gate.py",
"timeout": 10
}
]
}
]
},
"auto-format": {
"post_tool_execution": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "python3 /.agents/hooks-scripts/auto_lint.py",
"timeout": 15
}
]
}
]
}
}
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.security-gate组在每次code_execution或write_file调用前运行gate.py。如果脚本返回{"decision": "deny", "reason": "..."},则该工具调用将被跳过,拒绝原因会被传递到模型的上下文中。 - The
auto-formatgroup runsauto_lint.pyafter every tool finishes to enforce code styling.auto-format组在每个工具执行完成后运行auto_lint.py,以强制执行代码样式。
Hooks also support http type handlers that POST directly to an external endpoint. For complete HTTP hook definitions and failure handling semantics, refer to the hooks documentation.
钩子还支持 http 类型处理程序,可直接向外部端点发送 POST 请求。有关完整的 HTTP 钩子定义和故障处理语义,请参阅钩子文档。
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.
各团队已经在使用钩子构建生产级的验证流水线。例如,AI 原生投资银行 Offdeal 使用 post_tool_execution 钩子在远程沙盒内运行自动化图像验证。
“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. “OffDeal 是一家 AI 原生投资银行,Archie 是我们银行家每天使用的 AI 分析师。银行家使用的演示文稿(decks)对公司 Logo 有严格要求:买方表格、赞助商栏、墓碑网格等,单份演示文稿中通常包含 30 多个 Logo。每一个 Logo 都必须是正确的公司,具有合适的尺寸和长宽比,包含名称,背景透明,并且在白色幻灯片上具有高对比度。
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_executionhook 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.” 在智能体钩子出现之前,我们无法在 Gemini 的托管智能体上实现这一点:因为沙盒是远程的,我们的验证代码无处运行。有了钩子,当 Archie 编写公司列表时,post_tool_execution钩子会立即在沙盒内触发我们的流水线,获取候选图像、执行像素级质量检查、使用 Gemini Vision 验证每个 Logo,并发布一份已批准文件的清单,这些文件是唯一允许进入演示文稿的图像。” — 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. 托管智能体现已在免费层级项目中可用。开发者可以使用无需激活计费的项目 API 密钥来试验智能体工作流。
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).
由于托管智能体执行多轮自主循环,复杂任务可能会消耗大量的 Token 预算。为了防止任务失控,你可以在 agent_config 中传递 max_total_tokens 来限制总消耗量(输入 + 输出 + 思维链)。
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.
当智能体达到限制时,执行将安全暂停,交互返回状态为 “incomplete”。环境状态会被保留,使你能够通过传递 previous_interaction_id 并设置新的预算,从中断处继续执行。
const interaction = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: "Audit all modules in this repo and generate a migration report.",
agent_config: {
type: "antigravity",
max_total_tokens: 10000,
},
environment: ...
});