-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathai-agent-memory.html
More file actions
498 lines (450 loc) · 21.7 KB
/
ai-agent-memory.html
File metadata and controls
498 lines (450 loc) · 21.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Memory in the Age of AI Agents - Agent</title>
<link rel="stylesheet" href="styles.css">
<style>
.ai-section {
background: white;
border-radius: 8px;
padding: 30px;
margin-bottom: 30px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}
.ai-section h2, .ai-section h3, .ai-section h4 {
color: #1e40af;
margin-top: 25px;
margin-bottom: 15px;
}
.ai-section h2 {
border-bottom: 2px solid #e2e8f0;
padding-bottom: 15px;
margin-top: 0;
}
.highlight-box {
background: linear-gradient(135deg, rgba(30, 64, 175, 0.05), rgba(124, 58, 237, 0.05));
border-left: 4px solid #1e40af;
padding: 15px;
margin: 15px 0;
border-radius: 4px;
}
.code-block {
background: #f1f5f9;
border-left: 4px solid #1e40af;
padding: 15px;
margin: 15px 0;
border-radius: 4px;
overflow-x: auto;
font-size: 0.9rem;
font-family: 'Courier New', monospace;
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
background: white;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
table thead {
background: linear-gradient(135deg, #1e40af, #7c3aed);
color: white;
}
table th, table td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #e2e8f0;
}
table tbody tr:hover {
background-color: rgba(30, 64, 175, 0.05);
}
.back-link {
display: inline-block;
margin-bottom: 20px;
padding: 10px 20px;
background: #1e40af;
color: white;
text-decoration: none;
border-radius: 6px;
transition: all 0.3s ease;
font-weight: 600;
}
.back-link:hover {
background: #0c4a6e;
transform: translateY(-2px);
}
.breadcrumb {
color: #64748b;
font-size: 0.95rem;
margin-bottom: 20px;
}
.breadcrumb a {
color: #1e40af;
text-decoration: none;
}
code {
background: #f1f5f9;
padding: 2px 6px;
border-radius: 3px;
font-family: 'Courier New', monospace;
font-size: 0.9rem;
}
</style>
</head>
<body>
<div class="container">
<div class="sidebar">
<div class="logo">📚 索引</div>
<ul class="toc">
<li><a href="index.html">🏠 首页</a></li>
<li><a href="index.html#ai">🤖 AI</a>
<ul>
<li><a href="ai-model.html">1. Model</a>
<ul>
<li><a href="ai-model-gpt-principles.html">GPT 模型原理</a></li>
<li><a href="ai-model-attention-mechanism.html">注意力机制</a></li>
</ul>
</li>
<li><a href="ai-posttraining.html">Training</a>
<ul>
<li><a href="ai-pretraining.html">Pre-training</a></li>
<li><a href="ai-posttraining-overview.html">Post-training 全景指南</a></li>
<li><a href="ai-posttraining-peft.html">PEFT 详解</a></li>
</ul>
</li>
<li><a href="ai-agent.html">4. Agent</a>
<ul>
<li><a href="ai-agent-llm-survey.html">LLM Agent Survey</a></li>
<li><a href="ai-agent-agentic-reasoning.html">Agentic Reasoning</a></li>
<li><a href="ai-agent-memory.html">Memory</a></li>
<li><a href="ai-agent-self-evolving.html">Self-Evolving</a></li>
<li><a href="ai-agent-multi-agent.html">Multi-Agent Systems</a></li>
<li><a href="ai-agent-agentic-rl.html">Agentic RL</a></li>
<li><a href="ai-agent-knowledge-graph.html">Knowledge Graph</a></li>
<li><a href="ai-agent-rag.html">RAG</a></li>
<li><a href="ai-agent-tree-of-thoughts.html">Tree of Thoughts</a></li>
<li><a href="ai-agent-function-calling.html">Tools</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="decision.html">🔄 端到端</a></li>
<li><a href="models.html">⏱️ 预测</a></li>
</ul>
</div>
<main class="content">
<header class="header">
<h1>Memory in the Age of AI Agents</h1>
<p class="subtitle">AI 智能体时代的记忆机制</p>
</header>
<div class="breadcrumb">
<a href="index.html">首页</a> > <a href="index.html#ai">AI</a> > <a href="ai-agent.html">4. Agent</a> > Memory in AI Agents
</div>
<div class="page-toc">
<h4 style="margin-bottom: 15px; color: #1e40af;">📑 页面目录</h4>
<ul style="list-style: none; padding: 0; margin: 0;">
<li style="margin-bottom: 8px;"><a href="#memory-in-the-age-of-ai-agents" style="color: #1e40af; text-decoration: none; font-weight: 600;">Memory in the Age of AI Agents</a></li>
<li style="margin-left: 20px; margin-bottom: 6px;"><a href="#一记忆的必要性" style="color: #7c3aed; text-decoration: none; font-size: 0.95rem;">一、记忆的必要性</a></li>
<li style="margin-left: 20px; margin-bottom: 6px;"><a href="#二记忆的三维框架3d-framework" style="color: #7c3aed; text-decoration: none; font-size: 0.95rem;">二、记忆的三维框架(3D Framework)</a></li>
<li style="margin-left: 20px; margin-bottom: 6px;"><a href="#三记忆存储机制" style="color: #7c3aed; text-decoration: none; font-size: 0.95rem;">三、记忆存储机制</a></li>
<li style="margin-left: 20px; margin-bottom: 6px;"><a href="#四记忆检索策略" style="color: #7c3aed; text-decoration: none; font-size: 0.95rem;">四、记忆检索策略</a></li>
<li style="margin-left: 20px; margin-bottom: 6px;"><a href="#五记忆更新与遗忘" style="color: #7c3aed; text-decoration: none; font-size: 0.95rem;">五、记忆更新与遗忘</a></li>
<li style="margin-left: 20px; margin-bottom: 6px;"><a href="#六应用案例" style="color: #7c3aed; text-decoration: none; font-size: 0.95rem;">六、应用案例</a></li>
<li style="margin-left: 20px; margin-bottom: 6px;"><a href="#七挑战与未来" style="color: #7c3aed; text-decoration: none; font-size: 0.95rem;">七、挑战与未来</a></li>
</ul>
</div>
<section class="ai-section">
<h2 id="memory-in-the-age-of-ai-agents">Memory in the Age of AI Agents</h2>
<h3 id="一记忆的必要性">一、记忆的必要性</h3>
<p>AI 智能体需要记忆来:</p>
<ul>
<li><strong>保存历史信息</strong>:记录过去的交互和结果</li>
<li><strong>学习和改进</strong>:从过去的经验中学习</li>
<li><strong>上下文维护</strong>:维持对话和任务的连贯性</li>
<li><strong>知识积累</strong>:建立长期知识库</li>
<li><strong>个性化服务</strong>:根据用户历史提供定制化服务</li>
</ul>
<h3 id="二记忆的三维框架3d-framework">二、记忆的三维框架(3D Framework)</h3>
<div class="highlight-box">
<p><strong>记忆由三个维度组成:Functions(功能)、Forms(形式)、Dynamics(动态)</strong></p>
</div>
<h4>2.1 Functions(记忆功能)</h4>
<table>
<thead>
<tr>
<th>功能</th>
<th>说明</th>
<th>示例</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>编码(Encoding)</strong></td>
<td>将信息转化为可存储的形式</td>
<td>将用户输入转化为向量嵌入</td>
</tr>
<tr>
<td><strong>存储(Storage)</strong></td>
<td>保存编码后的信息</td>
<td>在向量数据库中存储</td>
</tr>
<tr>
<td><strong>检索(Retrieval)</strong></td>
<td>从存储中获取相关信息</td>
<td>基于相似度搜索相关记忆</td>
</tr>
<tr>
<td><strong>更新(Update)</strong></td>
<td>修改或补充已存储的信息</td>
<td>合并新信息到现有记忆</td>
</tr>
<tr>
<td><strong>遗忘(Forgetting)</strong></td>
<td>删除过时或不重要的信息</td>
<td>删除过期的用户偏好</td>
</tr>
</tbody>
</table>
<h4>2.2 Forms(记忆形式)</h4>
<h5>短期记忆(Short-term Memory)</h5>
<div class="highlight-box">
<p><strong>特点</strong>:容量小,快速衰减,用于当前对话</p>
<ul>
<li>实现方式:上下文窗口、会话历史</li>
<li>存储时间:分钟到小时级</li>
<li>示例:当前对话的前 N 条消息</li>
</ul>
</div>
<h5>长期记忆(Long-term Memory)</h5>
<div class="highlight-box">
<p><strong>特点</strong>:容量大,持久保存,用于跨会话信息</p>
<ul>
<li>实现方式:数据库、向量存储、知识图谱</li>
<li>存储时间:天到年级</li>
<li>示例:用户偏好、历史交互、学到的知识</li>
</ul>
</div>
<h5>工作记忆(Working Memory)</h5>
<div class="highlight-box">
<p><strong>特点</strong>:中等容量,用于当前任务处理</p>
<ul>
<li>实现方式:临时缓存、任务状态</li>
<li>存储时间:秒到分钟级</li>
<li>示例:当前计算中间结果</li>
</ul>
</div>
<table>
<thead>
<tr>
<th>记忆类型</th>
<th>容量</th>
<th>速度</th>
<th>持久性</th>
<th>应用</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>短期记忆</strong></td>
<td>小</td>
<td>快</td>
<td>低</td>
<td>当前对话</td>
</tr>
<tr>
<td><strong>工作记忆</strong></td>
<td>中</td>
<td>中等</td>
<td>中</td>
<td>任务处理</td>
</tr>
<tr>
<td><strong>长期记忆</strong></td>
<td>大</td>
<td>慢</td>
<td>高</td>
<td>知识积累</td>
</tr>
</tbody>
</table>
<h4>2.3 Dynamics(记忆动态)</h4>
<p>记忆的动态过程包括:</p>
<div class="code-block">
记忆生命周期:<br><br>
1. 获取(Acquisition):新信息进入记忆系统<br>
2. 巩固(Consolidation):信息从短期转为长期<br>
3. 保持(Maintenance):定期访问保持记忆活跃<br>
4. 检索(Retrieval):需要时提取记忆<br>
5. 遗忘(Forgetting):不重要信息逐渐消退<br>
6. 重组(Reorganization):记忆的重新整理和关联
</div>
<h3 id="三记忆存储机制">三、记忆存储机制</h3>
<h4>3.1 存储方式对比</h4>
<table>
<thead>
<tr>
<th>存储方式</th>
<th>特点</th>
<th>优点</th>
<th>缺点</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>向量数据库</strong></td>
<td>基于语义相似度</td>
<td>快速检索、语义理解</td>
<td>信息压缩丢失</td>
</tr>
<tr>
<td><strong>知识图谱</strong></td>
<td>结构化知识表示</td>
<td>逻辑清晰、关系明确</td>
<td>构建复杂、维护困难</td>
</tr>
<tr>
<td><strong>关系数据库</strong></td>
<td>表格式结构化存储</td>
<td>查询灵活、事务支持</td>
<td>语义理解能力弱</td>
</tr>
<tr>
<td><strong>文档存储</strong></td>
<td>灵活的 JSON/文本</td>
<td>易于扩展、适应性强</td>
<td>查询性能可能较差</td>
</tr>
</tbody>
</table>
<h4>3.2 混合存储架构</h4>
<div class="code-block">
推荐的混合架构:<br><br>
短期记忆:内存缓存(Redis)<br>
↓<br>
工作记忆:向量数据库(Pinecone/Weaviate)<br>
↓<br>
长期记忆:多层存储<br>
- 热数据:向量数据库<br>
- 温数据:关系数据库<br>
- 冷数据:对象存储(S3)
</div>
<h3 id="四记忆检索策略">四、记忆检索策略</h3>
<h4>4.1 检索方法</h4>
<ul>
<li><strong>语义检索</strong>:基于语义相似度的向量搜索</li>
<li><strong>关键词检索</strong>:基于关键词匹配</li>
<li><strong>时间检索</strong>:基于时间戳的检索</li>
<li><strong>关系检索</strong>:基于知识图谱的关系遍历</li>
<li><strong>混合检索</strong>:结合多种方法的检索</li>
</ul>
<h4>4.2 检索排序</h4>
<table>
<thead>
<tr>
<th>排序策略</th>
<th>说明</th>
<th>适用场景</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>相关性排序</strong></td>
<td>按语义相似度排序</td>
<td>一般查询</td>
</tr>
<tr>
<td><strong>时间排序</strong></td>
<td>按最近访问时间排序</td>
<td>需要最新信息</td>
</tr>
<tr>
<td><strong>重要性排序</strong></td>
<td>按信息重要度排序</td>
<td>知识库查询</td>
</tr>
<tr>
<td><strong>混合排序</strong></td>
<td>多个因素加权组合</td>
<td>复杂查询</td>
</tr>
</tbody>
</table>
<h3 id="五记忆更新与遗忘">五、记忆更新与遗忘</h3>
<h4>5.1 更新策略</h4>
<div class="highlight-box">
<p><strong>主动更新</strong>:系统主动更新过时信息</p>
<ul>
<li>定期刷新热数据</li>
<li>版本控制和历史追踪</li>
<li>冲突解决机制</li>
</ul>
</div>
<div class="highlight-box">
<p><strong>被动更新</strong>:基于新信息的增量更新</p>
<ul>
<li>增量学习</li>
<li>优先级队列更新</li>
<li>异步更新</li>
</ul>
</div>
<h4>5.2 遗忘机制</h4>
<ul>
<li><strong>时间衰减</strong>:旧信息的权重随时间降低</li>
<li><strong>访问频率</strong>:不常访问的信息优先删除</li>
<li><strong>相关性评分</strong>:低相关性信息优先删除</li>
<li><strong>容量限制</strong>:超过容量时删除最不重要的</li>
</ul>
<h3 id="六应用案例">六、应用案例</h3>
<h4>6.1 个性化推荐</h4>
<div class="code-block">
用户交互历史 → 编码 → 向量数据库<br>
↓<br>
新查询 → 检索相似历史 → 推荐系统<br>
↓<br>
个性化推荐结果
</div>
<h4>6.2 多轮对话</h4>
<ul>
<li>短期记忆:当前对话上下文</li>
<li>长期记忆:用户偏好、背景信息</li>
<li>工作记忆:当前讨论的主题、提到的实体</li>
</ul>
<h4>6.3 持续学习</h4>
<ul>
<li>新知识自动编码和存储</li>
<li>定期检索和巩固重要知识</li>
<li>基于反馈的知识更正</li>
</ul>
<h3 id="七挑战与未来">七、挑战与未来</h3>
<h4>7.1 当前挑战</h4>
<ul>
<li><strong>存储成本</strong>:大规模记忆存储成本高</li>
<li><strong>检索效率</strong>:快速精准检索困难</li>
<li><strong>隐私保护</strong>:敏感信息的安全存储</li>
<li><strong>一致性维护</strong>:分布式记忆的一致性</li>
</ul>
<h4>7.2 未来方向</h4>
<ul>
<li><strong>更高效的存储</strong>:压缩和索引技术</li>
<li><strong>更智能的检索</strong>:多模态检索、跨域检索</li>
<li><strong>更好的遗忘机制</strong>:自适应遗忘策略</li>
<li><strong>更强的隐私保护</strong>:差分隐私、联邦学习</li>
</ul>
<a href="ai-agent.html" class="back-link">← 返回 4. Agent</a>
</section>
<footer class="footer">
<p>更新时间:2026-04-13</p>
<p><a href="index.html">← 返回首页</a></p>
</footer>
</main>
</div>
<!-- 在线编辑器 - Quill.js + GitHub API -->
<link rel="stylesheet" href="https://cdn.quilljs.com/1.3.7/quill.snow.css">
<link rel="stylesheet" href="editor.css">
<script src="https://cdn.quilljs.com/1.3.7/quill.min.js"></script>
<script src="editor.js"></script>
</body>
</html>