Antigravity SDK Personas 角色定義與系統指令模組化封裝

對比 google-antigravity SDK 中 TemplatedSystemInstructions 與 CustomSystemInstructions 差異,給出安全審計等 Persona 工廠封裝及 SubagentConfig 權限隔離方案。

NNathaniel bigo··原創首發·AI 輔助撰寫
8 分鐘讀完
資料核對於 2026-12-03 · 依據官方文檔與公開資料整理 Pro 帳號

結論先說

  1. 絕大多數場景首選 types.TemplatedSystemInstructions:覆蓋 identity 並追加 SystemInstructionSection 的同時,完整保留 SDK 預設腳手架與環境上下文。
  2. types.CustomSystemInstructions 會旁路全部預設腳手架:傳入原始 text 後屏蔽環境提示,僅適合需要 100% 原生 Prompt 控制的高級場景。
  3. 角色模組化應把「指令小節」與「工具權限」綁定:例如安全審計員綁定 BuiltinTools.read_only(),避免審查時意外寫盤。
  4. 通過 types.SubagentConfig 隔離多角色上下文:每個子代理可配置獨立 system_instructions、tools 與模型參數。
  5. 複雜多角色編排測試依賴高額算力池:在 IDE 調優角色規範時推薦 Gemini Google AI Ultra 充值指南 與 Gemini Google AI Ultra 5x 人工 iOS。

SDK 系統指令三大配置形態對照

圖:本站根據 Antigravity SDK Personas 文檔 整理的示意圖

本文根據 Google Antigravity SDK 官方文檔整理,資料核對於 2026-12-03。配圖為本站整理的示意圖,不是介面截圖。本站(bigolab.com)由益陽市赫山區必高科技有限公司獨立運營,是獨立第三方服務商,不是 Google 官方網站。

適用於誰

  • 把系統提示詞硬編碼成大段字符串、難以複用與評審的 Python 開發者;
  • 用了 CustomSystemInstructions 後發現 Agent 丟失工作區認知或工具調不起來的工程師;
  • 希望把安全審計、PR 審查等角色與最小工具集打包進子代理的團隊。

一、三種系統指令注入方式與模組化代碼

指令形態保留預設腳手架結構化分段適用場景
純字符串 system_instructions="..."是(基礎)無輕量單文件原型
TemplatedSystemInstructions(推薦)完整保留SystemInstructionSection代碼審查、安全審計主力方案
CustomSystemInstructions完全旁路原始文本極簡定製格式或屏蔽預設上下文
import asyncio
from google.antigravity import Agent, CapabilitiesConfig, LocalAgentConfig, types
from google.antigravity.types import BuiltinTools

def build_auditor_si() -> types.TemplatedSystemInstructions:
    return types.TemplatedSystemInstructions(
        identity="You are a strict Application Security Auditor.",
        sections=[types.SystemInstructionSection(title="audit_scope", content="- 排查硬編碼密鑰與危險反序列化,僅輸出路徑與建議。")],
    )

async def main() -> None:
    auditor = types.SubagentConfig(
        name="security_auditor",
        description="只讀安全審計子代理。",
        system_instructions=build_auditor_si(),
        capabilities=CapabilitiesConfig(enabled_tools=BuiltinTools.read_only()),
    )
    async with Agent(LocalAgentConfig(subagents=[auditor])) as agent:
        res = await agent.chat("委派 security_auditor 審計 src/auth。")
        print(await res.text())

if __name__ == "__main__":
    asyncio.run(main())

人工核對要點:

  1. 需調工作區工具的角色均採用 TemplatedSystemInstructions;
  2. 每個 SystemInstructionSection 的 title 清晰表達約束主題;
  3. 只讀審核角色已通過 BuiltinTools.read_only() 收窄寫權限。

二、Custom 指令切換邊界與子代理選型

模組化 Persona 與子代理選型決策

圖:本站根據 Antigravity SDK Personas 文檔 與 Subagents 文檔 整理的示意圖

僅當接入極小上下文的本地模型或要求完全掌控原始 Prompt 時才用 CustomSystemInstructions;包含多步操作規程的領域手冊應放到 skills_paths 的 SKILL.md 中,保持 SystemInstructionSection 精煉。

