TencentDB-Agent-Memory icon indicating copy to clipboard operation
TencentDB-Agent-Memory copied to clipboard

[Feature] 实现 on_memory_write 钩子,自动同步 Hermes 内置记忆到 TencentDB

Open maxwell-feng opened this issue 6 months ago • 2 comments

当用户通过 Hermes 内置的 memory add 工具写入 MEMORY.md / USER.md 时,内容不会自动同步到 TencentDB。两个记忆存储层各自独立运行,需要手动通过 Gateway /capture API 迁移数据。

缺失的钩子

Hermes 的 MemoryProvider 基类定义了这个可选接口:
https://github.com/nousresearch/hermes-agent/blob/main/agent/memory_provider.py#L29


on_memory_write(action, target, content, metadata=None)
    — mirror built-in memory writes


当前 TencentDB 插件未实现此钩子。

建议实现

在 hermes-plugin/memory/memory_tencentdb/init.py 中添加:

python
def on_memory_write(self, action: str, target: str, content: str, metadata=None):
    同步 Hermes 内置记忆写入到 TencentDB L0
    self._gateway.capture(
        session_key="hermes-builtin-memory-sync",
        user_content=f"[Memory {action}] [{target}] {content}",
        assistant_content=f"已同步: {target} → {action}"
    )


预期效果

- 用户执行 memory add → 同时写入 MEMORY.md 和 TencentDB L0
- 用户执行 memory remove → 对应变更也被捕获
- L1→L2→L3 管线正常处理捕获到的条目

Describe the solution you'd like | 描述你期望的解决方案

在双记忆架构(Hermes 内置文件 + TencentDB)中,用户希望 memory add 写入的规则/偏好能自动进入 TencentDB 的 L0→L3 提炼管道,无需手动执行迁移脚本

Describe alternatives you've considered | 描述你考虑过的其他方案

No response

Additional context | 补充说明

No response

maxwell-feng avatar May 31 '26 22:05 maxwell-feng

感谢您给出的功能建议,我们会内部评估是否以及如何实现,有结果会在此处跟您同步,感谢关注!

Maxwell-Code07 avatar Jun 01 '26 15:06 Maxwell-Code07

感谢反馈,这个需求本身是合理的,我们理解部分场景下用户希望将 Hermes 内置 memory add 写入的内容同步到 TencentDB-Agent-Memory 中,形成统一的长期记忆管线。

不过目前我们暂时不计划默认合入该能力。主要原因是:内置记忆与 TencentDB-Agent-Memory 属于两套不同的记忆入口,部分用户可能只希望相关内容保留在 Hermes 本地记忆中,而不希望被自动同步到外部记忆系统。如果默认实现自动同步,可能会带来用户预期之外的数据合入、重复记忆或隐私边界问题。

对于确实有该诉求的场景,建议由业务侧显式调用 capture 接口接入,将需要同步的内容按需写入 TencentDB-Agent-Memory。这样可以让同步行为保持显式、可控,也便于业务自行处理去重、权限和数据治理等问题。

noFloat avatar Jun 02 '26 02:06 noFloat