跳至內容
遠端控制
工具與技能 - Antigravity SDKsdkAntigravity SDKAntigravity SDK工具與技能 - Antigravity SDK Antigravity SDK Antigravity SDKAntigravity SDK

自訂工具與代理技能

「自訂工具與代理技能」章節

SDK 讓您能使用…擴展代理的能力 自訂 Python 函式,內建網頁工具、 內建系統工具與代理技能。

關於模型內容協定(MCP)伺服器設定,請參閱 MCP 文件.

SDK 透過…提供內建系統工具的識別碼 BuiltinTools enum (google.antigravity.types.BuiltinTools).

識別碼列舉常數描述
list_directoryBuiltinTools.LIST_DIR列出目錄內容。
search_directoryBuiltinTools.SEARCH_DIR在檔案內搜尋。
find_fileBuiltinTools.FIND_FILE依模式尋找檔案。
view_fileBuiltinTools.VIEW_FILE讀取檔案內容。
create_fileBuiltinTools.CREATE_FILE建立新檔案。
edit_fileBuiltinTools.EDIT_FILE編輯現有檔案。
run_commandBuiltinTools.RUN_COMMAND執行殼層指令。
ask_questionBuiltinTools.ASK_QUESTION提示使用者輸入。
start_subagentBuiltinTools.START_SUBAGENT呼叫子子代理。
generate_imageBuiltinTools.GENERATE_IMAGE產生或編輯圖片。
search_webBuiltinTools.SEARCH_WEB執行 Google 搜尋。
read_url_contentBuiltinTools.READ_URL_CONTENT擷取 URL 內容。
finishBuiltinTools.FINISH傳回最終輸出。

工具群組輔助程式與篩選

「工具群組協助程式與篩選」章節

某些情況下,您可能想限制代理可存取的工具。您可以在控制代理的作用中工具 CapabilitiesConfig 與 enabled_tools 或 disabled_tools.

例如,你可以設定代理使其僅能存取 read_only 內建工具:

from google.antigravity import LocalAgentConfig, CapabilitiesConfig
from google.antigravity.types import BuiltinTools

config = LocalAgentConfig(
    capabilities=CapabilitiesConfig(
        enabled_tools=BuiltinTools.read_only()
    )
)

某些情況下,您可能想建立代理可運用的自訂 Python 函式。您可以在註冊自訂 Python 函式 LocalAgentConfig 作為您代理的工具。

例如,你可以設定代理以利用自訂 get_weather 函式:

from google.antigravity import Agent, LocalAgentConfig

def get_weather(city: str) -> str:
    """Returns the current weather for a city."""
    return f"It's sunny in {city}."

config = LocalAgentConfig(tools=[get_weather])

async with Agent(config) as agent:
    response = await agent.chat("What's the weather in Tokyo?")
    print(await response.text())

網頁搜尋(SEARCH_WEB)與 URL 擷取(READ_URL_CONTENT)工具預設啟用。

例如,你可以要求代理執行 Google 搜尋或閱讀網頁:

from google.antigravity import Agent, LocalAgentConfig

config = LocalAgentConfig()

async with Agent(config) as agent:
    response = await agent.chat("Search for latest updates on Gemini.")
    print(await response.text())

於 LocalAgentConfig, skills_paths 接受指向個別技能目錄的路徑,該目錄包含 SKILL.md 檔案,以及包含多個技能子目錄的 父目錄。

例如,你可以設定代理以利用自訂 code-review 技能:

from google.antigravity import Agent, LocalAgentConfig

config = LocalAgentConfig(
    skills_paths=["/path/to/skills/code-review"],
)

async with Agent(config) as agent:
    response = await agent.chat("Run a code quality audit.")
    print(await response.text())

關於完整的可運作程式碼範例,請查看 GitHub 儲存庫: