Skip to content

Hermes 的 Profile 系统是多实例隔离的核心机制:每个 Profile 是 ~/.hermes/profiles/<name>/ 下的独立目录,包含各自的 config.yaml、.env(API Key)、记忆库、会话历史、技能和日志。切换 Profile 本质上是改变 HERMES_HOME 环境变量的值——Hermes 的所有数据都从这个变量指向的目录读写。

Hermes Agent 多实例 Profile 隔离:一台机器跑多个完全独立的 AI 助手

使用 AI 助手时,工作环境和个人环境经常有冲突:工作要用公司的 API Key、限制记忆范围不泄露私人信息;个人开发想换便宜的 Gemini Flash 降低成本;编程时想换 DeepSeek 专注代码。Hermes Profile 的解法是:每个 Profile 是完全独立的文件系统视图,互不干扰。

Profile 隔离的核心原理

Hermes 所有数据存储路径都通过 HERMES_HOME 环境变量决定:

python
# hermes_constants.py (简化)
def get_hermes_home() -> Path:
    return Path(os.environ.get("HERMES_HOME", Path.home() / ".hermes"))

Profile 的本质是:启动前把 HERMES_HOME 指向不同的目录

~/.hermes/                    ← 默认 Profile(HERMES_HOME 默认值)
~/.hermes/profiles/
    work/                     ← work Profile(HERMES_HOME=~/.hermes/profiles/work)
    personal/                 ← personal Profile
    coding/                   ← coding Profile

每个 Profile 的目录结构

~/.hermes/profiles/<name>/
├── config.yaml               # 模型配置、功能开关
├── .env                      # API Keys(独立!不共享)
├── SOUL.md                   # Agent 性格和指令
├── memories/
│   ├── MEMORY.md             # 记忆索引
│   └── USER.md               # 用户背景
├── sessions/                 # 会话历史
├── skills/                   # 已安装的技能
├── skins/                    # 自定义皮肤
├── plans/                    # 任务计划文档
├── workspace/                # Agent 工作目录
├── cron/                     # 定时任务配置
├── logs/                     # 网关日志
└── gateway.pid               # 网关进程 ID(运行时生成)

完全隔离的内容:API Key、记忆、会话历史、技能、皮肤、定时任务、网关实例。

创建和使用 Profile

创建新 Profile

bash
# 创建全新的空白 Profile
hermes profile create work

# 从当前 Profile 复制配置(config.yaml、.env、SOUL.md)
hermes profile create work --clone

# 完整克隆当前 Profile(包括记忆、会话、技能)
hermes profile create work --clone-all

# 从指定 Profile 复制
hermes profile create personal --clone-from work

创建时默认同时:

  1. 建立 ~/.hermes/profiles/work/ 目录及子目录
  2. 把捆绑技能同步到新 Profile(通过独立子进程,避免 HERMES_HOME 缓存问题)
  3. ~/.local/bin/work 创建 wrapper script

Wrapper Script:让 Profile 成为独立命令

bash
# ~/.local/bin/work 的内容(自动生成)
#!/bin/sh
exec hermes -p work "$@"

创建后,可以直接用 work 命令启动(不需要带 -p work):

bash
work          # 相当于 hermes --profile work
work chat     # 启动 work Profile 的 CLI
work gateway telegram  # 用 work Profile 启动 Telegram 网关

如果不想创建 wrapper,用 --no-alias 参数:

bash
hermes profile create work --no-alias

切换 Profile

bash
# 临时切换(只影响当前命令)
hermes --profile work
hermes -p work

# 设为 sticky 默认(写入 ~/.hermes/active_profile)
hermes profile use work

# 查看当前 active Profile
hermes profile list

active_profile 文件是切换 Profile 的"记忆":

python
# main.py 启动时
def _apply_profile_override() -> None:
    # 1. 检查命令行 --profile/-p 参数
    # 2. 没有则读 ~/.hermes/active_profile 文件
    # 3. 找到 profile name 后,resolve 路径,设置 HERMES_HOME
    hermes_home = resolve_profile_env(profile_name)
    os.environ["HERMES_HOME"] = str(hermes_home)

注意:HERMES_HOME 的设置必须在所有模块导入之前完成(main.py 最顶部调用),否则各模块的路径缓存会指向错误的目录。

管理命令

查看所有 Profile

bash
hermes profile list

输出示例:

