🌐 Hermes Agent 配置与平台接入

第 4 篇 — 接入微信/Telegram,让 AI 无处不在

🎯 这篇讲什么

Hermes 真正的威力在于多平台接入。配好后,同一个 AI 可以同时在微信、Telegram、Discord 上为你服务。


🏗 核心概念:网关(Gateway)


┌─────────────┐
│  微信用户    │──┐
└─────────────┘  │
                 │     ┌──────────────┐      ┌─────────────┐
┌─────────────┐  ├────→│   Hermes     │─────→│  AI 模型     │
│ Telegram     │──┤     │   Gateway    │      │ (DeepSeek/   │
└─────────────┘  │     └──────────────┘      │  Claude/...) │
                 │                            └─────────────┘
┌─────────────┐  │
│ Discord      │──┘
└─────────────┘

网关就像一个总机接线员:所有聊天软件的消息统一转给 AI,再把回复发回去。


⚙ 基本命令速查


hermes gateway setup        # 交互式配置平台
hermes gateway run          # 前台运行(调试用)
hermes gateway install      # 安装为系统服务
hermes gateway start        # 启动服务
hermes gateway stop         # 停止服务
hermes gateway restart      # 重启服务
hermes gateway status       # 查看状态

📱 平台接入指南

微信 (Weixin)

适用场景:个人微信/企业微信,国内最实用


# 1. 进入网关配置
hermes gateway setup
# → 选择 "Weixin"

# 2. 按提示配置回调 URL 和 Token

# 3. 在企业微信后台配置应用
# 需要:企业 ID、应用 Secret、Token、EncodingAESKey

配置示例(~/.hermes/config.yaml 对应部分):


gateway:
  platforms:
    weixin:
      enabled: true
      corp_id: "wx开头的企业ID"
      agent_id: "应用ID"
      secret: "应用Secret"
      token: "你自己设置的Token"
      encoding_aes_key: "43位随机字符串"

Telegram


# 1. 找 @BotFather 创建 Bot,拿到 Token
# 2. 配置
hermes gateway setup
# → 选择 "Telegram"
# → 输入 Token

# 3. 启动
hermes gateway start

gateway:
  platforms:
    telegram:
      enabled: true
      token: "123456:ABC-DEF1234ghikl..."

Discord


# 1. https://discord.com/developers/applications
# 2. 创建 Application → Bot → 拿到 Token
# 3. 必须开启 Message Content Intent(Privileged Gateway Intents)
# 4. OAuth2 生成邀请链接,加 Bot 进服务器

gateway:
  platforms:
    discord:
      enabled: true
      token: "你的Bot Token"

Slack


gateway:
  platforms:
    slack:
      enabled: true
      bot_token: "xoxb-..."
      app_token: "xapp-..."
⚠ Slack Bot 默认只能私聊。要响应频道消息,需订阅 message.channels 事件。

🔧 高级配置

多套配置(Profiles)

在家一套配置,在公司一套配置,互不干扰:


# 创建工作配置
hermes profile create work --clone

# 切换配置
hermes profile use work

# 列出所有配置
hermes profile list

每个 profile 有独立的:

API Key 池(自动切换密钥防限流)


# 添加多个密钥
hermes auth add
# → 选择提供商 → 输入密钥

# 查看密钥池
hermes auth list

# 重置用完的密钥
hermes auth reset deepseek

定时任务(Cron)

自动执行重复任务,像设闹钟一样简单:


# 每天 9 点发天气
hermes cron create "0 9 * * *" --prompt "查询北京今天天气并发到微信"

# 每 30 分钟检查服务器状态
hermes cron create "30m" --prompt "ssh 到服务器检查 CPU 和内存,如果 > 80% 通知我"

# 查看所有定时任务
hermes cron list

# 暂停 / 恢复 / 删除
hermes cron pause <job_id>
hermes cron resume <job_id>
hermes cron remove <job_id>

🛡 安全与隐私

命令批准模式


# 推荐:智能模式(小操作自动批准,危险操作需确认)
hermes config set approvals.mode smart

# 危险:关闭所有批准(不推荐)
hermes config set approvals.mode off

PII 脱敏(网关消息中隐藏手机号等)


hermes config set privacy.redact_pii true

密钥不泄露

Hermes 不会.env 里的密钥发给 AI。安全。


📊 日常管理


# 查看 AI 使用量和花费
hermes insights
hermes insights --days 30

