集成概述
内存-Agent 工作流
核心集成模式
1. 自动内存管理- Agent 自动存储对话事件
- 上下文检索透明进行
- Token 限制自动管理
- 短期:近期对话上下文
- 长期:持久化用户知识和偏好
- 长对话自动摘要
- Token 感知的上下文裁剪
- 对话分支用于实验
框架集成
配置与最佳实践
内存配置
故障排查
常见集成问题
内存未持久化下一步
短期内存
了解对话上下文管理
长期内存
实现持久化知识存储
会话管理
处理多用户场景
API 参考
完整 API 文档
将 AG-Kit 的内存系统与 AI agents 和框架集成的完整指南
// 生产环境配置
const memory = MySQLMemory.create({
host: process.env.DB_HOST,
database: process.env.DB_NAME,
sessionId: userId,
// 上下文工程
maxTokens: 8000,
enableContextManagement: true
});
const agent = new Agent({
name: 'production-assistant',
model: provider,
memory: memory,
// 内存感知配置
maxContextTokens: 8000,
memoryRetrievalLimit: 10
});
// ❌ 错误:内存实例未共享
const agent1 = new Agent({ memory: new InMemoryMemory() });
const agent2 = new Agent({ memory: new InMemoryMemory() });
// ✅ 正确:共享内存实例
const sharedMemory = new InMemoryMemory();
const agent1 = new Agent({ memory: sharedMemory });
const agent2 = new Agent({ memory: sharedMemory });
// ❌ 错误:不同用户使用相同会话
const agent = new Agent({ memory, sessionId: 'default' });
// ✅ 正确:每个用户使用唯一会话
const agent = new Agent({
memory,
sessionId: `user-${userId}`
});
此页面对您有帮助吗?