訂閱與開通提示:多角色協同調測推薦 Gemini Google AI Ultra 5x 人工 iOS 或 Gemini Google AI Ultra 20x 人工 iOS;需獨立測試帳號可看 Google 帳號與訂閱指南 或選 谷歌電郵成品號(質保 3 天首登、封號不在質保範圍,須遵守 Google 服務條款);多模型對比可搭 Claude Max 5x iOS 自助充值。全站以商品頁實時標價為準,標價不含稅,開具國內增值稅發票另付 6% 稅費;單獨申請自定義明細電子收據免費,企業批量支持籤中文合同並對公結算。

常見問題

問:換成 CustomSystemInstructions 後不會用工作區工具了怎麼回事?

答:CustomSystemInstructions 會旁路預設 SDK 腳手架與環境資訊,需要內置工程能力時請改回 TemplatedSystemInstructions。

問:長段業務 SOP 放 SystemInstructionSection 還是用 Skills?

答:人設與輸出格式放 SystemInstructionSection,長步驟領域規程建議通過 skills_paths 掛載 SKILL.md。

問:不同子代理 Persona 能綁定隔離的自定義工具嗎?

答:可以,SubagentConfig(tools=[...]) 註冊的工具會自動限定在該子代理作用域內。

問:團隊購買訂閱怎麼開 6% 增值稅發票與對公簽約?

答:在 AI 訂閱與帳號服務總覽 或 Gemini Google AI Ultra 5x/20x 充值指南 選 Gemini Google AI Ultra 5x 人工 iOS。全站以商品頁實時標價為準,標價不含稅,開具國內增值稅發票另付 6% 稅費;單獨申請自定義明細電子收據免費。本站明示質保訂閱、不質保封號,請遵守服務商條款合規使用。

相關教學

參考資料

Nathaniel 的更多內容

  1. 01

    Antigravity Python SDK 接入 Local Models 本地模型實戰

    實戰配置 google-antigravity SDK 通過 LiteRTAgentConfig 端側運行 Gemma 4 26B A4B,或通過 LocalOpenAIAgentConfig 對接 Ollama、LM Studio 與 vLLM 實現離線工具調用。

    Gemini其他 AI 工具0
  2. 02

    Python 環境接入 google-antigravity:環境部署與密鑰鑑權入門

    演示 pip 安裝包含內置運行時二進制的 google-antigravity SDK、GEMINI_API_KEY 與 Vertex AI 企業雙路鑑權配置,以及異步流式 Agent 快速啟動代碼。

    Gemini其他 AI 工具0
  3. 03

    多 IDE 切換使用 Antigravity:全局快捷鍵與插件衝突排查

    彙總 VS Code、JetBrains(2026.2.1+)、Zed、Xcode 與 Android Studio 中 Antigravity 擴展的版本與鑑權差異,以及 Tab、Alt+Enter、Ctrl+L 與 Copilot 快捷鍵衝突解法。

    Gemini其他 AI 工具0
  4. 04

    google-antigravity SDK 自定義 Tools 註冊與 Skills 注入

    講解 google-antigravity SDK 類型安全 Python 工具函數註冊、BuiltinTools 五大權限分組、ASK_QUESTION 交互啟用及 skills_paths 動態掛載 SKILL.md 實踐。

    Gemini其他 AI 工具0
  5. 05

    Antigravity Python SDK 集成 MCP Server 與資源權限綁定

    詳解如何在 google-antigravity SDK 中通過 McpStdioServer 與 McpStreamableHttpServer 接入外部 MCP 服務,並結合 disabledTools 與 policies 收窄工具權限邊界。

    Gemini其他 AI 工具0
  6. 06

    Antigravity SDK Policies 安全策略:命令執行與路徑審批邊界

    剖析 Antigravity Python SDK 的聲明式 Policies 引擎,演示如何通過 allow、deny、ask_user 與 safe_defaults 劃定只讀目錄、攔截危險命令及接入人工審批迴調。

    Gemini其他 AI 工具0

