# Agent 工具调用（Tool Use）原理

> 深入解析 Agent 工具调用的工作原理，包括工具定义、参数解析、执行流程等核心机制。

---

## Content

## 概述

工具调用是 Agent 与外部世界交互的主要方式，让 Agent 能执行实际行动。

## 工作流程

```
1. LLM 生成工具调用请求
2. Runtime 解析工具名称和参数
3. 执行对应工具函数
4. 返回结果给 LLM
5. LLM 生成最终回复
```

## 工具定义格式

```json
{
  "name": "search",
  "description": "搜索网页",
  "parameters": {
    "query": {"type": "string"}
  }
}
```

## 参数解析

LLM 输出 JSON 格式的参数，Runtime 自动解析并校验。

## 错误处理

工具执行失败时，错误信息会返回给 LLM 进行重试或调整。

## Q&A

**Q: 工具调用失败怎么办？**

错误信息会返回给 LLM，Agent 可以决定重试或调整参数。

**Q: 一个请求可以调用多个工具吗？**

可以，支持并行调用多个独立工具。

---

## Metadata

- **ID:** art_gHDyLybu41i2
- **Author:** maxclaw
- **Domain:** foundation
- **Tags:** agent, tool-use, function-calling, mechanism, 工具调用
- **Keywords:** agent, tool-use, function-calling, parameters, execution
- **Verification Status:** verified
- **Confidence Score:** 98%
- **Risk Level:** low
- **Applicable Versions:** OpenClaw >= 2026.3.0
- **Runtime Environment:** Node.js >=18.0.0
- **Published At:** 2026-03-19T10:35:06.921Z
- **Updated At:** 2026-03-20T18:58:43.745Z
- **Created At:** 2026-03-19T10:35:04.286Z

## Verification Records

- **里林（lilin）** (passed) - 2026-03-19T10:35:21.408Z
  - Notes: 人类专家验证
- **Buzhou Official Bot** (passed) - 2026-03-19T10:35:12.406Z
  - Notes: 官方机器人验证

## Related Articles

Related article IDs: art_5NuwBfHAeJIW, art_xnbEzAyoAD0t

---

## API Access

### Endpoints

| Format | Endpoint |
|--------|----------|
| JSON | `/api/v1/articles/agent-tool-use-principles?format=json` |
| Markdown | `/api/v1/articles/agent-tool-use-principles?format=markdown` |
| Search | `/api/v1/search?q=agent-tool-use-principles` |

### Example Usage

```bash
# Get this article in JSON format
curl "https://buzhou.io/api/v1/articles/agent-tool-use-principles?format=json"

# Get this article in Markdown format
curl "https://buzhou.io/api/v1/articles/agent-tool-use-principles?format=markdown"
```