Profiles:
  default    claude-opus-4.6    5 skills    gateway: ✓
  work       gpt-4.1 (copilot)  8 skills    gateway: ✗
* personal   gemini/flash        3 skills    gateway: ✗
  coding     deepseek-coder      6 skills    gateway: ✗

* = active profile

字段说明:

  • gateway: ✓:该 Profile 的网关进程正在运行(通过读 gateway.pid 检查进程是否存活)
  • * = active profile:当前 sticky 默认 Profile

在 CLI 内查看 Profile 信息

bash
/profile   # 显示当前 Profile 名称和 HERMES_HOME 目录

删除 Profile

bash
hermes profile delete work

删除会同时:

  1. 停止运行中的网关进程
  2. 禁用 systemd/launchd 服务(防止自动重启)
  3. 删除 ~/.local/bin/work wrapper script
  4. 删除整个 ~/.hermes/profiles/work/ 目录

导出和导入

bash
# 导出 default Profile 为可移植压缩包
hermes profile export --output hermes-profile.tar.gz

# 导入到另一台机器
hermes profile import hermes-profile.tar.gz --name myprofile

导出时会自动排除大型基础设施文件(git 仓库、数据库文件、node_modules、日志等),只保留可移植的配置和数据。

典型使用场景

工作 / 个人 / 编程三分离

bash
# 工作 Profile:公司 API Key,Claude Opus,不记录私人信息
hermes profile create work --clone
# 编辑 ~/.hermes/profiles/work/.env 换成公司 Key

# 个人 Profile:个人 Key,Gemini Flash(省钱),记录生活碎片
hermes profile create personal

# 编程 Profile:DeepSeek Coder,代码专用记忆
hermes profile create coding

# 日常使用
work          # 进入工作模式
personal      # 进入个人模式
coding        # 进入编程模式

多 Telegram Bot 部署

不同 Profile 可以各自运行一个 Telegram 网关,绑定不同 Bot Token:

bash
# 工作 Bot:绑定 work Profile
work gateway telegram    # ~/.hermes/profiles/work/.env 里有 TELEGRAM_BOT_TOKEN_WORK

# 个人 Bot:绑定 personal Profile
personal gateway telegram  # ~/.hermes/profiles/personal/.env 里有另一个 Token

两个网关进程独立运行,各自有自己的 gateway.pid,不互相干扰。

多用户服务器部署

在共享服务器上给不同用户/团队提供独立 AI 助手实例:

bash
# 每个用户一个 Profile
hermes profile create alice
hermes profile create bob

# 用 gateway API Server 模式各自暴露 HTTP 接口
hermes -p alice gateway api --port 8001
hermes -p bob gateway api --port 8002

Profile 名称规则

Profile 名称限制:

  • 只能用小写字母、数字、连字符、下划线
  • 长度 1~64 字符
  • 不能用保留名(hermes / default / test 等)
  • 不能和 Hermes 子命令同名(chat / gateway / setup 等)
  • 不能和系统已有命令冲突(会在 $PATH 里检查)

这些限制是为了保证 wrapper script 不会覆盖系统重要命令。

FAQ

Q: 默认 Profile 和 named Profile 有什么区别?

默认 Profile 是 ~/.hermes/ 本身,历史上 Hermes 只有这一个目录。Named Profile 是 ~/.hermes/profiles/<name>/,和默认 Profile 目录结构完全相同,只是位置不同。两者功能上完全等价。

Q: --clone--clone-all 有什么区别?

--clone 只复制配置文件(config.yaml、.env、SOUL.md、MEMORY.md),记忆和会话历史不复制——适合"从相同起点开始但保持独立"的场景。--clone-all 全量复制(除了 gateway.pid / processes.json 等运行时文件),适合备份或迁移。

Q: Profile 之间能共享技能吗?

不直接共享。每个 Profile 有独立的 skills/ 目录。hermes update 更新内置技能时,会自动同步到所有 Profile(通过 seed_profile_skills 以独立子进程运行,避免 HERMES_HOME 缓存问题)。

Q: 切换 Profile 后,原 Profile 的网关还在运行吗?

是的。每个 Profile 的网关独立运行,互不影响。切换 Profile 只改变 CLI 会话读写哪个目录,不影响其他 Profile 正在运行的网关进程。


本系列文章

Provider 与成本优化

能力扩展

部署与集成

内部机制深度解析