agent-memory
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAgent Memory
Agent Memory
Give agents the ability to remember and learn across conversations.
为Agent赋予跨对话的记忆与学习能力。
When to Use This Skill
何时使用该技能
Invoke this skill when:
- Adding conversation history
- Implementing long-term memory
- Building personalized agents
- Managing context windows
在以下场景中调用该技能:
- 添加对话历史记录
- 实现长期记忆
- 构建个性化Agent
- 管理上下文窗口
Parameter Schema
参数 Schema
| Parameter | Type | Required | Description | Default |
|---|---|---|---|---|
| string | Yes | Memory goal | - |
| enum | No | | |
| enum | No | | |
| 参数 | 类型 | 是否必填 | 描述 | 默认值 |
|---|---|---|---|---|
| string | 是 | 记忆目标 | - |
| 枚举 | 否 | | |
| 枚举 | 否 | | |
Quick Start
快速开始
python
from langchain.memory import ConversationBufferWindowMemorypython
from langchain.memory import ConversationBufferWindowMemorySimple buffer (last k messages)
Simple buffer (last k messages)
memory = ConversationBufferWindowMemory(k=10)
memory = ConversationBufferWindowMemory(k=10)
With summarization
With summarization
from langchain.memory import ConversationSummaryBufferMemory
memory = ConversationSummaryBufferMemory(llm=llm, max_token_limit=2000)
from langchain.memory import ConversationSummaryBufferMemory
memory = ConversationSummaryBufferMemory(llm=llm, max_token_limit=2000)
Vector store memory
Vector store memory
from langchain.memory import VectorStoreRetrieverMemory
memory = VectorStoreRetrieverMemory(retriever=vectorstore.as_retriever())
undefinedfrom langchain.memory import VectorStoreRetrieverMemory
memory = VectorStoreRetrieverMemory(retriever=vectorstore.as_retriever())
undefinedMemory Types
记忆类型
| Type | Use Case | Pros | Cons |
|---|---|---|---|
| Buffer | Short chats | Simple | No compression |
| Summary | Long chats | Compact | Loses detail |
| Vector | Semantic recall | Relevant | Slower |
| Hybrid | Production | Best of all | Complex |
| 类型 | 使用场景 | 优势 | 劣势 |
|---|---|---|---|
| Buffer | 短对话 | 简单易用 | 无压缩功能 |
| Summary | 长对话 | 占用空间小 | 会丢失细节 |
| Vector | 语义召回 | 相关性强 | 速度较慢 |
| Hybrid | 生产环境 | 兼顾所有优势 | 实现复杂 |
Multi-Layer Architecture
多层架构
python
class ProductionMemory:
def __init__(self):
self.short_term = BufferMemory(k=10) # Recent
self.summary = SummaryMemory() # Compressed
self.long_term = VectorMemory() # Semanticpython
class ProductionMemory:
def __init__(self):
self.short_term = BufferMemory(k=10) # Recent
self.summary = SummaryMemory() # Compressed
self.long_term = VectorMemory() # SemanticTroubleshooting
故障排除
| Issue | Solution |
|---|---|
| Context overflow | Add summarization |
| Slow retrieval | Cache, reduce k |
| Irrelevant recall | Improve embeddings |
| Memory not persisting | Check storage backend |
| 问题 | 解决方案 |
|---|---|
| 上下文溢出 | 添加摘要功能 |
| 检索速度慢 | 启用缓存,减小k值 |
| 召回结果不相关 | 优化嵌入模型 |
| 记忆无法持久化 | 检查存储后端 |
Best Practices
最佳实践
- Use multi-layer memory for production
- Set token limits to prevent overflow
- Add metadata (timestamps, importance)
- Implement TTL for old memories
- 在生产环境中使用多层记忆架构
- 设置令牌限制以防止溢出
- 添加元数据(时间戳、重要性)
- 为旧记忆实现TTL机制
Related Skills
相关技能
- - Vector retrieval
rag-systems - - Context management
llm-integration - - Agent architecture
ai-agent-basics
- - 向量检索
rag-systems - - 上下文管理
llm-integration - - Agent架构
ai-agent-basics