Layer 1: Working Memory
Working memory is the context window itself. It provides immediate access to information currently being processed but has limited capacity and vanishes when sessions end.
Working memory usage patterns include scratchpad calculations where agents track intermediate results, conversation history that preserves dialogue for current task, current task state that tracks progress on active objectives, and active retrieved documents that hold information currently being used.
Optimize working memory by keeping only active information, summarizing completed work before it falls out of attention, and using attention-favored positions for critical information.
Layer 2: Short-Term Memory
Short-term memory persists across the current session but not across sessions. It provides search and retrieval capabilities without the latency of permanent storage.
Common implementations include session-scoped databases that persist until session end, file-system storage in designated session directories, and in-memory caches keyed by session ID.
Short-term memory use cases include tracking conversation state across turns without stuffing context, storing intermediate results from tool calls that may be needed later, maintaining task checklists and progress tracking, and caching retrieved information within sessions.
Layer 3: Long-Term Memory
Long-term memory persists across sessions indefinitely. It enables agents to learn from past interactions and build knowledge over time.
Long-term memory implementations range from simple key-value stores to sophisticated graph databases. The choice depends on complexity of relationships to model, query patterns required, and acceptable infrastructure complexity.
Long-term memory use cases include learning user preferences across sessions, building domain knowledge bases that grow over time, maintaining entity registries with relationship history, and storing successful patterns that can be reused.
Layer 4: Entity Memory
Entity memory specifically tracks information about entities (people, places, concepts, objects) to maintain consistency. This creates a rudimentary knowledge graph where entities are recognized across multiple interactions.
Entity memory maintains entity identity by tracking that "John Doe" mentioned in one conversation is the same person in another. It maintains entity properties by storing facts discovered about entities over time. It maintains entity relationships by tracking relationships between entities as they are discovered.
Layer 5: Temporal Knowledge Graphs
Temporal knowledge graphs extend entity memory with explicit validity periods. Facts are not just true or false but true during specific time ranges.
This enables queries like "What was the user's address on Date X?" by retrieving facts valid during that date range. It prevents context clash when outdated information contradicts new data. It enables temporal reasoning about how entities changed over time.
第一层:工作内存
工作内存就是上下文窗口本身。它提供对当前处理信息的即时访问,但容量有限,会话结束后会消失。
工作内存的使用场景包括:Agent跟踪中间结果的草稿计算、保留当前任务对话历史、跟踪活跃目标的当前任务状态,以及存储当前正在使用的已检索文档。
优化工作内存的方法包括:仅保留活跃信息、在已完成工作超出注意力范围前进行摘要、将关键信息放在注意力优先的位置。
第二层:短期内存
短期内存可在当前会话中持久化,但不会跨会话留存。它提供搜索和检索功能,且没有永久存储的延迟。
常见实现包括:会话范围的数据库(会话结束后持久化)、指定会话目录中的文件系统存储、按会话ID键控的内存缓存。
短期内存的使用场景包括:跨轮次跟踪对话状态而不填充上下文、存储后续可能需要的工具调用中间结果、维护任务清单和进度跟踪、在会话内缓存检索到的信息。
第三层:长期内存
长期内存可无限期跨会话持久化。它使Agent能够从过往交互中学习,并随时间积累知识。
长期内存的实现从简单的键值存储到复杂的图数据库不等。选择取决于要建模的关系复杂度、所需的查询模式以及可接受的基础设施复杂度。
长期内存的使用场景包括:跨会话学习用户偏好、构建随时间扩展的领域知识库、维护带有关系历史的实体注册表、存储可复用的成功模式。
第四层:实体内存
实体内存专门跟踪有关实体(人物、地点、概念、对象)的信息,以保持一致性。这会创建一个基础的知识图谱,其中实体可在多次交互中被识别。
实体内存通过跟踪一次对话中提到的「John Doe」与另一次对话中的是同一人来维护实体标识;通过存储随时间发现的实体事实来维护实体属性;通过跟踪发现的实体之间的关系来维护实体关系。
第五层:时序知识图谱
时序知识图谱通过显式有效期扩展了实体内存。事实并非单纯的真或假,而是在特定时间范围内为真。
这使得可以进行诸如「用户在日期X的地址是什么?」的查询,通过检索该日期范围内有效的事实来实现。它可以防止过时信息与新数据冲突导致的上下文矛盾,还能实现关于实体随时间如何变化的时序推理。