Hermes Agent 进阶玩法:终端、技能、Cron、自动化部署


前言:装好了,然后呢?

hermes install 跑通,hermes chat 能对话。接下来?

大多数教程停在「会聊天」。但 Hermes 的设计初衷是 可编程的、可编排的、可持久化的 Agent 基础设施

本文把「进阶」拆成 5 个可落地的层级,每层给配置、给命令、给避坑点。读完能直接上手:

层级 核心能力 适合场景
L1 技能系统 复用别人的最佳实践、把自己的流程固化
L2 Cron 定时任务 每日早报、定时巡检、自动发布
L3 多 Agent 编排 复杂任务拆解、并行处理、代码审查
L4 外部集成 GitHub、Notion、Telegram、Cloudflare
L5 生产级部署 博客自动化、监控告警、回滚策略

L1:技能系统——把「会做的事」变成「可调用的能力」

1.1 什么是技能

技能 = Markdown 文档 + 可选脚本/模板,放在 ~/.hermes/skills/<category>/<name>/

结构:

skills/
└── my-skill/
    ├── SKILL.md          # 必需:YAML frontmatter + 说明
    ├── scripts/          # 可选:Python/Shell 脚本
    ├── templates/        # 可选:模板文件
    └── references/       # 可选:参考资料

1.2 官方技能库(开箱即用)

# 查看已安装技能
hermes skills list

# 加载技能(会话内临时)
skill_view(name="github-pr-workflow")

# 或在对话中直接说「用 github-pr-workflow 技能帮我 review PR」

新手必装 5 个

技能 用途
github-pr-workflow PR 全流程:分支、提交、CI、合并
hugo-dual-deploy Hugo 双端部署
systematic-debugging 4 阶段根因调试法
plan 任务规划:写计划再执行
hermes-agent-skill-authoring 自己写技能

1.3 实战:把「每日日记写→构建→部署」做成技能

创建 ~/.hermes/skills/productivity/daily-blog-deploy/SKILL.md

---
name: daily-blog-deploy
description: "每日日记:从模板生成 → hugo 构建 → wrangler 部署 → 验证"
category: productivity
tags: [hugo, cloudflare, automation, blog]
---
# Daily Blog Deploy 技能

## 触发条件
- 用户说「发今日日记」或「deploy today's diary」

## 执行步骤
1. **生成文章**:从模板创建 `content/posts/diary-YYYY-MM-DD-xxx.md`
2. **配图**:复制/生成 `static/images/diary_cover.svg`
3. **构建**`hugo --buildFuture`
4. **部署**`wrangler pages deploy public --project-name=ningop-blog --branch=main`
5. **验证**:curl pages.dev + ningop.com 双域名 200 检查

## 模板
`templates/diary_template.md`

## 脚本
`scripts/deploy.py`(含重试、日志、通知)

避坑:技能里写死路径会在别人机器上挂。用环境变量或相对路径,或在 SKILL.md 里明确「需用户先配置 BLOG_ROOT」。


L2:Cron 定时任务——让 Agent 自己干活

2.1 核心概念

Cron 任务 = Prompt + Schedule + 可选 Skills + Delivery Target

每次触发都是全新会话,无上下文记忆,所以 Prompt 必须自包含

2.2 创建方式

# 交互式创建(推荐新手)
hermes cron create

# 或 CLI 一行
hermes cron create \
  --name "daily-morning-brief" \
  --schedule "0 7 * * *" \
  --prompt "生成今日早报:抓取 GitHub Trending + Hacker News 前 5,用中文摘要发 Telegram" \
  --skills "web-search,github-trending" \
  --deliver "telegram"

2.3 实战:每日自动发日记

hermes cron create \
  --name "auto-daily-diary" \
  --schedule "0 22 * * *" \
  --prompt "
今晚 22:00 自动生成今日日记并部署:

1. 主题:今日完成的 3 件核心事 + 1 个洞察 + 1 个待改进
2. 文件:content/posts/diary-$(date +%F)-auto.md
3. 图片:static/images/diary_cover.svg(复用模板)
4. 命令:
   hugo --buildFuture
   wrangler pages deploy public --project-name=ningop-blog --branch=main
5. 验证:curl https://ningop.com/posts/diary-$(date +%F)-auto/ 必须 200
6. 结果发 Telegram:成功/失败 + 耗时 + 链接

如构建失败,把错误日志完整发给我。
" \
  --skills "hugo-dual-deploy" \
  --deliver "telegram"

2.4 管理命令

hermes cron list          # 列出所有
hermes cron run <id>      # 立即执行一次(测试用)
hermes cron pause <id>    # 暂停
hermes cron resume <id>   # 恢复
hermes cron remove <id>   # 删除

