该 SDK 支持您使用 自定义 Python 函数、内置 Web 工具、内置系统工具和 Agent 技能来扩展 Agent 的功能。
对于 Model Context Protocol (MCP) 服务器配置,请查看 MCP 文档。
内置工具参考
SDK通过BuiltinTools 枚举(google.antigravity.types.BuiltinTools)为内置系统工具提供标识符。
| 标识符 | 枚举常量 | 描述 |
|---|---|---|
list_directory | BuiltinTools.LIST_DIR | 列出目录内容。 |
search_ | BuiltinTools.SEARCH_DIR | 在文件内搜索。 |
find_file | BuiltinTools.FIND_FILE | 按模式查找文件。 |
view_file | BuiltinTools.VIEW_FILE | 读取文件内容。 |
create_file | BuiltinTools.CREATE_FILE | 创建一个新文件。 |
edit_file | BuiltinTools.EDIT_FILE | 编辑现有文件。 |
run_command | BuiltinTools.RUN_COMMAND | 执行 Shell 命令。 |
ask_question | BuiltinTools.ASK_QUESTION | 提示用户输入。 |
start_subagent | BuiltinTools.START_SUBAGENT | 调用子 Agent。 |
generate_image | BuiltinTools.GENERATE_IMAGE | 生成或编辑图像。 |
search_web | BuiltinTools.SEARCH_WEB | 执行 Google 搜索。 |
read_ | BuiltinTools.READ_URL_CONTENT | 获取 URL 内容。 |
finish | BuiltinTools.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 存储库: