Antigravity 智能体是 Gemini API 上的通用托管式智能体。只需一次 API 调用,您就可以获得一个智能体,该智能体可以在 Google 托管的您自己的安全 Linux 沙盒中进行推理、执行代码、管理文件和浏览网页。
它由 Gemini 3.5 Flash 提供支持,并使用与 Antigravity IDE 相同的 harness。您可以通过 Interactions API 和 Google AI Studio 使用它。
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
agent="antigravity-preview-05-2026",
input="Read Hacker News, summarize the top 10 stories, and save the results as a PDF.",
environment="remote",
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: "Read Hacker News, summarize the top 10 stories, and save the results as a PDF.",
environment: "remote",
}, { timeout: 300000 });
console.log(interaction.output_text);
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Api-Revision: 2026-05-20" \
-d '{
"agent": "antigravity-preview-05-2026",
"input": "Read Hacker News, summarize the top 10 stories, and save the results as a PDF.",
"environment": "remote"
}'
功能
每次调用都可以预配 Linux 沙盒并启动工具使用循环。智能体会进行规划、执行操作、观察结果,并重复执行这些步骤,直到任务完成。
- 代码执行 :运行 Bash、Python 和 Node.js 命令。安装软件包、运行测试、构建应用。
- 文件管理 :在沙盒中读取、写入、修改、搜索和列出文件。文件在多次交互中保持不变。
- 网络访问 :Google 搜索和网址提取,用于获取数据。
- 上下文压缩 :自动上下文压缩(在令牌数达到约 13.5 万时触发),以支持长时间运行的多轮会话,而不会丢失上下文或达到令牌限制。
如需了解多轮使用和流式传输,请参阅快速入门。
支持的工具
默认情况下,智能体有权访问 code_execution、google_search 和 url_context。当您指定 environment 参数时,文件系统工具会自动启用。您只需在自定义或限制默认集时指定 tools 参数:
| 工具 | 类型值 | 说明 |
|---|---|---|
| 代码执行 | code_execution |
运行 shell 命令(bash、Python、Node),并捕获 stdout/stderr。 |
| Google 搜索 | google_search |
搜索公共网络。 |
| 网址上下文 | url_context |
提取和读取网页。 |
| 文件系统 | (通过 environment 启用) |
在沙盒中读取、写入、修改、搜索和列出文件。没有单独的工具类型,在设置 environment 时会自动启用。 |
如需将智能体限制为特定工具,请仅传递所需的工具:
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
agent="antigravity-preview-05-2026",
input="Search for the latest AI research papers on reasoning and summarize them.",
environment="remote",
tools=[
{"type": "google_search"},
{"type": "url_context"},
],
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: "Search for the latest AI research papers on reasoning and summarize them.",
environment: "remote",
tools: [
{ type: "google_search" },
{ type: "url_context" },
],
}, { timeout: 300000 });
console.log(interaction.output_text);
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Api-Revision: 2026-05-20" \
-d '{
"agent": "antigravity-preview-05-2026",
"input": "Search for the latest AI research papers on reasoning and summarize them.",
"environment": "remote",
"tools": [
{"type": "google_search"},
{"type": "url_context"}
]
}'
多模态输入
Antigravity 智能体支持多模态输入。目前,仅支持 text 和 image 输入。图片必须以内嵌 base64 编码字符串 (data) 的形式提供。
Python
import base64
from google import genai
client = genai.Client()
with open("path/to/chart.png", "rb") as f:
image_bytes = f.read()
interaction_inline = client.interactions.create(
agent="antigravity-preview-05-2026",
input=[
{"type": "text", "text": "Analyze this chart and summarize the trends."},
{
"type": "image",
"data": base64.b64encode(image_bytes).decode("utf-8"),
"mime_type": "image/png",
},
],
environment="remote",
)
JavaScript
import { GoogleGenAI } from "@google/genai";
import * as fs from "node:fs";
const client = new GoogleGenAI({});
const base64Image = fs.readFileSync("path/to/chart.png", { encoding: "base64" });
const interactionInline = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: [
{ type: "text", text: "Analyze this chart and summarize the trends." },
{
type: "image",
data: base64Image,
mime_type: "image/png",
},
],
environment: "remote",
}, { timeout: 300000 });
REST
BASE64_IMAGE=$(base64 -w0 /path/to/chart.png)
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Api-Revision: 2026-05-20" \
-d "{
\"agent\": \"antigravity-preview-05-2026\",
\"input\": [
{\"type\": \"text\", \"text\": \"Analyze this chart and summarize the trends.\"},
{
\"type\": \"image\",
\"mime_type\": \"image/png\",
\"data\": \"$BASE64_IMAGE\"
}
],
\"environment\": \"remote\"
}"
系统指令
您可以使用 system_instruction 自定义智能体的行为,以获取内嵌提示,也可以通过将指令文件装载到环境中来实现:
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
agent="antigravity-preview-05-2026",
input="Analyze the uploaded CSV and create a report.",
environment="remote",
system_instruction="You are a data analyst. Always include visualizations and export results as PDF.",
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: "Analyze the uploaded CSV and create a report.",
environment: "remote",
system_instruction: "You are a data analyst. Always include visualizations and export results as PDF.",
}, { timeout: 300000 });
console.log(interaction.output_text);
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Api-Revision: 2026-05-20" \
-d '{
"agent": "antigravity-preview-05-2026",
"input": "Analyze the uploaded CSV and create a report.",
"environment": "remote",
"system_instruction": "You are a data analyst. Always include visualizations and export results as PDF."
}'
智能体会自动从环境中加载指令文件:
AGENTS.md:如果在.agents/或工作区根目录中找到,则会附加为系统指令。SKILL.md:从.agents/skills/加载,并注册为智能体可以调用的功能。
例如:
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
agent="antigravity-preview-05-2026",
input="Analyze the Q1 revenue data and create a slide deck.",
environment={
"type": "remote",
"sources": [
{
"type": "inline",
"target": ".agents/AGENTS.md",
"content": "You are a data analyst. Always use matplotlib for charts.",
},
{
"type": "inline",
"target": ".agents/skills/slide-maker/SKILL.md",
"content": "---\nname: slide-maker\n---\n# Slide Maker\nCreate HTML slide decks...",
},
],
},
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
agent: "antigravity-preview-05-2026",
input: "Analyze the Q1 revenue data and create a slide deck.",
environment: {
type: "remote",
sources: [
{
type: "inline",
target: ".agents/AGENTS.md",
content: "You are a data analyst. Always use matplotlib for charts.",
},
{
type: "inline",
target: ".agents/skills/slide-maker/SKILL.md",
content: "---\nname: slide-maker\n---\n# Slide Maker\nCreate HTML slide decks...",
},
],
},
}, { timeout: 300000 });
console.log(interaction.output_text);
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $API_KEY" \
-d '{
"agent": "antigravity-preview-05-2026",
"input": "Analyze the Q1 revenue data and create a slide deck.",
"environment": {
"type": "remote",
"sources": [
{
"type": "inline",
"target": ".agents/AGENTS.md",
"content": "You are a data analyst. Always use matplotlib for charts."
},
{
"type": "inline",
"target": ".agents/skills/slide-maker/SKILL.md",
"content": "---\nname: slide-maker\n---\n# Slide Maker\nCreate HTML slide decks..."
}
]
}
}'
如需了解完整的智能体定义格式和可重复使用的命名智能体,请参阅构建自定义智能体。
环境
每次调用都会创建或重复使用 Linux 沙盒。environment 参数有三种形式:
| 姿势 | 说明 |
|---|---|
"remote" |
使用默认设置预配新的沙盒。 |
"env_abc123" |
按 ID 重复使用现有环境,保留所有文件和状态。 |
{...} |
完整的 EnvironmentConfig,包含自定义来源和网络规则。 |
如需详细了解来源(Git、GCS、内嵌)、网络、生命周期和资源限制,请参阅环境。
适用范围和定价
Antigravity 智能体可通过 Google AI Studio 中的 Interactions API 和 Gemini API 以预览版形式提供。
定价遵循随用随付模式,具体取决于底层 Gemini 模型的令牌和智能体使用的工具。与生成单个输出的标准聊天请求不同,Antigravity 交互是一种智能体工作流。单个请求会触发推理、工具执行、代码运行和文件管理的自主循环。
估算费用
费用因任务复杂性而异。智能体会自主确定需要多少工具调用、代码执行和文件操作。以下估算值基于运行情况。
| 任务类别 | 输入令牌 | 输出令牌 | 一般费用 |
|---|---|---|---|
| 研究和信息合成 | 10 万 - 50 万 | 1 万 - 4 万 | $0.30 - $1.00 |
| 文档和内容生成 | 10 万 - 50 万 | 1.5 万 - 5 万 | $0.30 - $1.30 |
| 流程和系统设计 | 10 万 - 40 万 | 1 万 - 3 万 | $0.25 - $0.80 |
| 数据处理和分析 | 30 万 - 300 万 | 3 万 - 15 万 | $0.70 - $3.25 |
通常会缓存 50% 到 70% 的输入令牌。包含许多工具调用的复杂智能体工作流在一次交互中可能会累积 300 万到 500 万个令牌,费用高达约 5 美元。
在预览版期间,环境计算 (CPU、内存、沙盒执行)不会收费 。
限制
- 预览版状态 :Antigravity 智能体和 Interactions API 处于预览版状态。功能和架构可能会发生变化。
- 不支持的生成配置 :不支持以下参数,并且会返回 400 错误:
temperature、top_p、top_k、stop_sequences、max_output_tokens。 - 结构化输出 :Antigravity 智能体不支持结构化输出。
- 不可用的工具 :目前尚不支持
file_search、computer_use、google_maps、function_calling和mcp。 - 文件系统工具 :目前没有文件系统工具。它是
environment的一部分。 - 背景 :智能体不支持使用
background=True,并且需要store=True。 - 不支持的多模态类型 。目前不支持音频、视频和文档输入。仅允许使用文本和图片。