Antigravity 代理程式是 Gemini API 上的通用型代管代理程式,只要呼叫單一 API,您就能在 Google 代管的專屬安全 Linux 沙箱中,取得可推理、執行程式碼、管理檔案及瀏覽網路的代理程式。
這項工具採用 Gemini 3.5 Flash,並使用與 Antigravity IDE 相同的安全防護措施。您可以透過 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 搜尋和擷取網址資料。
- 內容壓縮:自動壓縮內容 (約 135, 000 個權杖時觸發),支援長時間的多輪對話,不會遺失內容或達到權杖上限。
如要瞭解如何使用多輪對話和串流功能,請參閱快速入門導覽課程。
支援的工具
根據預設,代理程式可存取 code_execution、google_search 和 url_context。指定 environment 參數時,系統會自動啟用檔案系統工具。只有在自訂或限制預設集時,才需要指定 tools 參數:
| 工具 | 輸入值 | 說明 |
|---|---|---|
| 程式碼執行 | code_execution |
執行殼層指令 (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、內嵌)、網路、生命週期和資源限制,請參閱「環境」。
適用情形與定價
您可透過 Google AI Studio 和 Gemini API 的 Interactions API,試用 Antigravity 代理程式。
價格採用即付即用模式,依據基礎 Gemini 模型權杖和代理使用的工具計算。標準聊天要求只會產生單一輸出內容,但 Antigravity 互動是代理功能工作流程。單一要求會觸發自主迴圈,進行推論、執行工具、執行程式碼和管理檔案。
預估費用
費用會因工作複雜度而異。代理會自主判斷需要多少工具呼叫、程式碼執行和檔案作業。以下預估值是以跑步為依據。
| 工作類別 | 輸入詞元 | 輸出詞元 | 一般費用 |
|---|---|---|---|
| 研究與資訊整合 | 10 萬至 50 萬 | 1 萬至 4 萬 | $0.30 美元至 $1.00 美元 |
| 生成文件和內容 | 10 萬至 50 萬 | 15,000 至 50,000 | $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」的一部分。 - 背景:Agent 不支援使用
background=True,且需要store=True。 - 不支援的多模態類型。目前不支援音訊、影片和文件輸入。只能使用文字和圖片。