61 lines
1.5 KiB
Markdown
Raw Permalink 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.

# LangGraph 学习教程
## 课程大纲
| 步骤 | 内容 | 文件 | 状态 |
|------|------|------|------|
| 第 1 步 | 核心理念 | - | ✅ |
| 第 2 步 | Hello World | `hello.py` | ✅ |
| 第 3 步 | 条件边 | `conditional.py` | ✅ |
| 第 4 步 | 循环 + 智能体 | `loop.py`, `agent.py` | ✅ |
| 第 5 步 | ReAct 智能体 | `react_agent.py` | ✅ |
## 核心概念
```
LangGraph 图 = State(状态) + Node(节点) + Edge(边)
State: TypedDict节点间传递的数据包
Node: 函数,接收状态并返回更新
Edge: 连接节点,定义流程走向
- 固定边: add_edge()
- 条件边: add_conditional_edges()
```
## 运行示例
```powershell
# 设置编码
$env:PYTHONIOENCODING="utf-8"
# 运行各个示例
python hello.py # Hello World
python conditional.py # 条件边
python loop.py # 循环
python agent.py # AI 智能体 (模拟模式)
```
## ReAct 智能体配置
编辑 `config.py`
```python
API_KEY = "sk-..." # 你的 API Key
BASE_URL = "https://api.openai.com/v1" # API 地址
MODEL = "gpt-4o-mini" # 模型名称
MAX_ITERATIONS = 4 # 最大迭代次数
TEMPERATURE = 0.3 # 温度参数
```
运行:
```powershell
python react_agent.py # 内置测试
python react_agent.py "你的问题" # 自定义问题
```
## 下一步学习
- [ ] 检查点机制(暂停/恢复)
- [ ] 子图(嵌套图)
- [ ] 并行执行
- [ ] 流式输出