AI代理智能记忆管理

mcp-memory是一种为AI代理设计的智能记忆管理系统,通过自动分类、语义去重和记忆衰减机制解决记忆过时和重复问题,适用于需要长期记忆管理的AI应用场景。

  • by ShipItAndPray
  • JavaScript
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 ShipItAndPray/mcp-memory

使用说明

mcp存储器

AI代理的智能内存。记忆衰退,话题是频率加权的,一次性问题不会变成痴迷。

解决 Karpathy问题“两个月前的一个问题一直引起人们的极大兴趣,并被永久性地不当提及。”

v0.2.0的新增功能

  • 自动分类 --无需指定类别,从内容推断
  • 语义消隐 --二元组相似性可防止重复记忆
  • 优先权取代 --“更喜欢暗模式”然后“更喜欢亮模式”更新,而不是重复
  • 召回汽车加强 --搜索一个主题算作一次提及
  • 召回汽车修剪 --每次阅读都会清除死去的记忆
  • 系统提示注入 --通过MCP提示功能提供的活动存储器
  • 模糊遗忘 --“VS Code”匹配“用户更喜欢VS Code进行所有编辑”
  • 7工具→ 4 tools -更简单的API,更高的采用率(向后兼容)

行动中

Day 1: User asks 5 questions (Rust, dark mode, Python, job title, Haskell)

  #1 [ACTIVE] rel=1.000 cat=preference "User prefers dark mode in all editors"
  #2 [ACTIVE] rel=0.900 cat=fact       "User works as a senior software engineer"
  #3 [FADING] rel=0.500 cat=question   "User is building a Python web scraper"
  #4 [FADING] rel=0.300 cat=one-time   "User asked about Rust programming"
  #5 [FADING] rel=0.300 cat=one-time   "User asked what Haskell monads are"

Day 2-5: User mentions Python 4 more times → auto-upgraded to "interest"

  #1 [ACTIVE] rel=2.658 mentions=5 cat=interest    "Python web scraper"
  #2 [ACTIVE] rel=1.000 mentions=1 cat=preference  "dark mode"
  #3 [ACTIVE] rel=0.900 mentions=1 cat=fact         "senior software engineer"
  #4 [FADING] rel=0.300 mentions=1 cat=one-time     "Rust" ← FADING, won't obsess
  #5 [FADING] rel=0.300 mentions=1 cat=one-time     "Haskell" ← FADING, won't obsess

After 60 days:
  Rust:   0.3 × 0.5^(60/7) = 0.0008 → DEAD (gone, as it should be)
  Python: 0.8 × 0.5^(60/60) × 3.32 = 1.329 → STILL ACTIVE (real interest)

它是如何解决这个问题的

当前LLM内存 mcp内存
询问Rust一次→ 永远被提及 问一次→ 7天后消退
所有记忆权重相等 类别:一次性(7d)、问题(14d)、兴趣(60d)、偏好(180d)
无衰减 指数衰减——旧记忆自然会褪色
无频率跟踪 提到5+次→ 从“问题”到“兴趣”的自动升级
关键词匹配 Bigram相似度+相关性评分
代理必须决定记住 根据内容模式自动分类
矛盾的偏好共存 新偏好取代旧偏好
需要手动清理 自动删除召回时的死记忆

安装

"mcpServers": {
  "memory": {
    "command": "npx",
    "args": ["-y", "mcp-memory"]
  }
}

工具

工具 它做什么
remember 储存记忆。根据内容自动分类。通过二元组相似性自动消除重复。取代相互冲突的偏好。
recall 检索按相关性排序的记忆。自动加强了顶级比赛。汽车修剪死去的记忆。
forget 通过ID或模糊内容匹配删除内存。
inspect 调试视图:所有具有衰变状态、相关性得分、类别细分、健康状况的记忆。

自动分类

无需指定类别——它是从内容推断出来的:

内容模式 自动分类 衰减
“更喜欢X”、“喜欢X”和“总是使用X” preference 180天
“像X一样工作”,“是X”,“生活在X中” fact 365天
“实际上是X”、“意思是X”和“错了” correction 365天
“正在构建”、“正在工作” context 30天
“什么是X”,“如何X” one-time 7天
还有别的吗 question 14天

您仍然可以覆盖: remember(content: "...", category: "preference")

例子

自动分类首选项:

remember(content: "User prefers TypeScript over JavaScript")
→ Auto-detected as "preference". Persists 180 days.

语义消除:

remember(content: "Works as data scientist at Google")
remember(content: "Works as senior data scientist at Google")
→ Second call reinforces first (80% similar). Keeps longer version.

优先权取代:

remember(content: "User prefers dark mode")
remember(content: "User prefers light mode")
→ Superseded: "dark mode" → "light mode". One memory, not two.

召回汽车强化:

recall(query: "MCP servers")
→ Returns matching memories AND counts this as a mention.
  mention_count goes from 1 → 2 automatically.

模糊遗忘:

forget(content: "VS Code")
→ Matches and removes "User prefers VS Code for all editing"

数学

relevance = base_weight × decay × frequency_boost

where:
  base_weight  = category-specific (0.3 for one-time, 1.0 for preference)
  decay        = 0.5 ^ (age_days / halflife_days)
  freq_boost   = 1 + log2(mention_count)

2个月前的一次性问题: 0.3 × 0.5^(60/7) × 1.0 = 0.0003 → 实际上为零。不会浮出水面。

上周,一个偏好被提及了8次: 1.0 × 0.5^(7/180) × 4.0 = 3.89 → 每次召回的顶部。

向后兼容

v0.2.0仍然接受旧的v0.1.0工具名称(reinforce, prune, stats).它们在内部映射到新工具。没有突破性的变化。

许可证

麻省理工学院