Hermes 插件接入
duMemory Hermes 插件是一个 Hermes MemoryProvider,用于将 Hermes Agent 的对话写入云端长期记忆,并在后续对话中自动召回相关内容。插件仅支持云端远程模式,记忆写入、召回和反思均通过 duMemory Cloud 完成。
插件提供自动上下文注入能力,也可向 Hermes 暴露记忆工具,使 Agent 能在对话中主动保存、检索或基于长期记忆进行综合回答。
连接信息
| 信息 | 值 |
|---|---|
| API Base URL | https://cloud.memory.bj.baidubce.com/api |
| API Key | 在控制台“API Key”页签中创建,建议通过 DUMEMORY_API_KEY 写入环境配置 |
| Bank ID | 在控制台创建记忆库时设定,默认可使用 hermes,也可指定为已有 Bank ID |
| 插件下载地址 | https://cloud-memory.bj.bcebos.com/baidu-hermes-memory-1.0.0.tar.gz |
API Base URL 已包含
/api,不要再额外拼接。API Key 请勿写入公开仓库、公开文档或截图。
前提条件
- 已安装并可运行 Hermes
- Hermes 可以发现用户插件目录:
$HERMES_HOME/plugins/dumemory - 已创建记忆库,并获取 API Base URL、API Key 和 Bank ID
- 本机可访问 duMemory Cloud API
安装流程
1. 下载并解压插件
1wget -O dumemory-hermes-1.0.0.tar.gz https://cloud-memory.bj.bcebos.com/baidu-hermes-memory-1.0.0.tar.gz
2mkdir -p ~/.hermes/plugins/dumemory
3tar -xzf dumemory-hermes-1.0.0.tar.gz --strip-components=1 -C ~/.hermes/plugins/dumemory
2. 运行 Hermes 配置向导
1hermes memory setup dumemory
该命令会引导 Hermes 识别并启用 duMemory MemoryProvider。
3. 配置 API Key
密钥配置写入:
1~/.hermes/.env
推荐通过环境变量保存 API Key:
1cat >> ~/.hermes/.env <<'EOF'
2DUMEMORY_API_KEY=<your-api-key>
3DUMEMORY_API_URL=https://cloud.memory.bj.baidubce.com/api
4DUMEMORY_BANK_ID=<your-bank-id>
5EOF
控制台创建的 API Key 即插件连接 duMemory Cloud 时使用的鉴权凭证。
4. 配置插件行为
非密钥配置写入:
1~/.hermes/dumemory/config.json
推荐基础配置:
1{
2 "api_url": "https://cloud.memory.bj.baidubce.com/api",
3 "bank_id": "<your-bank-id>",
4 "memory_mode": "hybrid",
5 "recall_prefetch_method": "recall",
6 "recall_budget": "mid",
7 "recall_max_tokens": 4096,
8 "recall_max_input_chars": 800,
9 "recall_types": "observation",
10 "retain_async": true,
11 "retain_every_n_turns": 1,
12 "retain_context": "conversation between Hermes Agent and the User",
13 "auto_recall": true,
14 "auto_retain": true,
15 "timeout": 120
16}
5. 检查安装状态
1hermes memory status
如果状态正常,Hermes 会在对话前自动召回相关记忆,并在对话后将消息写入云端记忆库。
默认工具
插件向 Hermes 提供三个工具:
| Tool | Description |
|---|---|
dumemory_retain |
保存显式给出的记忆,支持可选 context 和 tags |
dumemory_recall |
从长期记忆中搜索相关事实 |
dumemory_reflect |
基于长期记忆综合回答问题 |
在 memory_mode 为 hybrid 或 tools 时,Hermes Agent 可主动调用这些工具。
配置参考
连接配置
| Key | Default | Description |
|---|---|---|
api_url |
https://cloud.memory.bj.baidubce.com/api |
duMemory 云端 API 地址 |
api_key |
— | duMemory API Key,建议通过 DUMEMORY_API_KEY 设置 |
Memory Bank 配置
| Key | Default | Description |
|---|---|---|
bank_id |
hermes |
默认 Memory Bank 名称 |
bank_id_template |
— | 可选动态 Bank 模板,支持 {profile}、{workspace}、{platform}、{user}、{session} |
单用户或固定 Agent 场景,建议直接设置 bank_id。多用户、多 workspace 或多 session 场景,可使用 bank_id_template 动态隔离记忆。
Recall 配置
| Key | Default | Description |
|---|---|---|
recall_budget |
mid |
召回强度:low / mid / high |
recall_prefetch_method |
recall |
自动召回方法:recall 或 reflect |
recall_max_tokens |
4096 |
召回结果最大 token 数 |
recall_max_input_chars |
800 |
自动召回查询最大字符数 |
recall_prompt_preamble |
— | 自动注入上下文的自定义前缀 |
recall_tags |
— | 搜索记忆时使用的标签过滤 |
recall_tags_match |
any |
标签匹配模式:any / all / any_strict / all_strict |
recall_types |
observation |
召回的事实类型,支持逗号分隔字符串或 JSON 数组 |
auto_recall |
true |
每轮对话前自动召回相关记忆 |
recall_types 默认只使用 observation,这样自动注入的上下文更紧凑。如需扩大召回范围,可设置为:
1{
2 "recall_types": "observation,world,experience"
3}
Retain 配置
| Key | Default | Description |
|---|---|---|
auto_retain |
true |
自动保存对话轮次 |
retain_async |
true |
服务端异步处理 retain |
retain_every_n_turns |
1 |
每 N 轮保存一次 |
retain_context |
conversation between Hermes Agent and the User |
保存记忆时的上下文标签 |
retain_tags |
— | 自动保存时附加的默认标签 |
observation_scopes |
— | 观察内容的合并范围,可选 combined、per_tag、all_combinations 或 JSON 标签列表 |
retain_source |
— | 写入 metadata.source 的来源标识 |
retain_user_prefix |
User |
保存用户消息时使用的前缀 |
retain_assistant_prefix |
Assistant |
保存助手消息时使用的前缀 |
Integration 配置
| Key | Default | Description |
|---|---|---|
memory_mode |
hybrid |
记忆接入模式 |
memory_mode 支持:
| 模式 | 说明 | 适合场景 |
|---|---|---|
hybrid |
自动注入上下文,同时向模型暴露工具 | 推荐默认模式,兼顾自动记忆和主动工具调用 |
context |
只自动注入上下文,不暴露工具 | 希望 Agent 无感使用记忆,不主动操作工具 |
tools |
只暴露工具,不自动注入上下文 | 希望 Agent 自主决定何时检索或保存记忆 |
环境变量
| Variable | Description |
|---|---|
DUMEMORY_API_KEY |
duMemory API Key |
DUMEMORY_API_URL |
覆盖 API 地址 |
DUMEMORY_BANK_ID |
覆盖默认 Memory Bank 名称 |
DUMEMORY_TIMEOUT |
API 请求超时时间,单位秒 |
DUMEMORY_RETAIN_SOURCE |
自动写入的 metadata.source |
DUMEMORY_RETAIN_USER_PREFIX |
用户消息保存前缀 |
DUMEMORY_RETAIN_ASSISTANT_PREFIX |
助手消息保存前缀 |
完整配置示例
1{
2 "api_url": "https://cloud.memory.bj.baidubce.com/api",
3 "bank_id": "hermes",
4 "memory_mode": "hybrid",
5 "recall_prefetch_method": "recall",
6 "recall_budget": "mid",
7 "recall_max_tokens": 4096,
8 "recall_max_input_chars": 800,
9 "recall_types": "observation",
10 "recall_tags": "",
11 "recall_tags_match": "any",
12 "retain_tags": "",
13 "retain_async": true,
14 "retain_every_n_turns": 1,
15 "retain_context": "conversation between Hermes Agent and the User",
16 "auto_recall": true,
17 "auto_retain": true,
18 "timeout": 120
19}
工作方式
初始化时,插件读取 ~/.hermes/dumemory/config.json 和 ~/.hermes/.env,创建 duMemory 云端客户端,并根据 Hermes 传入的 session 信息决定当前 Memory Bank。
对话进行时,queue_prefetch() 会在后台线程中执行自动 recall 或 reflect;下一轮 prefetch() 会把结果注入上下文。每轮对话结束后,sync_turn() 会把 user 和 assistant 消息写入 retain 队列,由单独的 writer 线程发送到云端。
当 Hermes 切换 session 时,插件会先把旧 session 中尚未保存的内容加入写入队列,再刷新当前 session 的 document 状态。关闭时,插件会等待写入线程和预取线程结束,并关闭云端客户端。
使用建议
- 默认使用
memory_mode: "hybrid",同时获得自动上下文和工具能力。 - 日常对话建议
recall_budget: "mid";对延迟敏感时可改为low。 - 自动注入上下文建议优先使用
recall_types: "observation",避免上下文过长。 - 多用户场景建议通过
bank_id_template或 tags 做隔离。 - API Key 建议只写入
~/.hermes/.env或系统环境变量,不写入公开配置。
评价此篇文章
