> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zerone.run/llms.txt
> Use this file to discover all available pages before exploring further.

# Tools

> 使用内建 Tool 并通过 Zod 定义自定义能力。

# 为 Agent 提供 Tool

Tool 是模型可以调用的函数。SDK 附带 20 余个内建 Tool，覆盖文件 I/O、搜索、命令执行、Web 访问、任务管理与 MCP 集成；自定义 Tool 可使用 `tool()` 的 Zod schema 或底层 `defineTool()`。

## 内建 Tool

| Tool                       | 说明                  |
| -------------------------- | ------------------- |
| **Bash**                   | 执行 shell 命令         |
| **Read**                   | 读取文件并带行号（文本、图片、PDF） |
| **Write**                  | 创建/覆盖文件             |
| **Edit**                   | 在文件中精确替换字符串         |
| **Glob**                   | 按模式查找文件             |
| **Grep**                   | 用正则搜索文件内容           |
| **WebFetch**               | 抓取并解析网页内容           |
| **WebSearch**              | 搜索网页                |
| **Task**                   | 派生 subagent 处理委派工作  |
| **MultiTask**              | 并行派发多个 subagent     |
| **Skill**                  | 调用已注册的 Skill        |
| **AskUserQuestion**        | 向用户请求输入             |
| **FindTool**               | 发现惰性加载的 Tool        |
| **CronCreate/Delete/List** | 定时任务管理              |
| **Config**                 | 动态配置                |
| **TodoWrite**              | 会话待办列表              |

## PDF 支持

Read Tool 支持提取 PDF 文件的文本内容：

```typescript theme={null}
const agent = createAgent({
  agent: {
    description: 'PDF reader',
    prompt: 'You are a helpful assistant.',
    allowedTools: ['Read'],
  },
})
const result = await agent.prompt('Read /path/to/document.pdf and summarize it')
console.log(result.text)
```

**依赖**：PDF 支持使用 `pdfjs-dist`，已作为 SDK 依赖附带——无需单独安装。

**能力**：

* 逐页提取文本并附带页码标记
* 提取 AcroForm 表单字段值
* 与文本文件一样支持 `offset` 和 `limit` 参数

## 自定义 Tool

```typescript theme={null}
import { z } from "zod";
import { createSdkMcpServer, query, tool } from "@zerone-agent/agent-sdk";

const weather = tool(
  "get_weather",
  "Get the temperature for a city",
  { city: z.string() },
  async ({ city }) => ({ content: [{ type: "text", text: `${city}: 22°C` }] }),
);

const server = createSdkMcpServer({ name: "weather", tools: [weather] });

for await (const event of query({
  prompt: "查询东京天气",
  options: { mcpServers: { weather: server } },
})) console.log(event.type);
```

Tool schema 应尽量窄，并用权限模式或 `canUseTool` 审批有副作用的调用。Tool 相关选项与函数签名见 [API Reference](/zh/sdk/api-reference)。
