Long-term memory for AI agents. Your AI remembers everything — preferences, decisions, context — across sessions, forever.
记忆
Agent Long-Term Memory
试用Three-tier long-term memory for AI agents — short-term + entity + episodic. 三层长期记忆架构:短期记忆 + 实体画像 + 情景记忆。跨项目共享用户画像,让 AI 真正记住你。
它能做什么
Three-tier long-term memory for AI agents — short-term + entity + episodic. 三层长期记忆架构:短期记忆 + 实体画像 + 情景记忆。跨项目共享用户画像,让 AI 真正记住你。
技能文档
Agent Long-Term Memory · AI 智能体长期记忆
Install from GitHub · 从 GitHub 安装
git clone https://github.com/exp007/agent-long-term-memory.git ~/.codex/skills/agent-memory
Three-tier persistent memory shared at ~/.codex/agent_memory/ across all projects.
三层持久记忆,数据存在 ~/.codex/agent_memory/,所有项目共享。
Quick Start · 快速开始
from agent_memory import get_memory
mem = get_memory()
mem.remember("name", "Alice")
mem.recall("name") # -> "Alice"
mem.recall("favorite color") # -> None (not yet stored)
API Reference · API 参考
Tier 2: Entity Memory · 实体记忆(结构化事实,SQLite)
| Method | Signature | Description |
|---|---|---|
remember | (key, value, evidence="", confidence=1.0) | Store a structured fact · 存储结构化事实 |
remember | (content, tags=None, ...) | Store a fact in v1 compat mode |
recall | (key_or_query, limit=10, tags=None) | Lookup by key or search by content · 按 key 精确查或按内容搜 |
recall_card | (key) | Get the full EntityCard · 获取完整卡片 |
get_profile | () | Return all entity cards · 获取全部画像 |
search_entities | (keyword) | Fuzzy search across keys and values · 模糊搜索 |
forget_entity | (key) | Delete an entity card · 删除 |
clean_stale | (threshold=0.3) | Remove low-confidence cards · 清理低置信度 |
entity_count | property | Number of entity cards · 卡片数量 |
Tier 3: Episodic Memory · 情景记忆(对话片段,ChromaDB)
| Method | Signature | Description |
|---|---|---|
archive | (content, summary="") | Store a conversation chunk · 存储对话片段 |
recollect | (query, n_results=5) | Semantic search · 语义检索 |
episodic_count | property | Number of stored episodes · 片段数量 |
Tier 1: Short-Term Memory · 短期记忆(滑动窗口)
| Method | Signature | Description |
|---|---|---|
add_turn | (user_text, assistant_text) | Record a turn · 记录一轮对话 |
get_recent | (n=None) | Get recent messages · 获取最近消息 |
clear_short_term | () | Clear buffer · 清空缓冲区 |
RAG Context Building · RAG 上下文构建
| Method | Signature | Description |
|---|---|---|
build_context | (user_query="", episodic_top_k=3) | Full MemoryContext · 完整上下文 |
build_system_extension | (user_query="", episodic_top_k=3) | Prompt injection string · 系统提示扩展 |
Auto Extraction · 自动抽取
| Method | Signature | Description |
|---|---|---|
auto_remember | (conversation_text) | Extract entities from text · 从对话中抽取实体。有 OpenAI key 用 LLM,无则用正则兜底。 |
v1 Compat API · v1 兼容接口
add_fact, get_fact, get_facts, list_facts, forget, supersede, forget_stale, learn, get_lessons, apply_lesson, track_entity, get_entity, update_entity, list_entities, link_fact_to_entity, stats, export_json, close
Standard Integration Pattern · 标准集成流程
session start: mem = get_memory(); inject mem.get_profile() into system prompt
every user message: mem.add_turn(user_msg, assistant_msg)
significant facts: mem.remember(key, value, evidence)
mem.auto_remember(conversation_text) # auto-extract · 自动抽取
conversation end: mem.archive(full_conversation, summary)
periodic cleanup: mem.clean_stale(0.3); mem.forget_stale(30)
shutdown: mem.close()
Dependencies · 依赖
pip install chromadb>=0.4.0 openai>=1.0.0
OpenAI key is optional — if unset, entity extraction falls back to regex patterns. OpenAI key 可选——不配也能用正则兜底。
相关技能
为 AI agent 建立持久、可检索、可遗忘的六层记忆体系。不是堆更多 context——是把记忆按信息密度分层:L1 对话流、L2 索引(≤200行)、L3 主题文件、L4 技能固化、L5 状态追踪、L6 经验累积。含 REM 做梦(只读扫描发现模式)、SWS 巩固(写入长期记忆)、遗忘脚本(自动清理过期条目...
AI 说"我记得",你敢信吗?测一下就知道。长期记忆评测台 memory-bench——本地一键评测智能体/大模型长期记忆:12 类题型(时序/实体/否定/反事实/跨会话整合),EM/F1 标准评分,零配置开箱即跑;可接真实 LLM 严评(SiliconFlow/DeepSeek),密钥 env 注入不落盘。结果可复现、可对比、可入发布证据。自带安全稳定性 10 维实测全 5.0。适合 Agent 开发者、AI 产品经理、记忆方案选型。"记忆好不好,测了才知道。"
Organize project, agent, or user memory using an A-MEM-style workflow with structured notes, semantic tags, contextual summaries, explicit links, and lightwe...
给 AI agent/bot 做跨会话持久记忆的分层混合方案。当用户要"给 bot 加记忆""让 agent 记住之前的事""跨会话上下文持久化""记忆去重/断链/陈旧检查",或要搭一个有长期记忆的 agent 时使用。方案=markdown 真理源(人可读可手改) + SQLite 派生索引(选择性召回) + 生命周期检查(断链/重复/陈旧),纯标准库零依赖。
Long-term memory for OpenClaw agents — SQLite hybrid recall (FTS5 + keyword + associative expansion + optional LLM embeddings), raw/curated anchors, session...