agent-handoff-memory
agent-handoff-memory
一个MCP服务器,为多个智能体提供共享的、带版本管理的记忆——以及一个明确的交接包,使得下一个会话从上一次停止的地方继续,而不是重新推导。
智能体在会话边界会丢失上下文。通常的补丁是将对话记录转储到提示中,希望下一次运行能够从中提取出正确的句子。交接包则相反:它是一个短小、结构化的对象,说明了已完成的工作、下一步计划、仍然不明确的地方,以及应该从哪个精确的记录版本开始——接收智能体在同一调用中获取这些版本,并附带关于任何已变更版本的警告。
git clone https://github.com/JusticeUA/agent-handoff-memory.git
cd agent-handoff-memory && npm install
npm run demo这会在两个进程中运行两个智能体,共享一个SQLite文件。无需API密钥,无需服务,无需原生构建步骤——node:sqlite是运行时的一部分。
演示内容
一个侦察智能体爬取(固定)招聘网站,记录发现,修正自己的一个评估,然后交接。一个独立的执行进程随后在不知道任何其他信息的情况下接管工作:
--- 1. pick up whatever is waiting --------------------------------
. packet h_1f4089bf from scout-agent: Two listings worth an application, one source caveat
. next: Draft an application for listing/482 (supplier catalogue scrape, $900)
. next: Draft an application for listing/553 (price monitor, $600)
. open: Is the 60s backoff enough, or does the board keep a longer penalty window?
. 4 pinned record versions arrived with the packet
. stale: listing/553/assessment was pinned at v1, now at v2
--- 3. re-read anything the warning touched -----------------------
. listing/553 v2 now says "maybe" (budget edited down to $400 and 17 more applicants arrived)
. dropping listing/553 - acting on the pinned v1 would be wrong
--- 5. report what actually happened ------------------------------
. success on listing/482/assessment: confidence 80% -> 84%
. failure on source/boards-example/rate-limit: confidence 60% -> 39%侦察智能体在写入交接包之后编辑了listing/553。执行智能体被告知其固定版本已过时,而不是被偷偷地提供新版本,因此它重新读取并丢弃了该条目。然后它报告实际发生的情况,驱动决策的事实的置信度也随之调整。
两个会话的完整输出:docs/demo-transcript.md。
如果想在两个终端中查看,而不是单个脚本:
# terminal 1
MEMORY_DB=shared.db node dist/demo/scout.js
# terminal 2
MEMORY_DB=shared.db node dist/demo/executor.js工具
工具 | 功能 |
| 在 |
| 读取某个键的当前版本,或按范围前缀、标签、自由文本、最低置信度进行搜索。 |
| 某个键的所有版本:值、作者、置信度,以及将各版本链接在一起的哈希链。 |
| 写入一个包:摘要、下一步计划、未解决问题,以及固定的记录版本。如果未提供引用,则会话中涉及的所有内容都会被固定。 |
| 领取该智能体最旧的未处理包,并附带已解析的固定记录返回,同时标记过时的记录。 |
| 报告驱动决策的记录的成功或失败;它们的置信度会移动,并保留前后对比。 |
| 计数、平均置信度、交接状态,以及可选的整个哈希链的完整性检查。 |
从MCP客户端使用
{
"mcpServers": {
"handoff-memory": {
"command": "node",
"args": ["/absolute/path/to/agent-handoff-memory/dist/src/server.js"],
"env": {
"MEMORY_DB": "/absolute/path/to/shared-memory.db",
"AGENT_ID": "researcher"
}
}
}
}将多个客户端指向同一个MEMORY_DB,使用不同的AGENT_ID,它们将共享一个记忆。存储使用WAL模式运行,正是为了支持这一点。
对于Claude Code:
claude mcp add handoff-memory -e MEMORY_DB=$PWD/shared.db -e AGENT_ID=researcher \
-- node $PWD/dist/src/server.js设计决策
值是不可变的,意见则不是。 写入现有的scope+key会追加版本N+1,并将旧版本标记为已替换。置信度和结果计数会在当前版本上移动——它们是对事实的意见,而非事实本身——并且每次移动都会写入outcomes表,包含前后值。因此,history保留的是信念的历史,而非投票变化的日志。
每个版本都经过哈希并链式连接。 每一行包含其内容体的sha256以及前一个版本的哈希。memory_stats { verify: true }会重新计算全部内容;直接在数据库文件中编辑的值将显示为损坏。其中一个测试正是执行了这样的编辑,并断言能够捕获。
过时的引用会被报告,而不会静默替换。 一个包固定了版本。如果基础数据发生了变化,接收智能体会被告知——它可以有意识地重新读取。另一种做法(静默地提供最新版本)会使智能体基于其计划从未构建过的数据采取行动。
置信度跟随结果,并保持在0到1之间。 成功会缩小与1的差距,失败则按比例缩小,因此重复的证据会接近边界,但不会固定在那里。乘数存放在src/models.ts的一个表中。
无网络、无守护进程、无原生模块。 存储使用node:sqlite,传输使用stdio。整个就是一个node进程和一个文件。
SenseLab AMFS
该项目也运行在SenseLab的AMFS TypeScript SDK上。src/amfs/sqlite-adapter.ts在SQLite上实现了SenseLab的AmfsAdapter合同——他们的AgentMemory负责推理,我们负责记忆——而demo/amfs-bridge.ts通过他们的API重新讲述了交接的演练:
npm run demo:amfs该SDK自带一个内存适配器(进程退出时消失)和一个HTTP适配器(需要托管的端点和密钥);本适配器填补了它们之间的空白,并在此过程中填充了contentHash/integrityChain,并回答了commitLog()(内存适配器留空的内容)。一个一致性测试通过两个适配器运行相同的会话,并比较结果。
在构建过程中我测量的内容——包括为什么在0.3.2版本中commitOutcome(SUCCESS)会降低置信度——已记录在docs/senselab-amfs.md中。
测试
npm test29个测试涵盖了存储、交接生命周期、MCP表面(通过内存传输连接的真实客户端和服务器,因此工具模式也得到验证),以及AMFS适配器。当可选的SDK未安装时,AMFS组会跳过自身。
布局
src/models.ts types and the outcome table
src/store.ts versioned SQLite store: memory, handoffs, outcomes
src/server.ts the MCP server and its seven tools
src/amfs/types.ts structural mirror of the AMFS SDK shapes
src/amfs/sqlite-adapter.ts durable adapter for SenseLab's AMFS SDK
demo/scout.ts session 1: crawl, write, correct, hand over
demo/executor.ts session 2: resume, act, report outcomes, hand back
demo/amfs-bridge.ts the same story through @senselab-ai/amfs要求
Node 24或更高版本,其中node:sqlite稳定且无需标志;在25.9版本上开发和测试。在Node 22.5-23.x上,相同的代码使用--experimental-sqlite运行。npm install会构建项目(通过prepare),因此dist/随后即可使用。
可选的@senselab-ai/amfs依赖由SenseLab根据BSL-1.1发布;本仓库的代码采用MIT许可证。
许可证
MIT——参见LICENSE。
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Person-owned, portable AI memory as a remote MCP server, readable and writable by any MCP client.
Cloud-hosted MCP server for durable AI memory
Shared, governed long-term memory for AI agents across tools and sessions via MCP and REST.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/JusticeUA/agent-handoff-memory'
If you have feedback or need assistance with the MCP directory API, please join our Discord server