Files
jaspersoft-agent-learn/step_01_tools/README.md
T

83 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Step 01: 理解 Tool - 工具系统基础
## 🎯 学习目标
- 理解什么是 Tool(工具)
- 理解为什么 Agent 需要 Tool
- 学会设计一个可扩展的工具系统
- 理解 Tool 的核心要素:name、description、execute
---
## 📖 概念讲解
### 什么是 Tool
在 AI Agent 系统中,**Tool(工具)** 是 Agent 与外部世界交互的方式。
```
没有 Tool 的 LLM
┌──────────────┐
│ 用户输入 │
└──────┬───────┘
┌──────────────┐
│ LLM │ ← LLM 只能"想",不能"做"
│ (只能思考) │
└──────┬───────┘
┌──────────────┐
│ 返回答案 │ ← 答案可能不准确,没有执行能力
└──────────────┘
有 Tool 的 Agent
┌──────────────┐
│ 用户输入 │
└──────┬───────┘
┌──────────────┐
│ LLM │
│ (思考 + 决策) │
└──────┬───────┘
┌──────────────┐
│ 需要执行工具? │──── 是 ──▶ 调用 Tool
└──────┬───────┘ │
│ ▼
│ 否 ┌──────────┐
▼ │ 执行 Tool │
┌──────────────┐ │ (访问外部) │
│ 返回答案 │ └─────┬─────┘
└──────────────┘ │
把执行结果反馈给 LLM
```
### 为什么需要 Tool
1. **LLM 不知道最新信息**Tool 可以搜索网页、查数据库
2. **LLM 不能执行操作**Tool 可以写文件、调用 API
3. **LLM 可能有幻觉**Tool 可以验证信息
4. **LLM 需要精确计算**Tool 可以调用计算器
### Tool 的核心要素
每个 Tool 都有三个核心要素:
```python
class Tool:
name: str # 工具名称(LLM 通过名字选择工具)
description: str # 工具描述(LLM 通过描述理解何时使用)
execute: function # 执行函数(实际做事的代码)
```
---
## 💻 代码实现
请打开 `concept.py` 查看详细代码注释。