Files

52 lines
2.1 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.
# Step 04: 添加 Memory - 记忆系统
## 🎯 学习目标
- 理解 Agent 为何需要记忆系统
- 理解多层记忆架构:短期 / 长期 / 工作记忆
- 学会实现上下文窗口管理
- 理解对话压缩技术
---
## 📖 核心概念
### 为什么 Agent 需要 Memory
```
没有 Memory
用户: "我叫张三"
Agent: 好的,张三先生
用户: "我叫啥?"
Agent: ??? 我不记得了
有 Memory
用户: "我叫张三"
Agent: 好的,张三先生
↓ 保存到 Memory
用户: "我叫啥?"
Agent: 你叫张三
↓ 从 Memory 读取
```
### 多层记忆架构
```
┌─────────────────────────────────────────────────────┐
│ Memory System │
├─────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌────────────┐ │
│ │ Working │ │ Short │ │ Long │ │
│ │ Memory │ │ Term │ │ Term │ │
│ ├─────────────┤ ├─────────────┤ ├────────────┤ │
│ │ 当前状态 │ │ 对话历史 │ │ 知识库 │ │
│ │ 正在处理 │ │ 最近几轮 │ │ RAG检索 │ │
│ │ 的任务 │ │ 对话 │ │ 持久记忆 │ │
│ └─────────────┘ └─────────────┘ └────────────┘ │
│ │
└─────────────────────────────────────────────────────┘
```
请打开 `concept.py` 查看实现。