同模型

  1. 01

    Antigravity Supercomplete 多行上下文預測補全調優指南

    對比 Antigravity Supercomplete 與普通 Autocomplete 的全文件增刪改能力,解析標籤頁、終端輸出上下文采納權重,以及 Tab Speed 與按詞采納調優策略。

    Gemini其他 AI 工具0
  2. 02

    Antigravity Tab to Import 自動導入依賴與路徑別名前綴識別

    說明 Antigravity Tab-to-Import 在文件頂部自動補全缺失 import 的觸發條件,以及 TypeScript tsconfig.json 與 Python pyproject.toml 路徑別名前綴識別配置。

    Gemini其他 AI 工具0
  3. 03

    Antigravity Tab to Jump 跨區域游標預測跳轉效率設定

    解析 Antigravity IDE 中 Tab-to-Jump 跨區域游標預測跳轉觸發邏輯,對比狀態欄 Tab Speed(Fast 與 Slow)差異,並給出連續重構場景設定與衝突排查要點。

    Gemini其他 AI 工具0
  4. 04

    Antigravity SDK Structured Output 強類型結構化輸出指南

    結合 Pydantic BaseModel 與 response_schema 約束 Antigravity Agent 的最終 JSON 輸出格式,涵蓋多模態附件聯合解析、類型校驗及 Decisions API 選型對比。

    Gemini其他 AI 工具0
  5. 05

    Antigravity SDK Subagents 多智能體拆分與異步編排模式

    解析 Antigravity SDK 動態自克隆與靜態 SubagentConfig 兩種多智能體模式,詳解獨立上下文隔離、專屬工具作用域及 SubagentSkillsConfig 技能裁剪策略。

    Gemini其他 AI 工具0
  6. 06

    Antigravity SDK Lifecycle & Hooks 生命週期鉤子與審計日誌

    全面梳理 google.antigravity.hooks 十大生命週期裝飾器,實戰演示如何用 pre_tool_call_decide、post_tool_call 與 usage_metadata 實現脫敏攔截與企業級審計上報。

    Gemini其他 AI 工具0

同產品的其他教學

  1. 01

    Review Changes in Editor 差異審閱面板逐行驗收與回滾技巧

    掌握 Antigravity IDE 內聯 Diff 單塊 Hunk 快捷鍵(Alt+Enter / Alt+Shift+Enter)、Cmd+Z 撤回審閱決定、並排對比切換及 Ctrl+Alt+M 行內批註排隊返工流程。

    Gemini其他 AI 工具0
  2. 02

    Browser Allowlist 與 Denylist 配置:限制 Agent 訪問域名邊界

    詳解 Antigravity Browser Actuation Rules 的黑白名單匹配規則:子域繼承、Deny 優先、localhost 按端口隔離、Google 敏感子域獨立授權與組織只讀白名單。

    Gemini其他 AI 工具0
  3. 03

    Antigravity Separate Chrome Profile 獨立配置與登入態隔離

    解析 Antigravity App(v2.30.0+)內置瀏覽器按帳號自動隔離與 IDE/CLI/企業端直連 Chrome 的區別,提供獨立目錄啟動參數、擴展衝突屏蔽及 Cookie 清理步驟。

    Gemini其他 AI 工具0
  4. 04

    Antigravity SDK 流式監聽 response.thoughts 推理軌跡解析

    演示如何在 Antigravity Python SDK 的異步對話循環中分離消費 response.thoughts 與正文 token,構建可區分思考過程與正式答覆的實時推理終端。

    Gemini其他 AI 工具0
  5. 05

    Antigravity SDK 流式監控 tool_calls 調用狀態與耗時統計

    結合 response.tool_calls 流式事件與 pre_tool_call_decide、post_tool_call、on_tool_error 鉤子,統計工具起止耗時、入參體積與失敗次數,精準定位性能瓶頸。

    Gemini其他 AI 工具0
  6. 06

    基於 google-antigravity SDK 構建並發自動化測試流水線

    詳解如何結合 asyncio.gather、信號量並發控制與 Pydantic 結構化輸出,用 google-antigravity SDK 搭建並行代碼審查與單測生成 CI 流水線。

    Gemini其他 AI 工具0

0 條評論

登入 後參與評論

還沒有評論,來搶沙發~