消息网关
通过 Telegram、Discord、Slack、WhatsApp、Signal、短信、电子邮件、Home Assistant、Mattermost、Matrix、钉钉、飞书/飞书(Lark)、企业微信、微信、BlueBubbles(iMessage)或您的浏览器与 Hermes 进行聊天。该网关是一个单一的后台进程,可连接到您配置的所有平台,管理会话,运行定时任务,并发送语音消息。
如需完整语音功能集——包括 CLI 麦克风模式、消息中的语音回复以及 Discord 语音频道对话——请参阅 语音模式 和 使用语音模式与 Hermes。
平台对比
| 平台 | 语音 | 图片 | 文件 | 线程 | 表情反应 | 键入指示 | 流式传输 |
|---|---|---|---|---|---|---|---|
| Telegram | ✅ | ✅ | ✅ | ✅ | — | ✅ | ✅ |
| Discord | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Slack | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| — | ✅ | ✅ | — | — | ✅ | ✅ | |
| Signal | — | ✅ | ✅ | — | — | ✅ | ✅ |
| 短信 | — | — | — | — | — | — | — |
| 电子邮件 | — | ✅ | ✅ | ✅ | — | — | — |
| Home Assistant | — | — | — | — | — | — | — |
| Mattermost | ✅ | ✅ | ✅ | ✅ | — | ✅ | ✅ |
| Matrix | ✅ | ✅ | ✅ | ✅ | — | ✅ | ✅ |
| 钉钉 | — | — | — | — | — | ✅ | ✅ |
| 飞书/飞书(Lark) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 企业微信 | ✅ | ✅ | ✅ | — | — | ✅ | ✅ |
| 微信 | ✅ | ✅ | ✅ | — | — | ✅ | ✅ |
| BlueBubbles | — | ✅ | ✅ | — | ✅ | ✅ | — |
语音 = TTS 语音回复和/或语音消息转录。图片 = 发送/接收图片。文件 = 发送/接收文件附件。线程 = 线程化对话。表情反应 = 消息上的表情反应。键入指示 = 处理时的键入指示。流式传输 = 通过编辑实现渐进式消息更新。
架构
每个平台适配器接收消息,通过每聊天会话存储进行路由,并将消息分发给 AIAgent 进行处理。网关还运行定时调度器,每 60 秒触发一次,执行所有到期的任务。
快速设置
配置消息平台最简单的方法是使用交互式向导:
hermes gateway setup # Interactive setup for all messaging platforms
该向导通过方向键选择,引导您完成每个平台的配置,显示哪些平台已配置,并在完成后提供启动/重启网关的选项。
网关命令
hermes gateway # Run in foreground
hermes gateway setup # Configure messaging platforms interactively
hermes gateway install # Install as a user service (Linux) / launchd service (macOS)
sudo hermes gateway install --system # Linux only: install a boot-time system service
hermes gateway start # Start the default service
hermes gateway stop # Stop the default service
hermes gateway status # Check default service status
hermes gateway status --system # Linux only: inspect the system service explicitly
聊天命令(在消息中使用)
| 命令 | 描述 |
|---|---|
/new 或 /reset | 开始一次全新的对话 |
/model [provider:model] | 显示或更改模型(支持 provider:model 语法) |
/provider | 显示可用的提供者及其认证状态 |
/personality [name] | 设置一个个性 |
/retry | 重试上一条消息 |
/undo | 删除上一次交互 |
/status | 显示会话信息 |
/stop | 停止正在运行的代理 |
/approve | 批准待处理的危险命令 |
/deny | 拒绝待处理的危险命令 |
/sethome | 将此聊天设为首页频道 |
/compress | 手动压缩对话上下文 |
/title [name] | 设置或显示会话标题 |
/resume [name] | 恢复之前命名的会话 |
/usage | 显示此会话的 token 使用情况 |
/insights [days] | 显示使用情况洞察和分析 |
/reasoning [level|show|hide] | 更改推理努力程度或切换推理显示 |
/voice [on|off|tts|join|leave|status] | 控制消息语音回复及 Discord 语音频道行为 |
/rollback [number] | 列出或恢复文件系统检查点 |
/background <prompt> | 在独立后台会话中运行提示 |
/reload-mcp | 从配置重新加载 MCP 服务器 |
/update | 将 Hermes Agent 更新到最新版本 |
/help | 显示可用命令 |
/<skill-name> | 调用任何已安装的技能 |
会话管理
会话持久化
会话在消息之间持续存在,直到被重置。代理会记住您的对话上下文。
重置策略
会话根据可配置的策略进行重置:
| 策略 | 默认值 | 描述 |
|---|---|---|
| 每日 | 凌晨 4:00 | 每天特定时间重置 |
| 空闲 | 1440 分钟 | 无操作 N 分钟后重置 |
| 两者 | (组合) | 任一条件先触发即重置 |
可在 ~/.hermes/gateway.json 中为各平台配置覆盖设置:
{
"reset_by_platform": {
"telegram": { "mode": "idle", "idle_minutes": 240 },
"discord": { "mode": "idle", "idle_minutes": 60 }
}
}
安全性
默认情况下,网关会拒绝所有未在允许列表中或未通过私信配对的用户。 这是具有终端访问权限的机器人最安全的默认设置。
# Restrict to specific users (recommended):
TELEGRAM_ALLOWED_USERS=123456789,987654321
DISCORD_ALLOWED_USERS=123456789012345678
SIGNAL_ALLOWED_USERS=+155****4567,+155****6543
SMS_ALLOWED_USERS=+155****4567,+155****6543
EMAIL_ALLOWED_USERS=trusted@example.com,colleague@work.com
MATTERMOST_ALLOWED_USERS=3uo8dkh1p7g1mfk49ear5fzs5c
MATRIX_ALLOWED_USERS=@alice:matrix.org
DINGTALK_ALLOWED_USERS=user-id-1
# Or allow
GATEWAY_ALLOWED_USERS=123456789,987654321
# Or explicitly allow all users (NOT recommended for bots with terminal access):
GATEWAY_ALLOW_ALL_USERS=true
私信配对(允许列表的替代方案)
无需手动配置用户 ID,未知用户在向机器人发送私信时会收到一次性配对码:
# The user sees: "Pairing code: XKGH5N7P"
# You approve them with:
hermes pairing approve telegram XKGH5N7P
# Other pairing commands:
hermes pairing list # View pending + approved users
hermes pairing revoke telegram 123456789 # Remove access
配对码 1 小时后过期,受速率限制,并使用加密随机性生成。
中断代理
当代理正在工作时,发送任何消息即可中断它。关键行为如下:
- 正在进行的终端命令会立即终止(先发送 SIGTERM,1 秒后发送 SIGKILL)
- 工具调用会被取消 — 仅执行当前正在运行的调用,其余调用将被跳过
- 多条消息会被合并 — 中断期间发送的消息将合并为一条提示
/stop命令 — 中断操作且不排队后续消息
工具执行进度通知
通过 ~/.hermes/config.yaml 控制在聊天中显示多少工具活动信息:
display:
tool_progress: all # off | new | all | verbose
tool_progress_command: false # set to true to enable /verbose in messaging
启用后,机器人在执行任务时会发送状态消息:
💻 `ls -la`...
🔍 web_search...
📄 web_extract...
🐍 execute_code...
后台会话
在独立的后台会话中运行提示,使代理能独立处理任务,同时保持主聊天的响应性:
/background Check all servers in the cluster and report any that are down
Hermes 会立即确认:
🔄 Background task started: "Check all servers in the cluster..."
Task ID: bg_143022_a1b2c3
工作原理
每个 /background 提示都会启动一个独立的代理实例,异步运行:
- 隔离会话 — 后台代理拥有独立的会话和独立的对话历史。它不了解你当前聊天的上下文,仅接收你提供的提示。
- 相同配置 — 继承当前网关设置中的模型、提供商、工具集、推理设置和提供商路由。
- 非阻塞 — 主聊天保持完全可交互。在后台任务运行时,你仍可发送消息、执行其他命令或启动更多后台任务。
- 结果交付 — 任务完成后,结果将发送回你发出命令的同一聊天或频道,并以“✅ 后台任务完成”为前缀。如果失败,你会看到“❌ 后台任务失败”及错误信息。
后台进程通知
当运行后台会话的代理使用 terminal(background=true) 启动长时间运行的进程(如服务器、构建等)时,网关可将状态更新推送到你的聊天。通过 ~/.hermes/config.yaml 中的 display.background_process_notifications 控制此功能:
display:
background_process_notifications: all # all | result | error | off
| 模式 | 你将收到的内容 |
|---|---|
all | 运行输出更新 以及 最终完成消息(默认) |
result | 仅接收最终完成消息(无论退出码如何) |
error | 仅在退出码非零时接收最终消息 |
off | 完全不接收进程监视消息 |
你也可以通过环境变量设置此选项:
HERMES_BACKGROUND_NOTIFICATIONS=result
使用场景
- 服务器监控 — “/background 检查所有服务的健康状况,若有任何宕机则提醒我”
- 长时间构建 — “/background 构建并部署预发布环境”,同时继续聊天
- 研究任务 — “/background 研究竞争对手定价并以表格形式总结”
- 文件操作 — “/background 将 ~/Downloads 中的照片按日期整理到对应文件夹”
在消息平台上的后台任务是“发送即忘”——你无需等待或主动检查。任务完成后,结果会自动返回到同一聊天中。
服务管理
Linux(systemd)
hermes gateway install # Install as user service
hermes gateway start # Start the service
hermes gateway stop # Stop the service
hermes gateway status # Check status
journalctl --user -u hermes-gateway -f # View logs
# Enable lingering (keeps running after logout)
sudo loginctl enable-linger $USER
# Or install a boot-time system service that still runs as your user
sudo hermes gateway install --system
sudo hermes gateway start --system
sudo hermes gateway status --system
journalctl -u hermes-gateway -f
在笔记本电脑和开发机上使用用户级服务。在 VPS 或无头主机上使用系统级服务,确保系统启动时自动恢复,无需依赖 systemd linger。
除非你确实需要,否则避免同时安装用户和服务级网关单元。Hermes 检测到两者共存时会发出警告,因为启动/停止/状态行为会变得模糊。
如果你在同一台机器上运行多个 Hermes 安装(使用不同的 HERMES_HOME 目录),每个安装都会拥有自己的 systemd 服务名称。默认的 ~/.hermes 使用 hermes-gateway;其他安装使用 hermes-gateway-<hash>。hermes gateway 命令会自动针对当前 HERMES_HOME 选择正确的服务。
macOS(launchd)
hermes gateway install # Install as launchd agent
hermes gateway start # Start the service
hermes gateway stop # Stop the service
hermes gateway status # Check status
tail -f ~/.hermes/logs/gateway.log # View logs
生成的 plist 文件位于 ~/Library/LaunchAgents/ai.hermes.gateway.plist。它包含三个环境变量:
- PATH — 安装时的完整 shell PATH,已在前面添加了 venv 的
bin/和node_modules/.bin。这确保用户安装的工具(如 Node.js、ffmpeg 等)可供网关子进程(如 WhatsApp 桥接)使用。 - VIRTUAL_ENV — 指向 Python 虚拟环境,确保工具能正确解析包。
- HERMES_HOME — 将网关限定到你的 Hermes 安装目录。
launchd plist 是静态的 —— 如果你在设置网关后安装了新工具(例如通过 nvm 安装新版本 Node.js,或通过 Homebrew 安装 ffmpeg),请再次运行 hermes gateway install 以捕获更新后的 PATH。网关会检测到过时的 plist 并自动重新加载。
与 Linux systemd 服务类似,每个 HERMES_HOME 目录都有自己的 launchd 标签。默认的 ~/.hermes 使用 ai.hermes.gateway;其他安装使用 ai.hermes.gateway-<suffix>。
平台特定工具集
每个平台都有其专属的工具集:
| 平台 | 工具集 | 功能特性 |
|---|---|---|
| 命令行界面 (CLI) | hermes-cli | 完全访问权限 |
| Telegram | hermes-telegram | 完整工具集,包括终端 |
| Discord | hermes-discord | 完整工具集,包括终端 |
hermes-whatsapp | 完整工具集,包括终端 | |
| Slack | hermes-slack | 完整工具集,包括终端 |
| Signal | hermes-signal | 完整工具集,包括终端 |
| 短信 (SMS) | hermes-sms | 完整工具集,包括终端 |
| 邮件 | hermes-email | 完整工具集,包括终端 |
| Home Assistant | hermes-homeassistant | 完整工具集 + HA 设备控制(ha_list_entities, ha_get_state, ha_call_service, ha_list_services) |
| Mattermost | hermes-mattermost | 完整工具集,包括终端 |
| Matrix | hermes-matrix | 完整工具集,包括终端 |
| 钉钉 | hermes-dingtalk | 完整工具集,包括终端 |
| 飞书 / Lark | hermes-feishu | 完整工具集,包括终端 |
| 企业微信 | hermes-wecom | 完整工具集,包括终端 |
| 微信 | hermes-weixin | 完整工具集,包括终端 |
| BlueBubbles | hermes-bluebubbles | 完整工具集,包括终端 |
| API 服务器 | hermes(默认) | 完整工具集,包括终端 |
| Webhooks | hermes-webhook | 完整工具集,包括终端 |