# 查看对话历史
hermes sessions list
hermes sessions browse

# 更新 Hermes
hermes update

# 查看日志排查问题
tail -100 ~/.hermes/logs/gateway.log
grep -i "error" ~/.hermes/logs/gateway.log | tail -20

🔄 与 Claude Code 协同

Hermes 和 Claude Code 不是竞争关系,是合作关系:


# 在 Hermes 中装 Claude Code 技能
hermes skills install claude-code

# 然后通过微信/TG 说:
# "帮我在 ~/myproject 里用 claude code 重构 auth.py"
# Hermes 会自动调用 Claude Code 完成,把结果发回微信

用户(微信) → Hermes(网关) → Claude Code(编码) → 结果 → 微信

🏥 网关常见问题急救


# 1. 网关连不上
hermes gateway status                # 看状态
systemctl --user status hermes-gateway  # 看系统级状态

# 2. 网关崩溃循环
systemctl --user reset-failed hermes-gateway

# 3. SSH 断开网关就挂(Linux)
sudo loginctl enable-linger $USER

# 4. WSL2 网关随窗口关闭
# 在 /etc/wsl.conf 加:
# [boot]
# systemd=true

# 5. 查看最近错误
grep -i "failed\|error" ~/.hermes/logs/gateway.log | tail -20

🚦 下一步


❓ 常见问题 (FAQ)

Q1: 微信接入需要企业微信吗?

取决于接入方式。Hermes 官方支持的是企业微信应用。如果你有企业微信管理员权限,按正文配置即可。个人微信接入需要额外方案。

Q2: Telegram Bot 怎么创建?

找 @BotFather,发 /newbot,起个名字,拿到 Token。整个过程 2 分钟,免费。

Q3: 网关老是挂掉怎么办?

先查日志:tail -100 ~/.hermes/logs/gateway.log。常见原因:① SSH 断开时没开 lingering(sudo loginctl enable-linger $USER);② 内存不足 OOM;③ API Key 过期。

Q4: 多个平台能同时用吗?

✅ 网关天然支持。配好微信和 Telegram 后,同一个 AI 在两个平台同时在线。消息互不干扰。

Q5: 定时任务设了没执行?

hermes cron list 确认任务存在且未暂停;② 检查 gateway 是否在运行;③ 看 cron 日志。cron 依赖网关,网关挂了任务就不会跑。

Q6: 怎么备份配置?

直接打包:tar -czf hermes-backup.tar.gz ~/.hermes/config.yaml ~/.hermes/.env ~/.hermes/auth.json。恢复时解压回去即可。

Q7: 换电脑怎么迁移?

复制 ~/.hermes/ 整个目录到新电脑同名位置,运行 hermes doctor --fix 自动修复路径。

Q8: Profile 和直接改 config 有什么区别?

Profile = 多套独立配置,一键切换。适合「家里一套、公司一套」或「测试环境/生产环境分开」。日常用默认 profile 就够了。

Q9: 公共频道/群聊里 Bot 乱说话怎么办?

Discord:限制 Bot 只能响应 @mention。Telegram:Bot Settings → Group Privacy → 只响应 / 命令。Slack:只订阅 app_mention 事件。

Q10: 怎么让 Hermes 更聪明?

① 装更多技能(hermes skills install xxx);② 开启 self-improvement 技能让它自我进化;③ 在对话中纠正它,它会记住;④ 写好 SOUL.md 定义性格。


⚠ 平台接入最容易翻车的地方

翻车现场正确姿势
Discord Bot 加了但完全不理人必须开 Message Content Intent! 90% 的新手卡在这一步
Slack Bot 只在私聊回、频道里装死订阅 message.channels 事件,否则 Bot 看不见频道消息
hermes gateway install 后以为自动启动了install 只是装服务,还要 hermes gateway start
SSH 一断网关就挂sudo loginctl enable-linger $USER 让服务在登出后继续跑
WSL2 窗口关了网关也没了/etc/wsl.confsystemd=true,重启 WSL
网关配置改了不生效hermes gateway restart 重启服务,光改文件不够
定时任务设了 cron 表达式写错0 9 * * * = 每天 9 点,*/30 * * * * = 每 30 分钟,别搞混
安全模式 off 后 AI 乱执行命令推荐 approvals.mode smart,小操作自动批,危险操作弹确认

标签:#AI #教程 #HermesAgent #配置 #多平台