工具与技能

本页目录

该 SDK 支持您使用 自定义 Python 函数、内置 Web 工具、内置系统工具和 Agent 技能来扩展 Agent 的功能。

对于 Model Context Protocol (MCP) 服务器配置,请查看 MCP 文档。

内置工具参考

SDK通过BuiltinTools 枚举(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执行 Shell 命令。
ask_questionBuiltinTools.ASK_QUESTION提示用户输入。
start_subagentBuiltinTools.START_SUBAGENT调用子 Agent。
generate_imageBuiltinTools.GENERATE_IMAGE生成或编辑图像。
search_webBuiltinTools.SEARCH_WEB执行 Google 搜索。
read_url_contentBuiltinTools.READ_URL_CONTENT获取 URL 内容。
finishBuiltinTools.FINISH返回最终输出。

工具组辅助函数与过滤

在某些情况下,您可能希望限制 Agent 可以访问的工具。您可以使用 CapabilitiesConfig 或 enabled_tools 控制 disabled_tools 中 Agent 的活动工具。

例如,您可以将 Agent 配置为只能访问 read_only 内置工具:

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

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

自定义 Python 函数

在某些情况下,您可能希望创建 Agent 可以利用的自定义 Python 函数。您可以在 LocalAgentConfig 中注册自定义 Python 函数作为 Agent 的工具。

例如,您可以将 Agent 配置为利用自定义 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())

内置 Web 工具

默认情况下启用 Web 搜索 (SEARCH_WEB) 和 URL 获取 (READ_URL_CONTENT) 工具。

例如,您可以要求您的 Agent 执行 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())

Agent 技能

在 LocalAgentConfig 中,skills_paths 接受包含 SKILL.md 文件的各个技能目录的路径,以及包含多个技能子目录的父目录。

例如,您可以将 Agent 配置为利用自定义 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 存储库: