2004 字
10 分钟
从零搭建个人 AI 助手:Hermes Agent + 微信 + 飞书全平台接入实战
从零搭建个人 AI 助手:Hermes Agent + 微信 + 飞书全平台接入实战
🤖 写在前面:你有没有幻想过有一个 24 小时在线的 AI 助手?你在微信上给它发条消息,它就能帮你看代码、查资料、写文章?今天我就把压箱底的教程拿出来,手把手教你从零搭建一个能同时在微信和飞书上为你服务的 AI 助手。不要 998,不要 198,一个 Hermes Agent 全搞定。
一、最终效果预览
先看看做完之后是什么效果:
📱 你(微信):帮我查一下 Python 列表推导式的性能🤖 Hermes:列表推导式比传统 for 循环快 2-3 倍,原因是…… (附代码示例和 Benchmark 数据)
📱 PM(飞书):下午 3 点的需求评审准备好了吗?🤖 Hermes:(自动回复)已整理好会议 agenda: 1. 新功能架构评审 2. API 接口设计 3. 数据库表变更 已同步到飞书文档,链接:[docs.feishu.cn/xxx]
⏰ 每天 9:00:🤖 Hermes:早上好!今天的安排是—— · 10:00 代码 Review · 14:00 技术分享会 · 今日 GitHub Trending 有 3 个项目值得关注 · 你的博客昨天新增 256 次访问听起来是不是很酷?那我们就开始动手吧!
二、整体架构
┌─────────────────────────────────────────────────┐│ 你的服务器 ││ ││ ┌──────────────┐ ┌─────────────┐ ││ │ Hermes Agent│ │ Cron 调度 │ ││ │ (核心引擎) │◄──┤ (定时任务) │ ││ └──────┬───────┘ └─────────────┘ ││ │ ││ ┌──────┴───────┐ ││ │ MCP 工具 │ ││ │ ┌───┐ ┌───┐ │ ││ │ │文件│ │Web │ │ ││ │ └───┘ └───┘ │ ││ │ ┌───┐ ┌───┐ │ ││ │ │Git │ │DB │ │ ││ │ └───┘ └───┘ │ ││ └──────┬───────┘ │└──────────┼──────────────────────────────────────┘ │ ┌───────┴────────┐ │ 消息网关 │ ├──────┬─────────┤ │ 微信 │ 飞书 │ └──────┴─────────┘三、安装 Hermes Agent
3.1 服务器准备
首先,你需要一台能跑 Python 的服务器。推荐配置:
- CPU:2 核以上
- 内存:4GB 以上
- 系统:Ubuntu 22.04 / Debian 12
- 网络:能访问 GitHub 和 LLM API(境外服务器最好)
3.2 安装 Hermes
# 更新系统sudo apt update && sudo apt upgrade -y
# 安装 Python 和 pipsudo apt install python3 python3-pip python3-venv -y
# 创建虚拟环境python3 -m venv /opt/hermes-envsource /opt/hermes-env/bin/activate
# 安装 Hermes Agentpip install hermes-agent
# 验证安装hermes --version# 应该输出: Hermes Agent v0.15.1+3.3 初始化配置
# 初始化hermes init
# 配置 LLM 提供商(这里用 OpenRouter 作为例子)hermes config set provider openrouterhermes config set model anthropic/claude-sonnet-4hermes config set openrouter.api_key "sk-or-v1-your-key-here"
# 验证配置hermes config list四、接入微信
作为国内用户,微信肯定是最重要的入口。
4.1 注册企业微信应用
Hermes 通过企业微信的开放接口接入微信,这样就不需要担心封号问题。
# 1. 登录 https://work.weixin.qq.com/# 2. 创建应用# 3. 获取以下信息:# - CorpID# - AgentID# - Secret4.2 配置 Hermes 微信连接
weixin: corp_id: "ww1234567890" agent_id: 1000001 secret: "your-secret-here" token: "your-callback-token" # 自定义 encoding_aes_key: "your-aes-key" # 自动生成
# 配置欢迎消息 welcome_message: | 🤖 你好!我是你的 AI 助手。 你可以直接问我任何技术问题,或者试试以下功能: - /help 查看全部命令 - /blog 写一篇技术文章 - /code 帮我写段代码 - /web 搜索网页信息
# 配置 AI 回复 ai_reply: enabled: true model: "claude-sonnet-4" temperature: 0.7 max_tokens: 40964.3 启动服务
# 启动 Hermes(建议使用 screen 或 tmux 保持后台运行)hermes run4.4 配置企业微信回调
企业微信需要配置一个公网可访问的回调地址:
# Nginx 配置server { listen 80; server_name your-domain.com;
location /weixin/callback { proxy_pass http://localhost:8000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; }}五、接入飞书
飞书在国内企业里用得很多,特别是字节跳动的生态。
5.1 创建飞书应用
# 1. 登录 https://open.feishu.cn/# 2. 创建企业自建应用# 3. 开启机器人能力# 4. 获取 App ID 和 App Secret5.2 配置 Hermes
# config.yaml 追加feishu: app_id: "cli_xxxxxxxx" app_secret: "your-app-secret"
# 配置自动回复 auto_reply: enabled: true
# 配置群聊白名单(防止在所有群里都回) chat_whitelist: - "oc_xxxxxx" # 技术讨论群 - "oc_yyyyyy" # 项目开发群六、配置定时任务
6.1 每日技术简报
每天早上推送 GitHub Trending 和技术新闻:
hermes cron create \ --name "daily-briefing" \ --schedule "0 9 * * 1-5" \ --prompt "整理今天 GitHub Trending 上的热门项目和技术新闻,生成一份 3-5 条的简报,发送到微信" \ --deliver "weixin"6.2 博客自动更新
hermes cron create \ --name "blog-update" \ --schedule "0 10 * * *" \ --prompt "调研今天的技术热点,写 5-8 篇技术文章,一次性推送到博客仓库" \ --workdir "/opt/data/blog"6.3 周报生成器
hermes cron create \ --name "weekly-report" \ --schedule "0 18 * * 5" \ --prompt "回顾本周的工作内容,生成周报并发送到飞书文档" \ --deliver "feishu"七、高级玩法
7.1 自定义命令
# 在技能系统中添加自定义命令@hermes.command("translate")async def translate_command(text: str, target_lang: str = "zh"): """翻译文本:/translate Hello world -> zh""" result = await llm.translate(text, target_lang) return result
@hermes.command("weather")async def weather_command(city: str): """查询天气:/weather 北京""" import httpx async with httpx.Client() as client: resp = await client.get(f"https://wttr.in/{city}?format=3") return resp.text7.2 MCP 工具集成
通过 MCP 协议连接更多工具:
tools: mcp: servers: # 文件系统操作 filesystem: command: npx args: ["-y", "@modelcontextprotocol/server-filesystem"]
# 数据库查询 database: command: python args: ["mcp-db-server.py"]
# Jira 集成 jira: command: npx args: ["-y", "@anthropic/jira-mcp"]7.3 多 Agent 编排
当任务太复杂时,可以让 Hermes 调度多个子 Agent:
@hermes.workflow("project-analysis")async def analyze_project(repo_url: str): """分析一个 GitHub 项目"""
# Stage 1: 代码审查 code_review = await hermes.delegate( goal="审查这个项目的代码质量", context=f"项目地址:{repo_url}" )
# Stage 2: 性能分析 perf_analysis = await hermes.delegate( goal="分析项目的性能瓶颈", context=f"代码分析结果:{code_review}" )
# Stage 3: 生成报告 report = await hermes.delegate( goal="综合前面的分析,生成完整的项目评估报告", context=f"代码审查:{code_review}\n性能分析:{perf_analysis}" )
return report八、运维与监控
8.1 查看日志
# 实时查看日志hermes logs --follow
# 查看最近 100 条hermes logs --tail 100
# 按级别过滤hermes logs --level ERROR8.2 健康检查
# 检查各个连接状态hermes status# 输出:# ✅ 微信连接正常# ✅ 飞书连接正常# ✅ LLM API 正常# ✅ MCP 工具:4/4 在线# ✅ Cron 调度:3 个任务活跃8.3 自动重启
# 使用 systemd 设置开机自启sudo cat > /etc/systemd/system/hermes.service << 'EOF'[Unit]Description=Hermes AgentAfter=network.target
[Service]Type=simpleUser=hermesExecStart=/opt/hermes-env/bin/hermes runWorkingDirectory=/opt/hermesRestart=alwaysRestartSec=10
[Install]WantedBy=multi-user.targetEOF
sudo systemctl enable hermessudo systemctl start hermes九、常见问题
Q1: 微信消息延迟?
检查企业微信的回调配置,确保公网 IP 和端口能正常访问。另外,企业微信免费版的消息频率限制比较严,可以考虑升级到企业版。
Q2: AI 回复太慢?
- 用速度更快的模型(比如 DeepSeek 或者 GPT-4o mini)
- 降低
max_tokens限制 - 检查服务器网络到 LLM API 的延迟
Q3: 怎么让 Hermes 更像”人”?
调整 prompt:
# 给 Hermes 设置一个"人格"system_prompt: | 你是一个热情的技术专家,叫"辉哥"。 你说话风趣幽默,但技术功底扎实。 回答问题时先用简单的话解释,再深入技术细节。 不要一板一眼,多用比喻和段子。十、总结
从零到一搭建一个全平台 AI 助手,其实只需要三步:
- 装一个 Hermes Agent(5 分钟)
- 连上微信和飞书(10 分钟)
- 配置定时任务(5 分钟)
总耗时不到半小时,你就拥有了一个 24 小时在线的 AI 助手。它能:
- 💬 在微信/飞书上回答你的技术问题
- 📝 自动写博客文章发到 GitHub
- 📊 定时生成日报/周报
- 🔍 替你搜索和整理信息
- 🐛 帮你调试代码
最棒的是,这一切都是免费的——你只需要付 LLM API 的费用(如果你用 DeepSeek 的话,一个月十几块钱就够了)。
💡 行动起来:别光收藏了,现在就 SSH 到你的服务器上,装个 Hermes 试试。半小时后,你就会来评论区跟我说:真香!
有什么问题欢迎在评论区留言,我会用我的 AI 助手回复你 😄
从零搭建个人 AI 助手:Hermes Agent + 微信 + 飞书全平台接入实战
https://www.oferry.com/posts/a97/