避坑

  • schedule服务器时区(通常是 UTC)。北京 7 点 = UTC 23:00 前一天 → 0 23 * * *
  • deliver: "telegram" 发到配置的 Home Channel;要发给自己私聊要用 deliver: "origin"
  • Cron 里不要递归创建新 Cron(会炸)

L3:多 Agent 编排——把大象拆成蚂蚁搬

3.1 核心概念

delegate_task = 并行启动多个隔离子 Agent,各自有独立终端、上下文、工具集。

  • Leaf(默认):干活的,不能再分发
  • Orchestrator:可再分发(需配置 max_spawn_depth > 1

3.2 实战:代码审查流水线

# 伪代码:在主 Agent 里调用
delegate_task(tasks=[
  {
    "goal": "安全扫描:跑 bandit + semgrep,输出高危列表",
    "toolsets": ["terminal", "file"],
    "context": "repo: /root/my-project, branch: feature/xyz"
  },
  {
    "goal": "单元测试:跑 pytest -x -q,输出失败用例",
    "toolsets": ["terminal"],
    "context": "repo: /root/my-project"
  },
  {
    "goal": "代码风格:跑 ruff + black --check,输出 diff",
    "toolsets": ["terminal"],
    "context": "repo: /root/my-project"
  }
])
# 等 3 个并行跑完,主 Agent 汇总生成审查报告

3.3 实战:博客选题→大纲→正文→配图→部署

# 一条指令拆 5 个子任务并行
hermes delegate "写一篇《RAG 实战避坑》并部署" \
  --tasks "
  1. 选题调研:搜 RAG 2024 最新论文/博客,提取 10 个核心避坑点
  2. 大纲生成:按『现象-原因-方案-代码』结构产出大纲
  3. 正文写作:按大纲写 3000 字实操文章,含代码块
  4. 配图生成:用 picsum 生成 1600x900 封面
  5. 部署验证:hugo + wrangler + curl 双域名检查
  "

避坑

  • 子 Agent 无记忆无 Memory 工具无 Clarify —— 全部上下文必须塞进 context
  • 并发上限受 delegation.max_concurrent_children 限制(默认 3)
  • 子 Agent 结果是「自述」,必须二次验证(curl、cat 文件、检查 exit code)

L4:外部集成——把 Agent 接进真实系统

4.1 GitHub 集成(必配)

# 1. 配置 PAT(Settings → Developer settings → Personal access tokens)
# 权限:repo, workflow, read:org, admin:repo_hook

# 2. 登录 gh
gh auth login --with-token < token.txt

# 3. Hermes 里用 github-* 技能
skill_view(name="github-pr-workflow")
skill_view(name="github-code-review")
skill_view(name="github-issues")

4.2 Cloudflare 集成(部署用)

# 1. 创建 API Token
# Dashboard → My Profile → API Tokens → Create Token
# 权限:Account → Cloudflare Pages → Edit
#       Zone → Zone → Read(可选,自定义域名用)

# 2. 设为环境变量或 wrangler config
export CLOUDFLARE_API_TOKEN=cfut_xxx
export CLOUDFLARE_ACCOUNT_ID=xxx

# 3. 验证
wrangler whoami
wrangler pages deploy public --project-name=my-blog

4.3 Telegram / Discord 通知

# Telegram:在 Hermes 设置里连好 Bot
# Discord:同理

# Cron 里 deliver: "telegram" 或 "discord"
# 代码里用 send_message 工具
send_message(target="telegram", message="🚀 部署完成: https://ningop.com/posts/xxx/")

L5:生产级部署——博客自动化全流程

5.1 完整流程图

┌─────────────┐     ┌─────────────┐     ┌─────────────┐     ┌─────────────┐
│  选题/触发   │ ──→ │  生成文章    │ ──→ │  本地构建    │ ──→ │  部署验证    │
│  (Cron/手动) │     │  (模板+AI)   │     │  (hugo)      │     │  (wrangler)  │
└─────────────┘     └─────────────┘     └─────────────┘     └─────────────┘
                           │                   │                   │
                           ▼                   ▼                   ▼
                    ┌─────────────┐     ┌─────────────┐     ┌─────────────┐
                    │  配图/本地化 │     │  语法/链接检查 │     │  双域名 200  │
                    │  (scripts)   │     │  (scripts)   │     │  + 通知     │
                    └─────────────┘     └─────────────┘     └─────────────┘

5.2 关键脚本:scripts/auto_deploy.py

#!/usr/bin/env python3
"""自动化部署:生成 → 构建 → 部署 → 验证 → 通知"""
import subprocess, sys, time, os
from datetime import datetime

BLOG_ROOT = os.getenv("BLOG_ROOT", "/root/ningfeiyu.github.io")
PROJECT = "ningop-blog"
DOMAINS = ["https://ningop.com", "https://www.ningop.com"]

def run(cmd, cwd=BLOG_ROOT):
    r = subprocess.run(cmd, shell=True, cwd=cwd, capture_output=True, text=True)
    if r.returncode != 0:
        print(f"❌ {cmd}\n{r.stderr}")
        return False, r.stderr
    return True, r.stdout

def main():
    slug = sys.argv[1] if len(sys.argv) > 1 else f"diary-{datetime.now():%Y-%m-%d}-auto"
    
    # 1. 生成文章(简化:假设已存在)
    print(f"📝 文章: {slug}")
    
    # 2. 构建
    ok, out = run("hugo --buildFuture")
    if not ok: return 1
    print("✅ 构建完成")
    
    # 3. 部署
    ok, out = run(f"wrangler pages deploy public --project-name={PROJECT} --branch=main")
    if not ok: return 1
    print("✅ 部署完成")
    
    # 4. 等待传播
    time.sleep(10)
    
    # 5. 验证
    url = f"https://ningop.com/posts/{slug}/"
    ok, _ = run(f"curl -sI -o /dev/null -w '%{{http_code}}' {url}")
    if ok and "200" in out:
        print(f"✅ 验证通过: {url}")
    else:
        print(f"❌ 验证失败: {url} -> {out}")
        return 1
    
    # 6. 通知
    msg = f"🚀 部署成功\n{url}\n耗时: {time.time()-start:.1f}s"
    run(f'hermes send telegram "{msg}"')  # 伪代码
    return 0

if __name__ == "__main__":
    start = time.time()
    sys.exit(main())

5.3 回滚策略

# 1. Git 回滚 + 重新部署(最稳)
git revert HEAD
git push
# GitHub Actions / 手动触发重新部署

# 2. Cloudflare Pages 回滚
# Dashboard → Pages → 项目 → Deployments → 选旧版本 → Promote to production

# 3. Wrangler 回滚
wrangler pages deployment list --project-name=ningop-blog
wrangler pages deployment promote <deployment-id> --project-name=ningop-blog

5.4 监控告警(最小可行)

# Cron 每 10 分钟巡检
hermes cron create \
  --name "blog-health-check" \
  --schedule "*/10 * * * *" \
  --prompt "
检查 https://ningop.com/ 和 https://ningop.com/posts/latest/ 
必须 200 OK,否则发 Telegram 告警。
" \
  --deliver "telegram"

避坑总结速查表

场景 解法
Cron 不触发 时区不对(服务器 UTC) 北京 7 点 = 0 23 * * *
Cron 发不到 Telegram deliver 写错 origin 发回当前会话,或 telegram 发 Home
技能加载不生效 名字/路径大小写 skill_view(name="xxx") 区分大小写
子 Agent 结果不可信 只信 必须二次验证:curl、cat、exit code
Worker 401 设了 WORKER_API_KEY 但值不对 删掉或改用 Cloudflare Access
Hugo 不显示新文 日期写未来/过去错 date: 2026-06-22 + buildFuture = true
图片 404 路径没加 /images/ Markdown 里写 /images/xxx.jpg

进阶后的「日常最小动作集」

频率 动作 命令/触发
每天早 7 点 早报自动发 Cron 自动
每晚 22 点 日记自动生成部署 Cron 自动
有新想法 hermes chat 说「发篇关于 X 的文章」 手动触发技能
代码改动 git push → GitHub Actions 自动部署 Push 触发
发现 Bug hermes delegate "修复 X" --tasks "..." 手动编排
想复盘 hermes session search "部署失败" 会话检索

结语:从「用工具」到「造流水线」

Hermes 的核心价值不在「聊天更聪明」,而在:

  1. 技能 = 可复用的最佳实践模块
  2. Cron = 持久化的自动化执行器
  3. Delegate = 复杂任务的并行拆解器
  4. 集成 = 接入真实生产环境的连接器

新手建议:别一次全学。选 一个痛点(如「每天手动发日记烦」),用 Cron + 技能 + 脚本跑通。跑通一个,再加第二个。

把「会做的事」变成「自动发生的事」,才是 Agent 该有的样子。


参考资源

  • 官方文档:https://hermes-agent.nousresearch.com/docs
  • 技能库:~/.hermes/skills/ / hermes skills list
  • 示例项目:github.com/nousresearch/hermes-agent
  • 我的博客自动化源码:https://github.com/ningfeiyu/ningfeiyu.github.io