透過 Gemini API 的 Managed Agents,您可以運用自己的指令、技能和資料擴充 Antigravity 代理程式。您可以在互動時自訂代理程式內嵌,或將設定儲存為您透過 ID 叫用的受管理代理程式。
自訂 Antigravity 代理程式
如要快速建構自訂代理程式,最簡單的方式就是在建立新互動時,直接傳遞設定,不需要註冊步驟。您可以透過幾種主要方式擴充代理程式:
- 模型選取:透過
agent_config選擇基礎 Gemini 模型 (預設為 Gemini 3.7 Flash)。 - 系統指令:透過
system_instruction傳遞內嵌文字,以塑造行為。 - 工具:覆寫預設工具 (程式碼執行、搜尋、網址內容)、註冊遠端 MCP 伺服器,或定義自訂函式 (函式呼叫)。
- 檔案和技能:將
AGENTS.md和SKILL.md等檔案掛載到環境中。
以下是內嵌傳遞所有三個參數的範例:
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.",
system_instruction="You are a data analyst. Always include visualizations and export results as PDF.",
environment={
"type": "remote",
"sources": [
{
"type": "inline",
"target": ".agents/AGENTS.md",
"content": "Always use matplotlib for charts. Include a summary table in every report.",
},
{
"type": "inline",
"target": ".agents/skills/slide-maker/SKILL.md",
"content": "---\nname: slide-maker\n---\n# Slide Maker\nCreate HTML slide decks from data analysis results.",
},
],
},
)
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.",
system_instruction: "You are a data analyst. Always include visualizations and export results as PDF.",
environment: {
type: "remote",
sources: [
{
type: "inline",
target: ".agents/AGENTS.md",
content: "Always use matplotlib for charts. Include a summary table in every report.",
},
{
type: "inline",
target: ".agents/skills/slide-maker/SKILL.md",
content: "---\nname: slide-maker\n---\n# Slide Maker\nCreate HTML slide decks from data analysis results.",
},
],
},
}, { 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" \
-d '{
"agent": "antigravity-preview-05-2026",
"input": "Analyze the Q1 revenue data and create a slide deck.",
"system_instruction": "You are a data analyst. Always include visualizations and export results as PDF.",
"environment": {
"type": "remote",
"sources": [
{
"type": "inline",
"target": ".agents/AGENTS.md",
"content": "Always use matplotlib for charts. Include a summary table in every report."
},
{
"type": "inline",
"target": ".agents/skills/slide-maker/SKILL.md",
"content": "---\nname: slide-maker\n---\n# Slide Maker\nCreate HTML slide decks from data analysis results."
}
]
}
}'
所有項目都是在互動時定義。不必事先註冊任何項目,Antigravity 代理程式架構提供執行階段 (程式碼執行、檔案管理、網路存取),以及頂層的設定層。
工具和系統指令
您可以使用 system_instruction 和 tools 參數,自訂特定互動的代理程式行為和功能。
- 系統指令:使用
system_instruction參數傳遞內嵌文字,以塑造代理程式的行為。非常適合在每次通話時快速調整。《system_instruction》和《AGENTS.md》是加成效果,如果兩者都存在,則會同時套用。 - 工具:根據預設,Antigravity 代理程式可存取
code_execution、google_search和url_context。您可以在互動時傳遞tools參數,覆寫這份清單。您也可以註冊遠端 MCP 伺服器,或定義自訂函式 (函式呼叫),將代理程式連結至您自己的 API 和資料庫。pati 支援的工具完整詳細資料,請參閱「Antigravity Agent: Supported tools」。
以檔案為基礎的自訂
代理程式目錄結構
雖然您可以內嵌傳遞設定,但我們建議您在結構化目錄中整理代理程式的檔案。方便您管理、版本管控,以及掛接到代理程式環境。
典型的代理程式專案目錄如下所示:
my-agent/
├── AGENTS.md # Instructions on how the agent should operate
├── skills/ # Custom skills (subfolders and SKILL.md files)
│ └── slide-maker/
│ └── SKILL.md
└── workspace/ # Initial data files and knowledge
Antigravity 執行階段會掃描 .agents/ (和環境的根目錄) 是否有這些檔案。
AGENTS.md
代理程式會在啟動時,從環境中自動載入 .agents/AGENTS.md (或 /.agents/AGENTS.md) 做為系統指令。使用 AGENTS.md 進行長篇角色定義、詳細規範和說明,並與程式碼一起進行版本管控。
使用內嵌來源掛接 AGENTS.md:
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 report.",
system_instruction="You are a data analyst. Always include visualizations and export results as PDF.",
environment={
"type": "remote",
"sources": [
{
"type": "inline",
"target": ".agents/AGENTS.md",
"content": "Always use matplotlib for charts. Include a summary table in every report.",