第十二册:高阶玩法与实战案例

本章你将学到

  • 从入门到高阶的完整进阶路线图,明确你当前所处的阶段和下一步方向
  • Hermes 沙箱环境的安全分级配置,让 Agent 既能干活又不会"闯祸"
  • 语音交互的高级玩法,包括 STT/TTS 配置、多语言支持和语音触发工作流
  • 六个完整的实战案例:AI 投研流水线、内容自动化工厂、代码质量守护者、个人知识管理系统、智能客服机器人、数据监控与告警
  • 企业级应用场景的部署方案和安全合规考量
  • 八大高阶技巧:模型热切换、记忆压缩、技能链式调用、并行任务加速等

预计阅读时间:120-150 分钟

建议准备:一台已安装 Hermes 的电脑(参考第五册)、一个可用的 API Key(OpenAI/Anthropic/DeepSeek 均可)


1. 高阶玩法总览

1.1 从入门到高阶的进阶路线图

恭喜你,如果你正在阅读这一章,说明你已经完成了 Hermes 的基础学习——安装、配置、对话、基础技能使用都已经不在话下。现在,是时候把 Hermes 从"玩具"升级为"生产力工具"了。

让我先给你画一张进阶路线图,帮你定位自己当前的位置。

第一阶段:新手村(已完成)

  • 成功安装并运行 Hermes
  • 能进行基础对话和简单任务
  • 了解记忆系统和技能系统的基本概念
  • 接入至少一个大模型(OpenAI/Anthropic/本地模型)

第二阶段:熟练工(当前阶段)

  • 掌握沙箱安全配置,敢于让 Agent 执行系统命令
  • 学会语音交互配置,实现"动口不动手"
  • 能够搭建第一个自动化工作流(如定时日报)
  • 熟悉 MCP 协议,能接入外部工具服务
  • 掌握多平台接入(Telegram/飞书/微信等)

第三阶段:高阶玩家

  • 搭建完整的 Multi-Agent 系统
  • 实现复杂的业务自动化流水线
  • 自定义工具开发和技能链式调用
  • 性能优化和成本控制的精细调优
  • 企业级部署和安全合规配置

第四阶段:大师级

  • 为社区贡献高质量技能插件
  • 参与核心代码开发和架构设计
  • 基于 Hermes 构建商业产品或服务
  • 指导和培训其他用户

类比

把学 Hermes 比作学做菜。第一阶段是你刚学会用燃气灶和基本刀工;第二阶段是你能炒几个家常菜了;第三阶段是你能招待一桌客人,冷热搭配、荤素均衡;第四阶段是你能开餐厅、创新菜品、带徒弟。本章的目标,是带你从"家常菜"迈向"宴席级别"。

1.2 高阶玩家的典型工作流

高阶玩家使用 Hermes 的方式,和新手有着本质的不同。让我用一个典型的高阶玩家一天来给你展示。

早上 8:00 —— 自动日报推送

Hermes 的 Cron 任务准时触发。它已经完成了以下工作:

  • 从 Hacker News、GitHub Trending、Twitter 抓取了昨晚的 AI 行业热点
  • 用数据清洗 Agent 过滤了噪声信息
  • 用分析 Agent 提炼了关键趋势
  • 生成了一份格式化的 Markdown 报告
  • 通过 Telegram Bot 推送到了你的手机

你睁开眼睛,拿起手机就能看到 curated 好的行业动态。

上午 10:00 —— 语音启动投研任务

你对着手机说:"Hermes,帮我分析一下今天加密货币市场的走势,重点关注以太坊和 Solana。"

Hermes 接收到语音指令,转换为文本,触发预定义的投资研究工作流:

  • 调用价格监控工具获取实时数据
  • 读取过去 7 天的历史数据
  • 分析链上指标(交易量、活跃地址数)
  • 检索记忆中的投资策略和风险管理规则
  • 生成一份简短的投资建议报告

整个过程你不需要打字,也不需要盯着屏幕。

下午 2:00 —— 代码审查自动化

你提交了一个 Pull Request 到公司的代码仓库。Hermes 的 Git Hook 自动触发:

  • 读取 PR 中的代码变更
  • 进行静态分析和安全扫描
  • 检查代码风格是否符合团队规范
  • 生成审查报告,标注潜在问题和改进建议
  • 在 PR 下方自动发布评论

晚上 7:00 —— 内容自动发布

你运营着几个自媒体账号。Hermes 的内容自动化工厂在后台运行:

  • 选题 Agent 从热点追踪中筛选出适合的话题
  • 写作 Agent 生成了 5 篇不同风格的 AI 快讯
  • 审校 Agent 检查了事实准确性和表达流畅度
  • 格式化 Agent 为不同平台(公众号、小红书、抖音)生成了适配版本
  • 定时发布 Agent 按照最优时间推送到了各个平台

晚上 10:00 —— 知识归档

你今天浏览了很多文章和论文。Hermes 的知识管理系统:

  • 自动提取了你收藏的 RSS 文章的关键信息
  • 对内容进行了智能分类和标签化
  • 更新了个人知识图谱
  • 将相关内容关联到了你之前的笔记
  • 为明天的"每日回顾"准备了摘要

这就是高阶玩家的 Hermes —— 不是你在"用"它,而是它在"为你工作"。

Tips

不要被这个"理想化"的一天吓到。这些功能不是一天就能搭好的。高阶玩家的 Hermes 也是从小自动化开始,逐步叠加功能,最终形成一个完整的生态。本章的目的,就是手把手教你搭建这些系统。

1.3 本章实战案例的阅读方法

本章包含六个大型实战案例,每个案例都是一个完整的系统。为了让你最高效地学习,我建议以下阅读策略:

策略一:先通读,再精修

不要一开始就试图把某个案例的每行代码都搞懂。先快速浏览整个案例的架构和流程,理解"它做了什么"和"为什么这么做"。等你有了全局视角,再深入到具体配置和代码。

策略二:挑一个最感兴趣的先做

六个案例覆盖了不同领域:投研、内容创作、代码审查、知识管理、客服、数据监控。选择你最感兴趣或者最急需的那个,按照步骤完整搭建一遍。完成一个案例带来的成就感,会激励你继续做下一个。

策略三:从最小可用版本(MVP)开始

每个案例我都提供了"完整版"配置,但完整版可能涉及很多组件。我建议你先搭建一个最小可用版本——只保留核心功能,去掉锦上添花的功能。等 MVP 跑通了,再逐步添加高级功能。

策略四:边做边改

案例中的配置是"通用版",不一定完全适合你的需求。边做边根据自己的实际情况调整参数、修改逻辑、增减功能。最好的学习就是在实践中迭代。

注意

本章的所有案例都涉及外部服务(API、平台、数据库等)。在执行之前,请确保你已经阅读了每个案例的"前置准备"部分,并准备好了所需的 API Key 和账号。不要为了省事跳过安全设置——生产环境中一个配置错误可能导致数据泄露或财产损失。


2. 沙箱配置与安全调优

2.1 执行环境的安全分级

在让 Hermes 执行系统命令或运行代码之前,安全是你必须考虑的第一件事。想象一下,如果你的 Agent 不小心执行了 rm -rf /,或者运行了一个包含恶意代码的脚本,后果会怎样?

Hermes 的沙箱系统就是为了解决这个问题而设计的。它把代码执行环境分为四个安全等级,就像一个军营有不同的安全区域:

安全等级名称权限范围适用场景
Level 0完全隔离只读文件系统,禁止网络访问运行完全不可信的代码
Level 1受限执行可读写临时目录,限制网络访问运行来源不明的脚本
Level 2标准沙箱可读写工作目录,允许外部网络日常任务执行
Level 3信任模式完整系统访问,无限制自己编写的可信代码

类比

安全等级就像机场的安检级别。Level 0 是最高级别——你要脱鞋、解皮带、全身扫描,什么东西都不能带。Level 3 就是 VIP 通道——快速通过,基本不检查。不同的航班(任务)需要不同的安检级别。

2.2 沙箱(Sandbox)配置详解

Hermes 的沙箱基于 Docker 容器和系统级隔离技术实现。下面是详细的配置方法。

基础配置(在 config.yaml 中)

# ============================================
# 沙箱安全配置文件 - config.yaml
# ============================================
 
sandbox:
  # 默认安全等级:所有未明确指定的任务使用此等级
  default_level: 2
 
  # Docker 镜像配置
  docker:
    # 基础镜像,包含 Python、Node.js、常用工具
    image: "hermes/sandbox:latest"
    # 是否自动拉取最新镜像
    auto_pull: true
    # 容器资源限制
    resources:
      # CPU 核心数限制
      cpus: 2.0
      # 内存限制(MB)
      memory: 1024
      # 临时存储限制(MB)
      disk: 512
 
  # 网络访问控制
  network:
    # 是否允许容器访问外部网络
    enabled: true
    # 允许访问的域名白名单(为空表示允许所有)
    allowed_hosts:
      - "api.openai.com"
      - "api.anthropic.com"
      - "github.com"
      - "registry.npmjs.org"
    # 禁止访问的域名黑名单
    blocked_hosts:
      - "localhost"
      - "127.0.0.1"
      - "0.0.0.0"
 
  # 文件系统权限
  filesystem:
    # 只读目录(容器内无法修改)
    read_only:
      - "/app/templates"
      - "/app/config"
    # 可读写目录
    read_write:
      - "/app/workspace"
      - "/tmp"
    # 禁止访问的路径
    forbidden:
      - "/etc/passwd"
      - "/etc/shadow"
      - "/root/.ssh"
      - "~/.aws"
 
  # 命令执行超时(秒)
  timeout: 300
 
  # 环境变量隔离
  env_isolation: true

按任务类型设置安全等级

你可以在 Skill 或工作流配置中为特定任务指定安全等级:

# skills/web_search.yaml
name: "web_search"
description: "执行网络搜索"
 
# 此技能只需要访问外部网络,不需要本地文件操作
sandbox:
  level: 2
  network:
    enabled: true
  filesystem:
    read_write:
      - "/tmp/search_results"
 
---
# skills/code_execution.yaml
name: "code_execution"
description: "执行用户提供的代码"
 
# 用户代码不可信,使用严格隔离
sandbox:
  level: 0
  docker:
    resources:
      cpus: 1.0
      memory: 512
      disk: 256
  timeout: 60

Tips

一个实用的经验法则:凡是涉及用户输入的代码执行,都至少用 Level 1;完全不可信的来源用 Level 0;你自己写的自动化脚本可以用 Level 3。 宁可在安全上过度配置,也不要为了方便留下隐患。

2.3 命令审批机制的自定义

Hermes 有一个非常重要的安全功能:命令审批(Command Approval)。当 Agent 要执行某些敏感操作时,会先暂停并征求你的确认。

配置审批规则

# config.yaml 中的审批配置
approval:
  # 全局开关
  enabled: true
 
  # 审批模式:manual(手动)/ auto(自动)/ conditional(条件)
  mode: "conditional"
 
  # 条件审批规则
  rules:
    # 规则1:文件删除操作必须审批
    - name: "file_deletion"
      pattern: "rm\\s+-[rf]*\\s+.*"
      action: "require_approval"
      message: "⚠️ 检测到文件删除命令,请确认是否执行:{command}"
 
    # 规则2:系统级命令必须审批
    - name: "system_commands"
      pattern: "(sudo|chmod|chown|mkfs|fdisk)\\s+.*"
      action: "require_approval"
      message: "⚠️ 检测到系统级命令,需要管理员权限,请确认:{command}"
 
    # 规则3:网络请求自动通过(在允许域名内)
    - name: "network_requests"
      pattern: "(curl|wget|fetch)\\s+.*"
      action: "auto_approve"
      condition: "host_in_whitelist"
 
    # 规则4:数据库操作必须审批
    - name: "database_ops"
      pattern: "(DROP|DELETE|TRUNCATE|UPDATE)\\s+.*"
      action: "require_approval"
      message: "⚠️ 检测到数据修改命令,请确认:{command}"
 
    # 规则5:大规模文件操作提醒
    - name: "bulk_operations"
      pattern: "find\\s+.*-delete|rm\\s+-rf\\s+/.*"
      action: "block"
      message: "🚫 危险命令已拦截:{command}"

审批通知方式

approval:
  # 通知渠道配置
  notifications:
    # 终端交互式审批(默认)
    - channel: "terminal"
      enabled: true
      timeout: 60 # 等待用户输入的超时时间(秒)
 
    # Telegram 审批(适合远程/无人值守场景)
    - channel: "telegram"
      enabled: true
      bot_token: "${TELEGRAM_BOT_TOKEN}"
      chat_id: "${TELEGRAM_CHAT_ID}"
      timeout: 300 # 给用户更多时间响应
 
    # 邮件审批(适合企业环境)
    - channel: "email"
      enabled: false
      smtp_server: "smtp.gmail.com"
      to: "[email protected]"
      timeout: 3600

注意

如果你把 Hermes 部署在服务器上并启用了 Web 界面或第三方平台接入,务必配置 Telegram 或邮件审批。否则当 Agent 需要审批时,你会在终端看不到提示,任务就会一直卡住。

2.4 信任级别设置

Hermes 允许你为不同的 Skill、工具或工作流设置信任级别,实现更细粒度的安全控制。

# trust_levels.yaml
# 信任级别配置文件
 
trust_levels:
  # 内置工具和官方 Skill —— 完全信任
  builtin:
    sources:
      - "hermes.builtin.*"
      - "hermes.official.*"
    permissions:
      sandbox_level: 3
      auto_approve: true
      network_access: true
 
  # 社区贡献的 Skill —— 有限信任
  community:
    sources:
      - "hermes.community.*"
    permissions:
      sandbox_level: 1
      auto_approve: false
      network_access: true
      filesystem:
        read_only:
          - "/app/data"
        read_write:
          - "/tmp"
 
  # 用户自己编写的 Skill —— 根据用户选择
  user:
    sources:
      - "user.*"
    permissions:
      sandbox_level: 2 # 默认标准沙箱
      auto_approve: false
      network_access: true
 
  # 从未知来源安装的 Skill —— 最高警惕
  untrusted:
    sources:
      - "*"
    permissions:
      sandbox_level: 0
      auto_approve: false
      network_access: false
      filesystem:
        read_only: []
        read_write:
          - "/tmp/isolated"

2.5 生产环境安全清单

在将 Hermes 部署到生产环境之前,请逐一检查以下清单:

# Hermes 生产环境安全清单
 
## 沙箱配置
 
- [ ] 默认安全等级不超过 Level 2
- [ ] 容器资源限制已配置(CPU、内存、磁盘)
- [ ] 网络白名单已配置,仅允许必要的域名
- [ ] 文件系统禁止访问敏感路径(SSH 密钥、密码文件等)
 
## 审批机制
 
- [ ] 命令审批已启用
- [ ] 危险的系统命令(rm -rf、sudo 等)需要审批
- [ ] 数据库 DROP/DELETE 操作需要审批
- [ ] 审批通知渠道已配置且可正常接收
 
## 访问控制
 
- [ ] API Key 存储在环境变量中,不在配置文件里写明文
- [ ] SSH 密钥、密码等凭证不在代码仓库中
- [ ] `.env` 文件已加入 `.gitignore`
- [ ] 如使用 Docker,容器以非 root 用户运行
 
## 网络安全
 
- [ ] 防火墙规则已配置,仅开放必要端口
- [ ] HTTPS 已启用(如暴露 Web 接口)
- [ ] 反爬虫/速率限制已配置
- [ ] 日志中不包含敏感信息(API Key、密码等)
 
## 监控与告警
 
- [ ] 异常执行行为监控已启用
- [ ] 沙箱逃逸尝试告警已配置
- [ ] 资源使用监控已配置(防止资源耗尽攻击)

2.6 案例:安全地运行未知代码

假设你收到了一段别人发来的 Python 脚本,说是可以帮你"自动整理桌面文件"。你想让 Hermes 运行它,但又担心有安全隐患。这时候应该怎么做?

步骤1:创建隔离沙箱配置

# isolated_run.yaml
name: "safe_execution"
description: "安全执行未知来源代码"
 
sandbox:
  level: 0 # 最高隔离级别
  docker:
    image: "hermes/sandbox:minimal"
    resources:
      cpus: 0.5
      memory: 256
      disk: 100
  network:
    enabled: false # 完全断网
  filesystem:
    read_only:
      - "/app/code" # 只读挂载待执行的代码
    read_write:
      - "/tmp/output" # 只允许写到临时目录
  timeout: 30 # 30秒超时

步骤2:使用 Hermes CLI 安全执行

# 将未知代码放入隔离目录
mkdir -p ./isolated_run
cp unknown_script.py ./isolated_run/
 
# 使用 Hermes 的隔离执行命令
$ hermes exec --sandbox isolated_run.yaml --file ./isolated_run/unknown_script.py
 
# 查看执行结果(只能从指定输出目录读取)
cat ./isolated_run/output/result.json

步骤3:分析代码行为(不执行)

如果你连隔离执行都不放心,可以让 Hermes 先静态分析代码:

# 让 Hermes 分析代码的功能和潜在风险
$ hermes analyze --file unknown_script.py --depth detailed
 
# 预期输出示例:
# [ANALYSIS] 检测到以下行为:
# - 文件读取操作:读取 ~/Desktop 目录
# - 文件写入操作:在 ~/Desktop 创建整理后的文件夹
# - 网络操作:无
# - 系统调用:无
# - 风险评级:低(仅操作桌面文件,无敏感路径访问)

Tips

对于任何来源不明的代码,养成"先分析、再隔离执行、最后才正常执行"的习惯。Hermes 的 analyze 命令会检查代码中的文件操作、网络请求、系统调用等行为,给你一个风险评级。这个习惯可能某天真会救你一命。


3. 语音交互高阶玩法

3.1 语音输入(STT)高级配置

语音输入(Speech-to-Text,简称 STT)让你可以用说话代替打字,跟 Hermes 交互。这对于双手忙碌的场景(开车、做饭、运动)特别有用。

Hermes 支持多种 STT 引擎,从完全免费的本地模型到高质量的云端 API。

支持的 STT 引擎

引擎类型质量延迟成本适用场景
Whisper (本地)本地中高中等免费日常对话、隐私敏感
Whisper API云端$0.006/分钟高质量要求
DeepSpeech本地免费资源受限设备
Google STT云端$0.024/分钟多语言支持
Azure STT云端$1.0/小时企业环境

基础配置

# config.yaml 中的 STT 配置
stt:
  # 默认引擎
  engine: "whisper_local"
 
  # 本地 Whisper 配置
  whisper_local:
    # 模型大小:tiny/base/small/medium/large
    # 越大越准,但也越慢、越吃资源
    model: "base"
    # 语言设置:auto 自动检测,或指定如 "zh", "en"
    language: "auto"
    # 设备:cpu / cuda(需要 NVIDIA 显卡)
    device: "cpu"
    # 是否翻译为英文(Whisper 特有功能)
    translate: false
 
  # Whisper API 配置
  whisper_api:
    api_key: "${OPENAI_API_KEY}"
    model: "whisper-1"
    language: "auto"
 
  # Google STT 配置
  google_stt:
    credentials_path: "${GOOGLE_CREDENTIALS_PATH}"
    language_code: "zh-CN"
    # 是否启用自动标点
    enable_automatic_punctuation: true
 
  # 音频输入设置
  audio:
    # 采样率
    sample_rate: 16000
    # 录音时长限制(秒)
    max_duration: 60
    # 静音检测阈值(用于自动停止录音)
    silence_threshold: 0.02
    # 静音持续多久自动停止(秒)
    silence_duration: 2.0

高级配置:语音活动检测(VAD)

VAD(Voice Activity Detection)让 Hermes 能够自动检测你什么时候开始说话、什么时候说完,不需要手动按"录音"按钮。

stt:
  # VAD 配置
  vad:
    enabled: true
    # VAD 引擎:webrtc / silero / energy
    engine: "silero"
 
    silero:
      # 模型路径(自动下载)
      model: "silero_vad"
      # 检测阈值(0-1,越高越严格)
      threshold: 0.5
      # 最小语音长度(毫秒)
      min_speech_duration_ms: 250
      # 最大语音长度(毫秒)
      max_speech_duration_s: 60
      # 语音前预留的静音(毫秒)
      speech_pad_ms: 100

唤醒词配置

你可以设置一个唤醒词(Wake Word),就像"Hey Siri"或"OK Google"一样。只有检测到唤醒词后,Hermes 才会开始录音和识别。

stt:
  wake_word:
    enabled: true
    # 唤醒词
    phrase: "嘿 Hermes"
    # 唤醒词引擎:porcupine / snowboy / custom
    engine: "porcupine"
    # 灵敏度(0-1)
    sensitivity: 0.7
    # 唤醒后的监听超时(秒)
    listen_timeout: 10

类比

唤醒词就像是办公室的敲门声。平时 Hermes 在"专注做自己的事"(不监听),只有听到"敲门声"(唤醒词),它才会抬头听你说话。这样既省电(不处理无意义的背景音),又保护隐私(不会误录你的私人对话)。

3.2 语音输出(TTS)高级配置

语音输出(Text-to-Speech,简称 TTS)让 Hermes 可以用说话的方式回复你,而不是显示文字。

支持的 TTS 引擎

引擎类型质量延迟成本特点
Piper本地中高免费开源、轻量、支持多种语言
Coqui TTS本地免费质量优秀,支持语音克隆
Edge TTS云端(免费)免费微软 Edge 浏览器同款
OpenAI TTS云端很高$0.015/1K字符音质极佳,多种声音
ElevenLabs云端顶级$0.18/1K字符最自然的语音

基础配置

# config.yaml 中的 TTS 配置
tts:
  # 默认引擎
  engine: "edge_tts"
 
  # Edge TTS 配置(免费)
  edge_tts:
    # 语音选择
    # 中文女声:zh-CN-XiaoxiaoNeural
    # 中文男声:zh-CN-YunjianNeural
    # 英文女声:en-US-JennyNeural
    voice: "zh-CN-XiaoxiaoNeural"
    # 语速:0.5-2.0
    rate: "+0%"
    # 音量
    volume: "+0%"
 
  # OpenAI TTS 配置
  openai_tts:
    api_key: "${OPENAI_API_KEY}"
    model: "tts-1" # tts-1(快)或 tts-1-hd(高质)
    voice: "alloy" # alloy/echo/fable/onyx/nova/shimmer
    speed: 1.0
 
  # Piper 本地 TTS 配置
  piper:
    model: "zh_CN-huayan-medium"
    # 语速
    length_scale: 1.0
    # 音调
    noise_scale: 0.667
 
  # 输出设置
  output:
    # 播放设备:auto / 设备名称
    device: "auto"
    # 是否自动播放
    auto_play: true
    # 缓存语音文件(避免重复生成)
    cache_enabled: true
    cache_dir: "./cache/tts"

流式 TTS 配置(降低延迟)

传统的 TTS 是"生成完整文本的语音,然后再播放",延迟较高。流式 TTS 可以在文本生成的过程中就开始合成和播放,实现"边想边说"的效果。

tts:
  # 流式输出配置
  streaming:
    enabled: true
    # 句子分隔符(遇到这些符号就切分并合成)
    sentence_delimiters: ".。!!??;;\n"
    # 最小句子长度(字符数)
    min_sentence_length: 10
    # 最大缓冲区(句子数)
    max_buffer_size: 3
    # 是否启用打断(用户说话时停止播放)
    allow_barge_in: true

Tips

如果你追求"极致自然"的语音体验,推荐 OpenAI TTS 的 tts-1-hd 模型配合 shimmer 声音。如果你追求"免费且好用",Edge TTS 是最好的选择——它和微软 Edge 浏览器的"大声朗读"功能用的是同一个引擎,质量相当高。如果你需要完全离线运行(比如车载场景),Piper 或 Coqui TTS 是首选。

3.3 多语言语音支持

Hermes 的语音系统支持多种语言的输入和输出,你可以根据场景灵活切换。

# 多语言语音配置
stt:
  # 默认语言
  default_language: "zh"
 
  # 语言切换命令(说出这些词可以临时切换语言)
  language_switch:
    enabled: true
    commands:
      "说中文": "zh"
      "说英语": "en"
      "说日语": "ja"
    # 切换后的持续时间(秒),0 表示永久切换
    duration: 0
 
  # 自动语言检测
  auto_detect:
    enabled: true
    # 可能检测到的语言列表
    languages:
      - "zh"
      - "en"
      - "ja"
      - "ko"
 
tts:
  # 按语言配置不同的 TTS 引擎和声音
  language_mapping:
    zh:
      engine: "edge_tts"
      voice: "zh-CN-XiaoxiaoNeural"
    en:
      engine: "edge_tts"
      voice: "en-US-JennyNeural"
    ja:
      engine: "edge_tts"
      voice: "ja-JP-NanamiNeural"
    # 自动检测语言后,使用对应的声音
    auto_switch: true

3.4 语音触发工作流

语音不只是用来聊天的,还可以用来触发复杂的工作流。比如你说"开始晨间例行",Hermes 就自动执行一系列任务。

# workflows/voice_triggered.yaml
name: "voice_workflows"
description: "语音触发的工作流配置"
 
voice_triggers:
  # 触发词1:晨间例行
  - trigger: "开始晨间例行"
    workflow: "morning_routine"
    description: "执行晨间信息收集和汇报"
 
  # 触发词2:投研分析
  - trigger: "帮我分析市场"
    workflow: "market_analysis"
    description: "触发投资研究工作流"
 
  # 触发词3:代码审查
  - trigger: "审查这段代码"
    workflow: "code_review"
    description: "对最近的代码提交进行审查"
 
  # 触发词4:紧急暂停
  - trigger: "停止所有任务"
    action: "pause_all"
    description: "立即停止所有正在执行的任务"
 
  # 触发词5:状态查询
  - trigger: "你在忙什么"
    action: "status_report"
    description: "语音汇报当前任务状态"
 
# 晨间例行的具体工作流
workflows:
  morning_routine:
    steps:
      - action: "fetch_weather"
        params:
          location: "current"
      - action: "fetch_news"
        params:
          sources: ["hacker_news", "github_trending"]
          count: 10
      - action: "check_calendar"
        params:
          period: "today"
      - action: "generate_report"
        template: "morning_brief"
      - action: "tts_speak"
        text: "{{report.summary}}"

3.5 车载/穿戴设备场景

Hermes 的语音交互在车载和穿戴设备场景中有特别的优势——这些场景下打字几乎不可能,语音是唯一的交互方式。

车载场景配置

# 车载场景专用配置
car_mode:
  enabled: true
 
  # 蓝牙音频输入/输出
  bluetooth:
    device_name: "Car Audio"
    auto_connect: true
 
  # 车载场景优化
  optimizations:
    # 降低响应延迟(牺牲部分质量)
    fast_response: true
    # 简化回复(避免长篇大论)
    concise_mode: true
    # 大声朗读(适合车内噪音环境)
    high_volume: true
    # 优先使用本地模型(避免网络不稳定)
    offline_priority: true
 
  # 车载专用语音指令
  voice_commands:
    - "导航到{{目的地}}" -> action: "navigation"
    - "播放{{音乐}}" -> action: "music_control"
    - "打电话给{{联系人}}" -> action: "call"
    - "发送语音消息给{{联系人}}" -> action: "voice_message"
    - "汇报路况" -> action: "traffic_report"

穿戴设备场景配置

# 穿戴设备专用配置
wearable_mode:
  enabled: true
 
  # 资源受限设备优化
  resource_optimization:
    # 使用最小的 Whisper 模型
    stt_model: "tiny"
    # 禁用流式 TTS(节省电量)
    streaming: false
    # 缩短最大录音时长
    max_recording: 15
    # 降低 TTS 音质(节省电量和带宽)
    tts_quality: "low"
 
  # 电池管理
  battery:
    # 低电量模式阈值
    low_threshold: 20
    # 低电量时自动降低功能
    low_power_mode:
      disable_tts: true
      disable_background_tasks: true
      reduce_stt_quality: true

注意

在车载场景中使用 Hermes,安全永远是第一位的。确保语音交互不会分散你的驾驶注意力。建议把所有回复都设置为"一句话总结"模式,复杂信息等你停车后再查看。不要在驾驶过程中让 Hermes 执行需要审批的操作——你没法在开车时看屏幕确认。

3.6 案例:纯语音驱动的投研助手

这个案例展示如何搭建一个完全通过语音交互的投资研究助手。你可以在开车、健身、做饭的时候,用语音获取市场分析和投资建议。

系统架构

语音输入 → STT(Whisper) → 意图识别 → 工作流路由 → 数据处理 → TTS(OpenAI) → 语音输出

完整配置

# configs/voice_investment_assistant.yaml
name: "voice_investment_assistant"
description: "纯语音驱动的投资研究助手"
 
# STT 配置:快速响应优先
stt:
  engine: "whisper_api"
  whisper_api:
    api_key: "${OPENAI_API_KEY}"
    model: "whisper-1"
  # 启用 VAD,实现免提交互
  vad:
    enabled: true
    engine: "silero"
  # 唤醒词
  wake_word:
    enabled: true
    phrase: "小赫"
    sensitivity: 0.8
 
# TTS 配置:高质量语音输出
tts:
  engine: "openai_tts"
  openai_tts:
    api_key: "${OPENAI_API_KEY}"
    model: "tts-1-hd"
    voice: "nova"
  streaming:
    enabled: true
    allow_barge_in: true
 
# 投资研究工作流
workflows:
  investment_assistant:
    # 意图识别配置
    intent_detection:
      model: "gpt-4o-mini"
      intents:
        - name: "price_query"
          examples:
            - "比特币现在多少钱"
            - "以太坊价格"
            - "BTC 现价"
        - name: "market_analysis"
          examples:
            - "分析一下今天的市场"
            - "大盘怎么看"
            - "市场情绪如何"
        - name: "portfolio_review"
          examples:
            - "我的持仓怎么样"
            - "看看我的投资组合"
        - name: "alert_setup"
          examples:
            - "比特币涨到 7 万提醒我"
            - "设置价格提醒"
 
    # 各意图对应的处理流程
    handlers:
      price_query:
        - action: "fetch_crypto_price"
          symbols: "{{entities.symbols}}"
        - action: "format_price_response"
        - action: "tts_speak"
 
      market_analysis:
        - action: "fetch_market_data"
          timeframe: "1d"
        - action: "analyze_market_sentiment"
        - action: "generate_voice_report"
          max_length: "200字" # 语音不宜过长
        - action: "tts_speak"
 
      portfolio_review:
        - action: "read_portfolio"
        - action: "calculate_returns"
        - action: "tts_speak"
 
      alert_setup:
        - action: "create_price_alert"
          symbol: "{{entities.symbol}}"
          condition: "{{entities.condition}}"
          target: "{{entities.price}}"
        - action: "tts_speak"
          text: "好的,已经为您设置提醒。"
 
# 后台数据服务
data_sources:
  crypto_prices:
    provider: "coingecko"
    api_key: "${COINGECKO_API_KEY}"
    update_interval: 60 # 秒
 
  market_sentiment:
    provider: "alternative"
    indicators:
      - "fear_greed_index"
      - "btc_dominance"

使用示例对话

用户:"小赫"
Hermes:"我在,请说。"

用户:"比特币现在多少钱?"
Hermes:"比特币当前价格 67,432 美元,24 小时上涨 2.3%,交易量 285 亿美元。"

用户:"分析一下今天的市场"
Hermes:"今日市场整体偏乐观。恐惧贪婪指数 65,处于贪婪区间。比特币主导地位 52%,以太坊 Gas 费处于低位。主流币种普遍上涨,DeFi 板块表现突出。需要我详细分析某个板块吗?"

用户:"以太坊涨到 4000 提醒我"
Hermes:"好的,已经为您设置以太坊价格提醒,目标价 4000 美元。当前价格 3,521 美元,还需上涨 13.6%。"

Tips

纯语音交互有一个设计原则:回复要短,信息要密。想象一下你在听广播——如果主播说了一大段话,你很难记住所有内容。语音助手的回复最好控制在 100-200 字以内,一个回复只讲 1-2 个要点。复杂的信息用"分层汇报":先给摘要,用户问"详细说说"再给细节。


4. 实战案例:AI 投研流水线

4.1 需求分析:每日自动追踪 AI/Web3 热点

作为一个关注 AI 和 Web3 领域的投资者或研究人员,你每天早上都需要花 1-2 小时浏览各种信息源——Hacker News、GitHub Trending、Twitter、Reddit、技术博客……然后手动整理成一份可读性强的报告。

这个过程有几个痛点:

  1. 信息过载:每天产生的内容太多,你不可能全部看完
  2. 信息噪声:很多内容是重复、低质或不相关的
  3. 整理耗时:看完信息后,还需要花时间提炼要点、格式化
  4. 容易遗漏:手动浏览总有遗漏,可能错过重要信号
  5. 缺乏关联:单独看每条信息看不出趋势,需要跨源关联分析

解决方案:让 Hermes 搭建一条"投研流水线",每天自动完成信息收集、清洗、分析、报告生成和推送的全过程。

预期效果

  • 每天早上 8:00,你的 Telegram/飞书收到一份 curated 好的行业日报
  • 报告包含:热点摘要、趋势分析、关键数据、值得关注的项目
  • 每日运行成本约 $0.1-0.5(主要是 API 调用费用)
  • 你自己只需要花 5 分钟浏览报告,而不是 2 小时手动整理

4.2 整体架构设计(MCP + Cron + 多Agent)

这个系统采用多 Agent 协作架构,每个 Agent 负责一个环节,像流水线一样串联工作。

┌─────────────────────────────────────────────────────────────┐
│                    AI 投研流水线架构                          │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│   Cron 触发(每天 8:00)                                     │
│         │                                                   │
│         ▼                                                   │
│   ┌──────────────┐                                         │
│   │  数据收集 Agent │ ◄─── 多源并行抓取                       │
│   └──────┬───────┘                                         │
│          │ 原始数据                                         │
│          ▼                                                  │
│   ┌──────────────┐                                         │
│   │  数据清洗 Agent │ ──── 去重、过滤、格式化                  │
│   └──────┬───────┘                                         │
│          │ 清洗后数据                                       │
│          ▼                                                  │
│   ┌──────────────┐                                         │
│   │  分析 Agent   │ ──── 趋势提取、情感分析、关联挖掘          │
│   └──────┬───────┘                                         │
│          │ 分析结果                                         │
│          ▼                                                  │
│   ┌──────────────┐                                         │
│   │  报告生成 Agent│ ──── 格式化、图表、摘要                   │
│   └──────┬───────┘                                         │
│          │ 最终报告                                         │
│          ▼                                                  │
│   ┌──────────────┐                                         │
│   │  推送 Agent   │ ──── Telegram/飞书/邮件                  │
│   └──────────────┘                                         │
│                                                             │
└─────────────────────────────────────────────────────────────┘

为什么用多 Agent 而不是单个 Agent?

  1. 关注点分离:每个 Agent 只做好一件事,逻辑清晰,便于调试
  2. 并行优化:数据收集阶段可以同时抓取多个源
  3. 成本优化:不同环节可以用不同模型(收集用便宜模型,分析用强模型)
  4. 容错隔离:一个环节出问题不影响其他环节
  5. 可替换性:想换一个数据源?只改收集 Agent 就行

类比

多 Agent 流水线就像一家报社的编辑部。有记者(收集 Agent)去各地采访,有编辑(清洗 Agent)整理稿件,有评论员(分析 Agent)写深度分析,有排版员(报告生成 Agent)做成报纸,有发行员(推送 Agent)送到读者手中。每个人专精一项,效率最高。

4.3 数据源配置(Hacker News、GitHub Trending、Twitter/X、Reddit)

Hacker News 数据抓取

# data_sources/hacker_news.yaml
name: "hacker_news_source"
description: "从 Hacker News 抓取热门内容"
 
# 使用 Hermes 内置的 Web 搜索工具 + HN API
fetch:
  # Hacker News 官方 API(免费,无需 Key)
  - name: "top_stories"
    url: "https://hacker-news.firebaseio.com/v0/topstories.json"
    method: "GET"
    # 取前 30 条热帖的 ID
    parse: "json"
    limit: 30
 
  # 根据 ID 获取帖子详情
  - name: "story_details"
    url: "https://hacker-news.firebaseio.com/v0/item/{story_id}.json"
    method: "GET"
    # 从 top_stories 的结果中迭代获取
    iterate: "top_stories"
    # 只保留满足条件的帖子
    filter:
      - "score > 50" # 分数大于 50
      - "type == 'story'"
    fields:
      - "title"
      - "url"
      - "score"
      - "by" # 作者
      - "time"
      - "descendants" # 评论数
 
# 内容抓取(如果帖子是链接到外部文章)
content_extraction:
  enabled: true
  # 使用 Hermes 的网页内容提取工具
  tool: "web_fetch"
  # 提取正文(去除广告、导航等)
  article_only: true
  # 最大字符数
  max_length: 5000

GitHub Trending 抓取

# data_sources/github_trending.yaml
name: "github_trending"
description: "抓取 GitHub Trending 项目"
 
fetch:
  # GitHub Trending 页面(需要解析 HTML)
  - name: "trending_repos"
    url: "https://github.com/trending"
    method: "GET"
    parse: "html"
    selectors:
      repo_name: "h2.h3.lh-condensed a"
      description: "p.col-9.color-fg-muted.my-1"
      language: "span.d-inline-block.ml-0.mr-3 span[itemprop='programmingLanguage']"
      stars_today: "span.d-inline-block.float-sm-right"
 
  # 补充 API 获取详细信息
  - name: "repo_details"
    url: "https://api.github.com/repos/{owner}/{repo}"
    method: "GET"
    headers:
      Authorization: "token ${GITHUB_TOKEN}"
    fields:
      - "stargazers_count"
      - "forks_count"
      - "topics"
      - "created_at"
      - "updated_at"
 
# 过滤条件
filter:
  # 只关注 AI/Agent 相关项目
  keywords:
    - "ai"
    - "agent"
    - "llm"
    - "machine learning"
    - "openai"
    - "anthropic"
  # 今日新增 star 数
  min_stars_today: 50

Twitter/X 数据抓取

# data_sources/twitter_monitor.yaml
name: "twitter_monitor"
description: "监控 Twitter/X 上的 AI 相关讨论"
 
# 使用 Twitter API v2(需要开发者账号)
fetch:
  - name: "ai_tweets"
    endpoint: "https://api.twitter.com/2/tweets/search/recent"
    method: "GET"
    headers:
      Authorization: "Bearer ${TWITTER_BEARER_TOKEN}"
    params:
      query: "(AI OR Agent OR LLM OR GPT) lang:en -is:retweet"
      max_results: 50
      "tweet.fields": "created_at,public_metrics,author_id"
      expansions: "author_id"
      "user.fields": "username,public_metrics"
 
# 关注的关键账号(KOL 列表)
key_accounts:
  - "karpathy" # Andrej Karpathy
  - "ylecun" # Yann LeCun
  - "sama" # Sam Altman
  - " BinduReddy" # Bindu Reddy
  - "DrJimFan" # Jim Fan
 
# 监控的关键词标签
hashtags:
  - "#AI"
  - "#LLM"
  - "#ArtificialIntelligence"
  - "#Web3"

注意

Twitter/X API 在 2025 年之后收费较贵。如果预算有限,可以用以下替代方案:

  1. 使用 Nitter 等第三方前端(稳定性差,不推荐用于生产)
  2. 关注几个关键账号,用 RSSHub 将他们的推文转为 RSS
  3. 完全跳过 Twitter,用 Reddit 和 HN 替代(后两者免费且质量很高)

Reddit 数据抓取

# data_sources/reddit_monitor.yaml
name: "reddit_monitor"
description: "监控 Reddit 上 AI/Web3 相关讨论"
 
# Reddit API(免费,需要注册应用获取 client_id)
fetch:
  - name: "subreddit_posts"
    endpoint: "https://www.reddit.com/r/{subreddit}/hot.json"
    method: "GET"
    headers:
      User-Agent: "HermesResearchBot/1.0"
    params:
      limit: 25
 
# 监控的 Subreddit
subreddits:
  - "MachineLearning"
  - "LocalLLaMA"
  - "OpenAI"
  - "web3"
  - "cryptocurrency"
  - "ethdev"
 
# 过滤条件
filter:
  min_score: 20
  exclude_flair:
    - "Meme"
    - "Shitpost"

4.4 数据清洗与分析 Agent

数据清洗 Agent 配置

# agents/data_cleaner.yaml
name: "data_cleaner"
description: "清洗和标准化原始数据"
 
# 使用的模型(清洗不需要太强的模型,用便宜的)
model: "gpt-4o-mini"
 
# 清洗流程
pipeline:
  # 步骤1:去重
  - step: "deduplication"
    method: "semantic" # 语义去重(不仅比较标题,还比较内容相似度)
    threshold: 0.85 # 相似度超过 85% 视为重复
 
  # 步骤2:过滤低质量内容
  - step: "quality_filter"
    rules:
      - "content_length > 200" # 正文太短的不保留
      - "title_not_clickbait" # 过滤标题党
      - "language == 'en' or language == 'zh'" # 只保留中英文
 
  # 步骤3:分类打标签
  - step: "classification"
    categories:
      - "LLM/大模型"
      - "AI Agent"
      - "Web3/区块链"
      - "开源项目"
      - "投资/融资"
      - "产品发布"
      - "技术论文"
      - "行业观点"
 
  # 步骤4:提取关键信息
  - step: "extraction"
    fields:
      - "summary" # 一句话摘要
      - "key_points" # 3-5 个要点
      - "entities" # 提及的公司/项目/人名
      - "sentiment" # 情感倾向
 
# 输出格式
output:
  format: "json"
  schema:
    id: "string"
    source: "string"
    title: "string"
    url: "string"
    category: "string"
    summary: "string"
    key_points: "array[string]"
    entities: "array[string]"
    sentiment: "enum[positive, neutral, negative]"
    score: "number"
    timestamp: "datetime"

分析 Agent 配置

# agents/analyst.yaml
name: "investment_analyst"
description: "分析清洗后的数据,提取投资信号"
 
# 分析用强模型
model: "gpt-4o"
 
# 分析维度
analysis_dimensions:
  # 维度1:趋势分析
  - name: "trend_analysis"
    prompt: |
      分析以下 AI/Web3 行业数据,识别当前的主要趋势:
 
      数据:{{data}}
 
      请回答:
      1. 今天最热门的 3 个趋势是什么?
      2. 这些趋势是延续性的还是新出现的?
      3. 哪些趋势值得持续关注?
    output:
      - "top_trends"
      - "trend_momentum" # 趋势强度
 
  # 维度2:情绪分析
  - name: "sentiment_analysis"
    prompt: |
      分析以下内容的整体市场情绪:
 
      数据:{{data}}
 
      请给出:
      1. 整体情绪评分(1-10,10 最乐观)
      2. 情绪变化(比昨天更乐观/悲观/持平)
      3. 影响情绪的关键事件
    output:
      - "sentiment_score"
      - "sentiment_change"
      - "key_events"
 
  # 维度3:项目发现
  - name: "project_discovery"
    prompt: |
      从以下数据中识别值得关注的项目/公司/产品:
 
      数据:{{data}}
 
      对每个值得关注的项目,给出:
      1. 项目名称和简介
      2. 为什么值得关注
      3. 风险提醒(如有)
    output:
      - "notable_projects"
 
  # 维度4:关联分析
  - name: "correlation_analysis"
    prompt: |
      分析以下不同来源的信息之间有什么关联:
 
      数据:{{data}}
 
      寻找:
      1. 跨平台热议的同一话题
      2. 因果关系(A 事件可能导致 B 结果)
      3. 共识与分歧(不同社区对同一事件的看法差异)
    output:
      - "cross_platform_topics"
      - "causal_links"
      - "consensus_gaps"

4.5 报告生成与格式化

报告模板配置

# reports/daily_brief_template.yaml
name: "daily_brief"
description: "每日行业简报模板"
 
# 报告结构
template: |
  # 🚀 AI & Web3 每日简报
 
  **日期**:{{date}}
  **数据源**:Hacker News, GitHub, Reddit, Twitter
  **生成时间**:{{generation_time}}
 
  ---
 
  ## 📊 市场脉搏
 
  **整体情绪**:{{sentiment.score}}/10 {{sentiment.emoji}}
  **情绪变化**:{{sentiment.change}}
  **热门趋势**:
  {{#each trends}}
  - **{{name}}** — {{description}} (热度:{{momentum}})
  {{/each}}
 
  ---
 
  ## 🔥 今日热点
 
  {{#each hot_topics}}
  ### {{index}}. {{title}}
  - **来源**:{{source}}
  - **分类**:{{category}}
  - **摘要**:{{summary}}
  - **关键要点**:
  {{#each key_points}}
    - {{this}}
  {{/each}}
  - **🔗 原文**:{{url}}
 
  {{/each}}
 
  ---
 
  ## 💎 值得关注
 
  {{#each notable_projects}}
  ### {{name}}
  {{description}}
  - **亮点**:{{highlight}}
  - **⚠️ 风险**:{{risk}}
 
  {{/each}}
 
  ---
 
  ## 🔗 跨平台关联
 
  {{#each correlations}}
  **{{topic}}**:{{description}}
  - HN 讨论:{{hn_sentiment}}
  - Reddit 讨论:{{reddit_sentiment}}
  - GitHub 动态:{{github_activity}}
 
  {{/each}}
 
  ---
 
  > 💡 **今日思考**
  > {{daily_thought}}
 
  ---
 
  *本报告由 Hermes Agent 自动生成,仅供参考,不构成投资建议。*
 
# 样式配置
styling:
  # Markdown 格式
  format: "markdown"
  # 是否包含 emoji
  use_emoji: true
  # 最长长度
  max_length: 5000
  # 热点数量限制
  max_hot_topics: 5
  # 项目推荐数量限制
  max_notable_projects: 3

4.6 推送到 Telegram/飞书

Telegram 推送配置

# notifications/telegram_push.yaml
name: "telegram_daily_push"
description: "每日报告 Telegram 推送"
 
# Telegram Bot 配置
bot:
  token: "${TELEGRAM_BOT_TOKEN}"
  # 目标聊天 ID(可以是个人或群组)
  chat_id: "${TELEGRAM_CHAT_ID}"
 
# 推送内容
message:
  # 发送方式:text / markdown / photo(生成图片发送)
  format: "markdown"
  # 如果报告太长,是否分段发送
  split_long_message: true
  # 每段最大长度
  chunk_size: 4000
  # 发送前的预览
  preview: true
 
# 定时触发
schedule:
  cron: "0 8 * * *" # 每天上午 8:00
  timezone: "Asia/Shanghai"

飞书推送配置

# notifications/feishu_push.yaml
name: "feishu_daily_push"
description: "每日报告飞书推送"
 
# 飞书机器人配置
bot:
  webhook_url: "${FEISHU_WEBHOOK_URL}"
  # 飞书自定义机器人的签名密钥(如启用安全设置)
  secret: "${FEISHU_SECRET}"
 
# 消息格式(飞书支持富文本卡片)
message:
  format: "card"
  card_template: |
    {
      "msg_type": "interactive",
      "card": {
        "header": {
          "title": {
            "tag": "plain_text",
            "content": "🚀 AI & Web3 每日简报 — {{date}}"
          },
          "template": "blue"
        },
        "elements": [
          {
            "tag": "div",
            "text": {
              "tag": "lark_md",
              "content": "**市场情绪**:{{sentiment_score}}/10\n**热门趋势**:{{top_trend}}"
            }
          },
          {
            "tag": "hr"
          },
          {
            "tag": "div",
            "text": {
              "tag": "lark_md",
              "content": "{{content_summary}}"
            }
          },
          {
            "tag": "action",
            "actions": [
              {
                "tag": "button",
                "text": {
                  "tag": "plain_text",
                  "content": "查看完整报告"
                },
                "type": "primary",
                "url": "{{report_url}}"
              }
            ]
          }
        ]
      }
    }
 
# 定时触发
schedule:
  cron: "0 8 * * *"
  timezone: "Asia/Shanghai"

4.7 完整配置代码

下面是整个投研流水线的完整配置,你可以保存为 research_pipeline.yaml 并加载到 Hermes 中:

# ============================================================
# AI 投研流水线 —— 完整配置
 
# 版本:v1.0
# ============================================================
 
name: "ai_research_pipeline"
description: "每日自动追踪 AI/Web3 热点并生成报告"
version: "1.0"
 
# ============ 调度配置 ============
schedule:
  # 每天上午 8:00 执行
  cron: "0 8 * * *"
  timezone: "Asia/Shanghai"
  # 如果某次执行失败,是否重试
  retry:
    enabled: true
    max_attempts: 3
    delay_seconds: 60
 
# ============ 数据源配置 ============
data_sources:
  hacker_news:
    enabled: true
    fetch_count: 30
    min_score: 50
 
  github_trending:
    enabled: true
    languages: ["python", "typescript", "rust", "go"]
    min_stars_today: 30
 
  reddit:
    enabled: true
    subreddits:
      - "MachineLearning"
      - "LocalLLaMA"
      - "web3"
    min_score: 20
 
  twitter:
    enabled: true
    # 如果 API 不可用,自动跳过不影响其他源
    fallback: "skip"
 
# ============ Agent 配置 ============
agents:
  collector:
    model: "gpt-4o-mini"
    max_concurrent: 4 # 并行抓取
 
  cleaner:
    model: "gpt-4o-mini"
    dedup_threshold: 0.85
 
  analyst:
    model: "gpt-4o"
    temperature: 0.3 # 分析要稳定,不要随机
 
  reporter:
    model: "gpt-4o"
    max_output_length: 5000
 
# ============ 报告配置 ============
report:
  template: "daily_brief"
  format: "markdown"
  max_hot_topics: 5
  max_notable_projects: 3
  include_sentiment: true
  include_correlations: true
 
# ============ 推送配置 ============
notifications:
  telegram:
    enabled: true
    bot_token: "${TELEGRAM_BOT_TOKEN}"
    chat_id: "${TELEGRAM_CHAT_ID}"
    format: "markdown"
 
  feishu:
    enabled: false # 按需开启
    webhook_url: "${FEISHU_WEBHOOK_URL}"
    format: "card"
 
# ============ 记忆配置 ============
memory:
  # 保存历史报告,用于趋势对比
  store_reports: true
  # 保留天数
  retention_days: 30
  # 是否记录用户反馈("这篇报告有用/没用")
  track_feedback: true
 
# ============ 成本控制 ============
cost_control:
  # 每日预算上限(美元)
  daily_budget: 1.0
  # 预算超限时通知
  alert_on_overrun: true
  # 使用模型优先级(尽量用便宜的)
  model_priority: ["gpt-4o-mini", "gpt-4o"]

启动流水线的命令

# 加载流水线配置
$ hermes pipeline load ./research_pipeline.yaml
 
# 手动触发一次测试(不等待定时任务)
$ hermes pipeline run ai_research_pipeline --dry-run
 
# 查看流水线状态
$ hermes pipeline status ai_research_pipeline
 
# 查看执行历史
$ hermes pipeline logs ai_research_pipeline --limit 10
 
# 暂停/恢复流水线
$ hermes pipeline pause ai_research_pipeline
$ hermes pipeline resume ai_research_pipeline

4.8 成本分析(每日运行约 $0.1-0.5)

让我们来算算这条流水线每天花多少钱。

成本构成

项目单价每日用量每日成本
GPT-4o-mini(收集+清洗)$0.15/1M tokens~200K tokens$0.03
GPT-4o(分析+报告)$2.50/1M tokens~100K tokens$0.25
Twitter API(Basic)$100/月~$3.33/天
GitHub API免费(5000次/小时)~100次$0
Reddit API免费~50次$0
HN API免费~50次$0
服务器(VPS)$5-10/月~$0.3/天

Twitter API 替代方案(省钱版)

如果不使用 Twitter API,可以省掉每天 $3.33 的费用:

data_sources:
  twitter:
    enabled: false # 关闭 Twitter
 
  # 用 RSSHub 替代
  rsshub:
    enabled: true
    feeds:
      - "https://rsshub.app/twitter/user/karpathy"
      - "https://rsshub.app/twitter/user/ylecun"

优化后的每日成本

版本每日成本月度成本
完整版(含 Twitter API)~$3.9~$117
精简版(无 Twitter)~$0.6~$18
极致省钱版(全部本地模型)~$0.05~$1.5

Tips

如果你是个人用户,推荐"精简版"配置。信息源用 HN + GitHub + Reddit 已经足够丰富。Twitter 上的大部分重要信息会在 Reddit 和 HN 上出现。省下的钱够你多喝几杯咖啡了。

4.9 优化建议

优化1:用缓存减少重复调用

# 在 config.yaml 中启用智能缓存
cache:
  enabled: true
  # 网页内容缓存(相同 URL 不重复抓取)
  web_content:
    ttl: 3600 # 1小时
  # API 响应缓存
  api_response:
    ttl: 1800 # 30分钟
  # 报告片段缓存
  report_fragments:
    ttl: 86400 # 24小时

优化2:增量更新代替全量抓取

# 只抓取自上次运行以来的新内容
data_sources:
  hacker_news:
    incremental: true
    # 记录上次抓取的最大 item ID
    state_file: "./state/hn_last_id.txt"
 
  github_trending:
    incremental: false # GitHub Trending 每天变化,需要全量
    # 但可以用缓存避免重复请求
    cache_ttl: 3600

优化3:动态模型选择

# 根据任务复杂度自动选择模型
model_routing:
  # 简单任务用便宜模型
  simple_tasks:
    model: "gpt-4o-mini"
    conditions:
      - "token_count < 1000"
      - "task_type in ['summarize', 'classify']"
 
  # 复杂任务用强模型
  complex_tasks:
    model: "gpt-4o"
    conditions:
      - "task_type in ['analyze', 'reason', 'generate_report']"
 
  # 超长文本用 Claude(上下文窗口更大)
  long_context:
    model: "claude-sonnet"
    conditions:
      - "input_tokens > 10000"

优化4:智能去重减少处理量

cleaning:
  # 在抓取阶段就去重
  early_dedup:
    enabled: true
    # 如果两个 URL 的域名+路径相似度 > 90%,视为同一篇文章
    url_similarity_threshold: 0.9
 
  # 语义去重
  semantic_dedup:
    enabled: true
    # 使用 embedding 比较内容相似度
    embedding_model: "text-embedding-3-small"
    threshold: 0.85

5. 实战案例:内容自动化工厂

5.1 需求分析:自动生成社交媒体内容

自媒体运营有一个永恒的痛点:内容生产速度追不上发布频率的要求

假设你运营着 3 个平台:微信公众号、小红书和抖音。每个平台的风格不同:

  • 公众号:深度长文,1500-3000 字,注重逻辑和论据
  • 小红书:短平快,300-800 字,多用 emoji,注重视觉感
  • 抖音:文案要口语化,适合配音,强调"钩子"和情绪

如果你每天要为每个平台生产内容,光是写作就要花 3-4 小时,还没算选题和排版的时间。

解决方案:搭建一个"内容自动化工厂",让 Hermes 的多个 Agent 协作完成从选题到发布的全流程。

预期效果

  • 每天早上自动生成 5 篇 AI 快讯(不同平台版本)
  • 选题基于实时热点,确保内容的时效性
  • 每篇内容都经过审校 Agent 检查,避免事实错误
  • 发布时间优化(根据各平台流量高峰)
  • 你只需要花 10 分钟做最终确认和微调

5.2 选题 Agent(热点追踪)

选题是内容生产的第一步,也是最重要的一步。选题 Agent 的任务是:从海量信息中筛选出适合你账号定位的热点话题。

# agents/topic_selector.yaml
name: "topic_selector"
description: "从热点信息中筛选适合的内容选题"
 
# 账号定位(用于筛选匹配的话题)
account_profile:
  name: "示例账号"
  niche: "AI 技术解读与行业观察"
  target_audience: "AI 从业者、开发者、投资人"
  content_style: "深度分析 + 通俗解释"
  # 偏好话题权重
  topic_weights:
    "大模型技术": 1.5
    "AI Agent": 1.5
    "开源项目": 1.3
    "创业融资": 1.2
    "产品发布": 1.0
    "行业八卦": 0.3 # 低权重,不太关注八卦
 
# 热点数据源
sources:
  - "hacker_news"
  - "github_trending"
  - "weibo_hot" # 微博热搜
  - "zhihu_hot" # 知乎热榜
  - "twitter_trending"
 
# 选题策略
selection_strategy:
  # 策略1:时效性优先(新发生的事)
  - name: "timeliness"
    weight: 0.3
    criteria: "published_within_24h"
 
  # 策略2:热度优先(讨论的人多)
  - name: "popularity"
    weight: 0.25
    criteria: "engagement_score > threshold"
 
  # 策略3:匹配度优先(符合账号定位)
  - name: "relevance"
    weight: 0.3
    criteria: "semantic_similarity_to_profile > 0.7"
 
  # 策略4:差异化优先(别人没讲过的角度)
  - name: "differentiation"
    weight: 0.15
    criteria: "novelty_score > 0.6"
 
# 每日选题数量
daily_topics: 5
 
# 输出格式
output:
  - "title" # 选题标题
  - "angle" # 切入角度
  - "source_url" # 参考链接
  - "priority" # 优先级(1-5)
  - "estimated_reads" # 预估阅读量

选题 Agent 的工作流程

workflow:
  name: "daily_topic_selection"
  steps:
    # 步骤1:抓取热点
    - action: "fetch_trending"
      sources: "{{sources}}"
 
    # 步骤2:初步过滤(排除明显不相关的)
    - action: "filter"
      rules:
        - "language in ['zh', 'en']"
        - "not contains: [色情, 赌博, 政治]"
 
    # 步骤3:计算匹配度
    - action: "score_topics"
      strategy: "{{selection_strategy}}"
 
    # 步骤4:去重(避免连续多天讲同一话题)
    - action: "dedup_with_history"
      history_days: 7
      threshold: 0.8
 
    # 步骤5:生成选题列表
    - action: "generate_topic_list"
      count: "{{daily_topics}}"

类比

选题 Agent 就像一个敏锐的编辑部主任。每天早上,他浏览上百份报纸和网站,从中挑出最值得报道的 5 个话题。他不是随便挑——他要考虑:这个话题我们的读者关心吗?我们能讲出跟别人不一样的角度吗?这个话题现在讲是不是最好的时机?

5.3 写作 Agent(内容生成)

写作 Agent 是内容工厂的核心。它根据选题和平台要求,生成适配不同渠道的文案。

# agents/writer.yaml
name: "content_writer"
description: "根据选题生成各平台适配的文案"
 
# 平台适配配置
platform_presets:
  wechat:
    name: "微信公众号"
    style: "深度长文"
    length: "1500-3000字"
    tone: "专业、理性、有洞察"
    structure: "
      - 钩子开头(引发好奇)
      - 背景介绍(让读者跟上)
      - 核心分析(你的观点)
      - 案例/数据支撑
      - 总结升华
      - 互动引导(留言/转发)
    "
    formatting:
      use_headings: true
      use_blockquotes: true
      use_lists: true
 
  xiaohongshu:
    name: "小红书"
    style: "短平快笔记"
    length: "300-800字"
    tone: "亲切、活泼、有共鸣"
    structure: "
      - 封面标题(抓眼球)
      - 个人经历/感受引入
      - 干货内容(分点列出)
      - 情绪价值(共鸣、激励)
      - 互动引导(评论区话题)
    "
    formatting:
      use_emoji: true
      use_hashtags: true
      paragraph_length: "短句为主"
 
  douyin:
    name: "抖音"
    style: "短视频文案"
    length: "100-300字"
    tone: "口语化、有情绪、带节奏"
    structure: "
      - 黄金3秒钩子
      - 信息密度高的正文
      - 金句/反转/悬念结尾
      - 引导点赞关注
    "
    formatting:
      line_breaks: "每句一行"
      spoken_language: true  # 适合朗读
 
# 写作提示词模板
prompt_template: |
  你是一位专业的 {{platform.name}} 内容创作者,擅长 {{platform.style}}。
 
  请根据以下选题,撰写一篇 {{platform.name}} 的文案。
 
  **选题**:{{topic.title}}
  **切入角度**:{{topic.angle}}
  **参考信息**:{{topic.source_content}}
 
  **要求**:
  1. 字数控制在 {{platform.length}}
  2. 语气风格:{{platform.tone}}
  3. 结构遵循:{{platform.structure}}
  4. 格式要求:{{platform.formatting}}
  5. 不要编造数据,如果参考信息中没有具体数据,可以模糊表述或使用"据报道"等措辞
  6. 确保内容有信息增量,不要泛泛而谈
 
# 使用的模型
model: "gpt-4o"
temperature: 0.7  # 创意写作需要一定的随机性

批量生成工作流

workflow:
  name: "batch_content_generation"
  steps:
    # 步骤1:获取今日选题
    - action: "get_topics"
      source: "topic_selector"
      count: 5
 
    # 步骤2:为每个选题、每个平台生成内容
    - action: "parallel_generate"
      parallelism:
        topics: 5
        platforms: 3
      # 总共生成 15 篇内容(5选题 × 3平台)
 
    # 步骤3:格式化输出
    - action: "format_output"
      structure:
        - "topic_id"
        - "platform"
        - "title"
        - "content"
        - "word_count"
        - "estimated_read_time"

Tips

不同平台的文案风格差异很大,不要试图用同一篇内容"通发"所有平台。小红书的用户喜欢看"干货笔记",公众号的读者愿意读"深度分析",抖音的观众需要"快节奏信息"。写作 Agent 的价值就在于,它能理解这些差异并生成适配的内容。

5.4 审校 Agent(质量把控)

内容生成后,不能直接发布,必须经过审校。审校 Agent 负责检查事实准确性、语言表达、合规性等问题。

# agents/editor.yaml
name: "content_editor"
description: "审校生成的内容,确保质量"
 
# 审校维度
check_dimensions:
  # 维度1:事实核查
  - name: "fact_check"
    model: "gpt-4o"
    prompt: |
      请检查以下内容中的事实性陈述,标记可能存在的问题:
 
      内容:{{content}}
 
      检查要点:
      1. 数据是否准确(是否有明显错误的数据)
      2. 人名/公司名是否拼写正确
      3. 时间/日期是否合理
      4. 引用是否标注来源
      5. 是否存在明显的主观臆断被包装成事实
 
      输出格式:
      - 问题位置(段落/句子)
      - 问题描述
      - 建议修改
    severity: "high" # 事实错误必须修正
 
  # 维度2:语言表达
  - name: "language_quality"
    model: "gpt-4o-mini"
    prompt: |
      请检查以下内容的语言表达:
 
      内容:{{content}}
      平台:{{platform}}
 
      检查要点:
      1. 是否有语病或不通顺的句子
      2. 是否符合 {{platform}} 的语言风格
      3. 是否有重复啰嗦的表述
      4. 标点符号使用是否规范
      5. 段落划分是否合理
    severity: "medium"
 
  # 维度3:合规性检查
  - name: "compliance"
    model: "gpt-4o-mini"
    prompt: |
      请检查以下内容是否存在合规风险:
 
      内容:{{content}}
 
      检查要点:
      1. 是否涉及敏感话题(政治、色情、暴力等)
      2. 是否存在未经授权的引用/抄袭
      3. 是否涉及不实医疗/投资建议
      4. 是否侵犯他人隐私或名誉
      5. 广告法相关:是否使用了违禁词("最"、"第一"、"国家级"等)
    severity: "critical" # 合规问题一票否决
 
  # 维度4:平台适配检查
  - name: "platform_fit"
    model: "gpt-4o-mini"
    prompt: |
      请检查以下内容是否符合 {{platform}} 的平台规范:
 
      内容:{{content}}
 
      检查要点:
      1. 字数是否在合理范围内
      2. 格式是否符合平台习惯
      3. 是否有平台禁止的内容类型
      4. 标题是否符合平台算法偏好
    severity: "medium"
 
# 审校结果处理
result_handling:
  # 如果没有问题,直接通过
  auto_pass: "no_issues_found"
 
  # 如果有中低风险问题,自动修正
  auto_fix: "severity <= medium"
 
  # 如果有高风险问题,标记为需人工审核
  manual_review: "severity >= high"
 
  # 如果有严重合规问题,直接拒绝
  reject: "severity == critical"

5.5 多平台分发(公众号、小红书、抖音文案)

内容审校通过后,需要发布到各个平台。不同平台的发布方式不同:

微信公众号发布

# publishers/wechat_publish.yaml
name: "wechat_publisher"
description: "发布到微信公众号"
 
# 使用微信公众号 API(需要已认证的服务号)
api:
  app_id: "${WECHAT_APP_ID}"
  app_secret: "${WECHAT_APP_SECRET}"
 
# 发布配置
publish:
  # 素材上传
  upload_images: true
  # 封面图生成
  generate_cover: true
  cover_template: "default"
 
  # 文章设置
  article_settings:
    need_open_comment: true
    only_fans_can_comment: false
 
  # 发布方式:draft(保存草稿)/ publish(直接发布)/ schedule(定时)
  mode: "draft" # 建议先保存草稿,人工确认后再发布

小红书发布

# publishers/xiaohongshu_publish.yaml
name: "xiaohongshu_publisher"
description: "发布到小红书"
 
# 小红书目前没有官方 API,需要使用第三方工具或模拟操作
# 方案1:使用小红书创作者服务平台 API(需申请)
# 方案2:使用 Puppeteer 模拟浏览器操作(稳定性差)
# 方案3:导出内容,人工复制粘贴(推荐)
 
# 本配置采用方案3:生成发布就绪的内容
output:
  format: "copy_paste_ready"
  includes:
    - "title"
    - "content_with_emojis"
    - "hashtags"
    - "suggested_cover_text" # 封面图文字建议
    - "suggested_images" # 配图建议

抖音文案生成

# publishers/douyin_publish.yaml
name: "douyin_publisher"
description: "生成抖音发布文案"
 
# 抖音也没有直接的内容发布 API(视频发布除外)
# 这里生成适合抖音格式的文案
 
output:
  format: "douyin_script"
  includes:
    - "hook" # 前3秒钩子
    - "script" # 完整口播文案
    - "captions" # 字幕文本
    - "hashtags" # 推荐标签
    - "music_suggestion" # BGM建议
    - "duration_estimate" # 预估时长

5.6 定时调度配置

# schedule/content_factory.yaml
name: "content_factory_schedule"
description: "内容自动化工厂的定时调度"
 
# 整体调度计划
schedule:
  # 阶段1:每天早上 6:00 选题
  topic_selection:
    cron: "0 6 * * *"
    timezone: "Asia/Shanghai"
 
  # 阶段2:6:30 开始批量写作
  content_generation:
    cron: "30 6 * * *"
    depends_on: "topic_selection"
 
  # 阶段3:7:00 审校
  content_editing:
    cron: "0 7 * * *"
    depends_on: "content_generation"
 
  # 阶段4:7:30 推送待发布队列
  publish_queue:
    cron: "30 7 * * *"
    depends_on: "content_editing"
 
# 分平台发布时间优化
publish_times:
  # 公众号最佳发布时间
  wechat:
    - "12:00" # 午休时间
    - "18:30" # 下班路上
    - "21:00" # 睡前阅读
 
  # 小红书最佳发布时间
  xiaohongshu:
    - "07:30" # 早起刷手机
    - "12:30" # 午休
    - "20:00" # 晚饭后
 
  # 抖音最佳发布时间
  douyin:
    - "07:00" # 起床刷
    - "12:00" # 午饭刷
    - "18:00" # 下班刷
    - "21:00" # 睡前刷

5.7 案例:日更 5 篇 AI 快讯的配置方案

下面是一个完整的、可直接使用的日更 5 篇 AI 快讯配置:

# ============================================================
# 内容自动化工厂 —— 日更 5 篇 AI 快讯
# ============================================================
 
name: "daily_ai_news_factory"
description: "每日自动生成并发布 5 篇 AI 快讯"
 
# 账号设置
account:
  name: "示例账号"
  niche: "AI 每日快讯"
  platforms: ["wechat", "xiaohongshu"]
 
# 数据流
data_pipeline:
  # 数据源
  sources:
    - "hacker_news"
    - "github_trending"
    - "reddit/MachineLearning"
    - "reddit/LocalLLaMA"
 
  # 筛选条件:只选 AI 相关
  filter:
    keywords:
      - "AI"
      - "LLM"
      - "GPT"
      - "Claude"
      - "OpenAI"
      - "Agent"
      - "模型"
      - "训练"
      - "推理"
    exclude:
      - "NSFW"
      - "political"
    min_engagement: 20
 
# Agent 配置
agents:
  # 选题 Agent
  selector:
    model: "gpt-4o-mini"
    daily_count: 5
    strategy: "timeliness_first"
 
  # 写作 Agent
  writer:
    model: "gpt-4o"
    temperature: 0.7
    platforms:
      wechat:
        length: "800-1200字"
        style: "专业深度"
      xiaohongshu:
        length: "300-500字"
        style: "轻松干货"
 
  # 审校 Agent
  editor:
    model: "gpt-4o-mini"
    auto_fix: true
 
# 输出
output:
  # 保存到本地
  save_local: true
  output_dir: "./content_output/{{date}}"
 
  # 推送到 Telegram 预览
  telegram_preview:
    enabled: true
    bot_token: "${TELEGRAM_BOT_TOKEN}"
    chat_id: "${TELEGRAM_CHAT_ID}"
 
  # 发布到公众号(保存为草稿)
  wechat:
    enabled: true
    mode: "draft"
    app_id: "${WECHAT_APP_ID}"
    app_secret: "${WECHAT_APP_SECRET}"
 
# 定时执行
schedule:
  cron: "0 6 * * *"
  timezone: "Asia/Shanghai"
 
# 成本控制
cost_control:
  daily_budget: 0.5
  model_priority: ["gpt-4o-mini", "gpt-4o"]

运行命令

# 加载内容工厂
$ hermes factory load ./daily_ai_news_factory.yaml
 
# 手动执行一次
$ hermes factory run daily_ai_news_factory
 
# 查看今日生成的内容
$ ls ./content_output/$(date +%Y-%m-%d)
 
# 查看生成日志
$ hermes factory logs daily_ai_news_factory

常见问题

Q:自动生成的内容会不会被平台判定为 AI 内容而降权?

A: 这是所有 AI 内容创作者都关心的问题。目前的建议是:

  1. AI 生成后务必人工润色,加入你的个人经历、观点和表达习惯
  2. 不要完全依赖 AI,把它当作"初稿生成器"而不是"完稿发布器"
  3. 在内容中加入独特的信息增量,比如你自己的测试结果、采访、数据整理
  4. 定期分析内容的阅读数据,根据反馈调整生成策略 平台算法在不断进化,核心原则是:给读者提供真正有价值的内容,无论是否用了 AI 辅助。

6. 实战案例:代码质量守护者

6.1 需求分析:自动化代码审查与安全扫描

代码审查是软件开发中至关重要但也非常耗时的环节。一个典型的代码审查可能需要:

  • 30 分钟理解代码变更的背景和目的
  • 20 分钟检查代码风格和命名规范
  • 20 分钟分析潜在的安全漏洞
  • 15 分钟检查测试覆盖度
  • 15 分钟给出改进建议

总计:每次 PR 审查约 100 分钟。如果团队每天产生 5-10 个 PR,光是代码审查就要占用一个人一整天的时间。

解决方案:让 Hermes 担任"代码质量守护者",自动完成大部分机械性的审查工作,把人类审查者的精力解放出来,专注于架构设计和业务逻辑。

预期效果

  • 每个 PR 在提交后 1 分钟内得到初步审查反馈
  • 自动拦截明显的安全漏洞和代码风格问题
  • 生成结构化的审查报告,便于人类审查者快速浏览
  • 与 CI/CD 管道集成,不达标的代码无法合并

6.2 Git Hook 集成

Git Hook 是在 Git 操作的特定时机自动执行的脚本。我们可以通过 Hook 在代码提交或推送时触发 Hermes 的审查。

pre-commit Hook(提交前检查)

#!/bin/bash
# .git/hooks/pre-commit
# 在每次 git commit 前执行
 
echo "🔍 Hermes 正在检查你的代码..."
 
# 获取暂存区的文件列表
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.(py|js|ts|java|go)$')
 
if [ -z "$STAGED_FILES" ]; then
    echo "✅ 没有需要检查的代码文件"
    exit 0
fi
 
# 调用 Hermes 进行提交前检查
hermes review \
    --mode pre-commit \
    --files "$STAGED_FILES" \
    --config ./hermes-code-review.yaml \
    --output /tmp/hermes-pre-commit.json
 
# 读取检查结果
RESULT=$(cat /tmp/hermes-pre-commit.json | jq '.passed')
 
if [ "$RESULT" = "false" ]; then
    echo "❌ 代码检查未通过,请修复以下问题:"
    cat /tmp/hermes-pre-commit.json | jq '.issues[] | "  - \(.severity): \(.message) (\(.file):\(.line))"'
    echo ""
    echo "如果你确定要提交,使用 git commit --no-verify 跳过检查(不推荐)"
    exit 1
fi
 
echo "✅ 代码检查通过"
exit 0

pre-push Hook(推送前检查)

#!/bin/bash
# .git/hooks/pre-push
# 在每次 git push 前执行
 
echo "🔍 Hermes 正在检查本次推送..."
 
# 获取即将推送的提交
COMMITS=$(git log --oneline @{u}..HEAD 2>/dev/null || echo "")
 
if [ -z "$COMMITS" ]; then
    echo "✅ 没有新的提交需要检查"
    exit 0
fi
 
# 调用 Hermes 进行推送前检查
hermes review \
    --mode pre-push \
    --commits "@{u}..HEAD" \
    --config ./hermes-code-review.yaml \
    --output /tmp/hermes-pre-push.json
 
RESULT=$(cat /tmp/hermes-pre-push.json | jq '.passed')
 
if [ "$RESULT" = "false" ]; then
    echo "❌ 推送检查未通过"
    exit 1
fi
 
echo "✅ 推送检查通过"
exit 0

配置代码审查规则

# hermes-code-review.yaml
name: "code_quality_guardian"
description: "代码质量守护者配置"
 
# 审查触发时机
triggers:
  - "pre-commit"   # 提交前
  - "pre-push"     # 推送前
  - "pr-created"   # PR 创建时
  - "pr-updated"   # PR 更新时
 
# 按语言配置审查规则
rules_by_language:
  python:
    # 风格检查
    style:
      tool: "ruff"  # 或 flake8, pylint
      enabled: true
      # 自动修复可修复的问题
      auto_fix: true
      # 忽略的规则
      ignore: ["E501"]  # 行长度(我们用 black 处理)
 
    # 类型检查
    typing:
      tool: "mypy"
      enabled: true
      strict: true
 
    # 安全扫描
    security:
      tool: "bandit"
      enabled: true
      severity_threshold: "medium"
 
    # 测试覆盖度
    coverage:
      enabled: true
      min_coverage: 70  # 最低 70%
 
  javascript:
    style:
      tool: "eslint"
      enabled: true
      auto_fix: true
    security:
      tool: "eslint-plugin-security"
      enabled: true
 
  typescript:
    style:
      tool: "eslint"
      enabled: true
      auto_fix: true
    typing:
      tool: "tsc"
      enabled: true
 
# 通用规则(所有语言)
general_rules:
  # 检查敏感信息泄露
  secret_detection:
    enabled: true
    patterns:
      - "api_key\s*=\s*['\"][^'\"]{10,}['\"]"
      - "password\s*=\s*['\"][^'\"]+['\"]"
      - "AKIA[0-9A-Z]{16}"  # AWS Access Key
      - "ghp_[a-zA-Z0-9]{36}"  # GitHub Personal Token
 
  # 检查大文件
  large_files:
    enabled: true
    max_size_mb: 10
 
  # 检查二进制文件
  binary_files:
    enabled: true
    allowed_extensions: [".png", ".jpg", ".pdf", ".woff2"]

6.3 PR 自动审查工作流

当开发者在 GitHub/GitLab 上创建或更新 PR 时,Hermes 自动进行审查并发布评论。

# workflows/pr_review.yaml
name: "pr_auto_review"
description: "PR 自动审查工作流"
 
# 触发条件
triggers:
  - event: "pull_request"
    actions: ["opened", "synchronize"]
 
# PR 审查流程
pipeline:
  # 步骤1:获取 PR 信息
  - action: "fetch_pr_info"
    fields:
      - "title"
      - "description"
      - "changed_files"
      - "diff"
 
  # 步骤2:代码变更分析
  - action: "analyze_changes"
    # 分析变更的复杂度
    complexity_analysis: true
    # 识别变更的影响范围
    impact_analysis: true
 
  # 步骤3:执行静态分析工具
  - action: "run_linters"
    parallel: true
    tools:
      - "ruff"
      - "mypy"
      - "bandit"
 
  # 步骤4:AI 辅助审查
  - action: "ai_review"
    model: "gpt-4o"
    # 审查重点
    focus_areas:
      - "逻辑正确性"
      - "边界情况处理"
      - "错误处理完整性"
      - "性能影响"
      - "可维护性"
    # 输出格式
    output_format: "structured"
 
  # 步骤5:生成审查报告
  - action: "generate_report"
    template: "pr_review"
 
  # 步骤6:发布评论
  - action: "post_review_comment"
    # 在 GitHub PR 下方发布评论
    platform: "github"
    # 如果检查通过,发布"LGTM"评论
    post_lgtm_on_pass: true

AI 审查提示词

ai_review_prompt: |
  你是一位资深代码审查专家,请对以下代码变更进行审查。
 
  **PR 标题**:{{pr.title}}
  **PR 描述**:{{pr.description}}
  **变更文件**:{{pr.changed_files}}
 
  **代码 Diff**:
  ```diff
  &#123;&#123;pr.diff&#125;&#125;

请从以下维度进行审查:

  1. 逻辑正确性:代码逻辑是否正确?是否有明显的 bug?
  2. 边界情况:是否考虑了各种边界情况(空值、越界、并发等)?
  3. 错误处理:错误处理是否完善?是否有可能吞掉异常?
  4. 性能:是否有明显的性能问题(如 N+1 查询、内存泄漏等)?
  5. 可读性:代码是否易于理解?命名是否清晰?
  6. 安全性:是否有安全漏洞(注入、XSS、CSRF 等)?
  7. 测试:变更是否配套了测试?测试是否覆盖了关键路径?

对于每个发现的问题,请给出:

  • 严重程度(critical/high/medium/low)
  • 问题描述
  • 具体位置(文件名和行号)
  • 修改建议(包含代码示例)

如果代码没有问题,请明确说明"LGTM"(Looks Good To Me)。


### 6.4 安全漏洞扫描

```yaml
# security/scan_config.yaml
name: "security_scanner"
description: "安全漏洞扫描配置"

# 扫描工具配置
scanners:
  # 依赖漏洞扫描
  dependency_check:
    enabled: true
    tools:
      python: "safety"      # 检查 Python 依赖漏洞
      js: "npm audit"       # 检查 npm 依赖漏洞
      go: "govulncheck"     # 检查 Go 依赖漏洞

    # 漏洞严重性阈值
    severity_threshold: "medium"
    # 是否自动创建修复 PR
    auto_fix: false

  # 静态应用安全测试(SAST)
  sast:
    enabled: true
    tools:
      python: "bandit"
      js: "eslint-plugin-security"
      generic: "semgrep"

    # 规则集
    rules:
      - "owasp-top-10"
      - "cwe-top-25"

  # 密钥扫描
  secret_scan:
    enabled: true
    tool: "gitleaks"
    # 扫描历史提交
    scan_history: true
    history_depth: 100

  # 基础设施扫描(如果有 Dockerfile/K8s 配置)
  infrastructure:
    enabled: true
    tool: "checkov"
    files:
      - "Dockerfile"
      - "docker-compose.yml"
      - "*.tf"  # Terraform
      - "k8s/**/*.yaml"

# 扫描结果处理
reporting:
  # 生成 SARIF 格式报告(GitHub/GitLab 兼容)
  format: "sarif"
  output: "./security-report.sarif"

  # 在 PR 中标注漏洞位置
  annotate_pr: true

  # 严重漏洞阻止合并
  block_on_critical: true

6.5 代码质量报告生成

# reporting/quality_report.yaml
name: "quality_report"
description: "代码质量报告生成"
 
# 报告内容
sections:
  - name: "summary"
    title: "📊 质量概览"
    content: |
      - 检查文件数:{{stats.files_checked}}
      - 发现问题数:{{stats.issues_found}}
      - 严重问题:{{stats.critical}}
      - 高风险问题:{{stats.high}}
      - 中风险问题:{{stats.medium}}
      - 低风险问题:{{stats.low}}
      - 代码覆盖度:{{stats.coverage}}%
      - 质量评分:{{stats.score}}/100
 
  - name: "issues"
    title: "🔍 发现的问题"
    # 按严重程度分组
    group_by: "severity"
    # 每个问题包含
    fields:
      - "severity"
      - "message"
      - "file"
      - "line"
      - "suggestion"
 
  - name: "trends"
    title: "📈 质量趋势"
    # 与历史数据对比
    compare_with: "last_7_days"
    metrics:
      - "issue_count_trend"
      - "coverage_trend"
      - "score_trend"
 
  - name: "recommendations"
    title: "💡 改进建议"
    # AI 生成的改进建议
    ai_generated: true
    model: "gpt-4o-mini"
 
# 报告分发
distribution:
  # 发布到 PR 评论
  pr_comment: true
  # 发送到 Slack 频道
  slack:
    enabled: true
    webhook: "${SLACK_WEBHOOK_URL}"
    channel: "#code-quality"
  # 保存到文件
  file:
    enabled: true
    path: "./reports/quality-{{date}}.md"

6.6 CI/CD 集成方案

GitHub Actions 集成

# .github/workflows/hermes-review.yml
name: "Hermes Code Review"
 
on:
  pull_request:
    types: [opened, synchronize]
 
jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - name: "Checkout code"
        uses: actions/checkout@v4
        with:
          fetch-depth: 0 # 需要完整历史进行增量分析
 
      - name: "Setup Python"
        uses: actions/setup-python@v5
        with:
          python-version: "3.11"
 
      - name: "Install Hermes"
        run: |
          pip install hermes-cli
 
      - name: "Run Hermes Review"
        env:
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          hermes review \
            --mode pr-review \
            --pr-number ${{ github.event.pull_request.number }} \
            --config ./hermes-code-review.yaml \
            --output ./review-result.json
 
      - name: "Post Review Comment"
        uses: actions/github-script@v7
        with:
          script: |
            const fs = require('fs');
            const result = JSON.parse(fs.readFileSync('./review-result.json', 'utf8'));
 
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: result.review_comment
            });
 
      - name: "Check Review Result"
        run: |
          PASSED=$(cat ./review-result.json | jq '.passed')
          if [ "$PASSED" = "false" ]; then
            echo "❌ 代码审查未通过"
            exit 1
          fi
          echo "✅ 代码审查通过"

GitLab CI 集成

# .gitlab-ci.yml
stages:
  - review
 
hermes_review:
  stage: review
  image: python:3.11
  before_script:
    - pip install hermes-cli
  script:
    - hermes review
      --mode pr-review
      --merge-request-id $CI_MERGE_REQUEST_IID
      --config ./hermes-code-review.yaml
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"

6.7 案例:开源项目的自动化质量门禁

假设你是一个开源项目的维护者,每天有多个贡献者提交 PR。你希望在保证代码质量的同时,不给贡献者带来太高的门槛。

# ============================================================
# 开源项目自动化质量门禁
# ============================================================
 
name: "oss_quality_gate"
description: "开源项目质量门禁配置(对贡献者友好)"
 
# 贡献者友好配置
contributor_friendly:
  # 第一次贡献者的 PR 使用更宽松的规则
  first_time_contributor:
    rules:
      # 不强制要求测试(鼓励他们先参与)
      coverage:
        required: false
      # 风格问题自动修复而不是报错
      style:
        auto_fix: true
        block_on_style: false
 
    # 欢迎消息
    welcome_message: |
      🎉 感谢你为这个项目贡献代码!
 
      Hermes 已经自动审查了你的代码。一些小问题我已经帮你修正了,
      请查看最新的 commit。如果有任何疑问,欢迎随时提问。
 
  # 资深贡献者使用标准规则
  regular_contributor:
    rules:
      coverage:
        required: true
        min_coverage: 70
      style:
        auto_fix: true
        block_on_style: true
 
# 审查规则(分层)
rules:
  # 第一层:快速检查(30秒内完成)
  fast_checks:
    timeout: 30
    checks:
      - "secret_detection"
      - "large_files"
      - "basic_style"
 
  # 第二层:标准检查(2分钟内完成)
  standard_checks:
    timeout: 120
    checks:
      - "full_lint"
      - "type_check"
      - "security_scan"
 
  # 第三层:深度检查(5分钟内完成,异步)
  deep_checks:
    timeout: 300
    async: true # 不阻塞 PR,结果作为补充信息
    checks:
      - "ai_review"
      - "complexity_analysis"
      - "coverage_detailed"
 
# 质量门禁
quality_gate:
  # 必须通过才能合并
  required:
    - "fast_checks.passed"
    - "standard_checks.passed"
 
  # 不通过会警告但不阻塞
  recommended:
    - "deep_checks.score > 70"
 
  # 合并按钮状态
  merge_button:
    # 门禁通过:绿色
    pass: "enable"
    # 门禁失败:红色
    fail: "disable"
    # 进行中:黄色
    pending: "show_progress"

7. 实战案例:个人知识管理系统

7.1 需求分析:打造第二大脑

现代人的信息摄入量是巨大的。每天你要浏览几十篇文章、看几十个视频、读几十条社交媒体动态、收到几十封邮件。但问题是:你真正记住并能够调用的信息,可能不到 1%。

传统的笔记方法(随手记、收藏夹、文件夹)有几个问题:

  1. 存而不读:收藏了 1000 篇文章,但再也没看过
  2. 找而不得:需要某个信息时,想不起来存在哪里
  3. 信息孤岛:笔记之间没有关联,无法形成知识网络
  4. 缺乏回顾:没有定期回顾机制,知识随着时间遗忘

解决方案:用 Hermes 搭建一个"第二大脑"——自动收集、智能分类、构建知识图谱、定期回顾,让你的知识资产真正产生复利。

预期效果

  • 自动收集你浏览过的文章、邮件、书签
  • 智能分类和标签化,无需手动整理
  • 知识图谱可视化,发现信息之间的隐藏关联
  • 定期生成回顾报告,强化记忆
  • 需要时可以通过自然语言查询快速找到相关信息

7.2 信息收集自动化(RSS、邮件、书签)

RSS 订阅收集

# knowledge/rss_collector.yaml
name: "rss_collector"
description: "RSS 订阅自动收集"
 
# 订阅源
feeds:
  # AI 技术博客
  - url: "https://blog.openai.com/rss.xml"
    category: "AI 公司动态"
    priority: "high"
 
  - url: "https://simonwillison.net/atom.xml"
    category: "技术实践"
    priority: "high"
 
  - url: "https://lilianweng.github.io/index.xml"
    category: "技术深度"
    priority: "high"
 
  # 中文源
  - url: "https://www.qbitai.com/feed"
    category: "中文 AI 资讯"
    priority: "medium"
 
  # 个人博客
  - url: "https://example.com/feed.xml"
    category: "关注博主"
    priority: "medium"
 
# 收集配置
collection:
  # 检查频率
  check_interval: "1h"
  # 只收集最近 7 天的内容
  max_age: "7d"
  # 文章内容提取
  extract_content:
    enabled: true
    # 使用 Mercury 或 Readability 提取正文
    tool: "readability"
    # 保存完整内容
    save_full_text: true
 
  # 去重
  dedup:
    enabled: true
    # 基于 URL 去重
    by_url: true
    # 基于标题相似度去重
    by_title_similarity: 0.9
 
# 存储
storage:
  # 保存到本地文件
  local:
    enabled: true
    path: "./knowledge/inbox/{{date}}/"
 
  # 同时保存到数据库(用于检索)
  database:
    enabled: true
    type: "sqlite"
    path: "./knowledge/knowledge.db"

邮件收集

# knowledge/email_collector.yaml
name: "email_collector"
description: "自动收集和归档重要邮件"
 
# 邮件账户配置
accounts:
  - type: "imap"
    server: "imap.gmail.com"
    port: 993
    username: "${EMAIL_USERNAME}"
    password: "${EMAIL_APP_PASSWORD}" # 使用应用专用密码
    # 只收集特定标签的邮件
    labels: ["Newsletters", "AI", "Important"]
 
# 过滤规则
filters:
  # 只收集 Newsletter 类邮件
  - condition: "from contains 'newsletter' OR subject contains 'Newsletter'"
    action: "collect"
 
  # 收集特定发件人的邮件
  - condition: "from in ['[email protected]', '[email protected]']"
    action: "collect"
 
  # 忽略营销邮件
  - condition: "subject contains '促销' OR subject contains '优惠'"
    action: "ignore"
 
# 内容提取
extraction:
  # 提取邮件正文(去除签名、法律声明等)
  extract_body: true
  # 提取附件(PDF、DOC 等)
  extract_attachments: true
  # 附件保存路径
  attachment_path: "./knowledge/attachments/"

浏览器书签收集

# knowledge/bookmark_collector.yaml
name: "bookmark_collector"
description: "收集浏览器书签"
 
# 导入浏览器书签
import:
  # 支持的浏览器
  browsers:
    - "chrome"
    - "firefox"
    - "safari"
 
  # 书签文件路径
  paths:
    chrome: "~/Library/Application Support/Google/Chrome/Default/Bookmarks"
    firefox: "~/Library/Application Support/Firefox/Profiles/*/bookmarks.html"
 
  # 只导入特定文件夹的书签
  filter_folders:
    - "AI"
    - "Read Later"
    - "Research"
 
  # 忽略的文件
  ignore_patterns:
    - "javascript:"
    - "chrome://"
 
# 对书签进行内容抓取
fetch_content:
  enabled: true
  # 抓取延迟(避免被封)
  delay: 2
  # 最大抓取数量(每次运行)
  max_per_run: 20
  # 超时时间
  timeout: 30

7.3 智能分类与标签

收集到的信息需要自动分类和打标签,这样才能高效检索。

# knowledge/auto_classifier.yaml
name: "auto_classifier"
description: "知识内容自动分类和标签"
 
# 分类体系
categories:
  # 一级分类
  - name: "AI 技术"
    subcategories:
      - "大模型"
      - "Agent"
      - "RAG"
      - "微调"
      - "多模态"
 
  - name: "编程开发"
    subcategories:
      - "Python"
      - "前端"
      - "系统架构"
      - "DevOps"
 
  - name: "行业观察"
    subcategories:
      - "创业"
      - "投资"
      - "产品"
      - "商业化"
 
  - name: "个人成长"
    subcategories:
      - "效率工具"
      - "学习方法"
      - "思维方式"
 
# 自动标签
tagging:
  # 基于内容生成标签
  auto_generate:
    enabled: true
    model: "gpt-4o-mini"
    max_tags: 10
    # 标签风格
    style: "concise" # 简短标签,如 "transformer", "agent"
 
  # 基于规则打标签
  rule_based:
    - pattern: "transformer|attention|BERT|GPT"
      tags: ["transformer", "nlp"]
    - pattern: "docker|kubernetes|ci/cd"
      tags: ["devops", "container"]
    - pattern: "startup|vc|funding"
      tags: ["startup", "investment"]
 
  # 实体标签(人名、公司、产品)
  entity_extraction:
    enabled: true
    # 提取的实体类型
    types:
      - "PERSON" # 人名
      - "ORG" # 组织/公司
      - "PRODUCT" # 产品
      - "TECH" # 技术术语
 
# 分类模型配置
classification:
  model: "gpt-4o-mini"
  # 分类方法:single(单分类)/ multi(多标签)
  method: "multi"
  # 置信度阈值
  confidence_threshold: 0.7

7.4 知识图谱构建

知识图谱能把孤立的信息点连接起来,发现你原本不知道的关联。

# knowledge/knowledge_graph.yaml
name: "knowledge_graph"
description: "个人知识图谱构建"
 
# 图谱构建
graph:
  # 节点类型
  node_types:
    - "document" # 文档/文章
    - "concept" # 概念
    - "person" # 人
    - "organization" # 组织
    - "technology" # 技术
    - "tag" # 标签
 
  # 关系类型
  edge_types:
    - "mentions" # 提及
    - "related_to" # 相关
    - "part_of" # 属于
    - "contradicts" # 矛盾/反驳
    - "supports" # 支持
    - "prerequisite" # 前置知识
 
  # 构建方法
  construction:
    # 基于共现(同一文档中出现的实体建立关联)
    co_occurrence:
      enabled: true
      window_size: 100 # 字符窗口
      min_co_occurrence: 2
 
    # 基于语义相似度
    semantic_similarity:
      enabled: true
      model: "text-embedding-3-small"
      threshold: 0.8
 
    # 基于显式链接(文档中的超链接)
    explicit_links:
      enabled: true
 
# 图谱存储
storage:
  # 使用 NetworkX + 持久化
  format: "graphml"
  path: "./knowledge/knowledge_graph.graphml"
 
  # 定期备份
  backup:
    enabled: true
    interval: "1d"
    keep_count: 7
 
# 可视化
visualization:
  enabled: true
  # 使用 D3.js 或 Gephi 导出
  export_formats:
    - "html" # 交互式网页
    - "png" # 静态图片
    - "gexf" # Gephi 格式

7.5 定期回顾与总结

# knowledge/review_system.yaml
name: "review_system"
description: "定期知识回顾系统"
 
# 回顾计划
schedule:
  # 每日回顾(昨晚收集的内容)
  daily:
    cron: "0 9 * * *" # 每天早上 9 点
    content: "昨天收集的 {{count}} 条内容摘要"
    format: "brief"
 
  # 每周回顾
  weekly:
    cron: "0 10 * * 1" # 每周一上午 10 点
    content: "本周知识汇总"
    includes:
      - "本周收集的内容统计"
      - "新出现的概念/技术"
      - "知识图谱的变化"
      - "推荐阅读 TOP 5"
    format: "detailed"
 
  # 每月回顾
  monthly:
    cron: "0 10 1 * *" # 每月 1 号上午 10 点
    content: "月度知识报告"
    includes:
      - "月度阅读统计"
      - "知识领域分布变化"
      - "兴趣趋势分析"
      - "知识盲区提醒"
    format: "comprehensive"
 
# 回顾内容生成
review_generation:
  model: "gpt-4o"
  # 生成风格
  style: "conversational" # 像朋友聊天一样回顾
 
  # 个性化
  personalization:
    # 基于用户画像调整内容
    based_on_profile: true
    # 强调用户关注的领域
    highlight_interests: true
    # 提醒可能遗漏的重要内容
    surface_missed_content: true
 
# 推送
notifications:
  # Telegram 推送
  telegram:
    enabled: true
    bot_token: "${TELEGRAM_BOT_TOKEN}"
    chat_id: "${TELEGRAM_CHAT_ID}"

7.6 与 Notion/Obsidian 集成

Notion 集成

# integrations/notion_sync.yaml
name: "notion_sync"
description: "与 Notion 同步知识库"
 
# Notion API 配置
notion:
  token: "${NOTION_INTEGRATION_TOKEN}"
  # 目标数据库
  database_id: "${NOTION_DATABASE_ID}"
 
# 同步规则
sync:
  # 双向同步还是单向?
  direction: "bidirectional"
 
  # 同步触发条件
  triggers:
    - "new_content_collected"
    - "daily_schedule"
    - "manual"
 
  # 字段映射
  field_mapping:
    hermes_field: "notion_property"
    mappings:
      title: "Name"
      content: "Content"
      category: "Category"
      tags: "Tags"
      url: "URL"
      summary: "Summary"
      collected_at: "Created"
 
  # 自动在 Notion 中创建页面
  auto_create_page:
    enabled: true
    # 页面模板
    template: |
      # {{title}}
 
      **来源**:{{url}}
      **分类**:{{category}}
      **标签**:{{tags}}
 
      ---
 
      ## 摘要
 
      {{summary}}
 
      ## 笔记
 
      {{content}}
 
      ## 关联
 
      {{related_content}}

Obsidian 集成

# integrations/obsidian_sync.yaml
name: "obsidian_sync"
description: "与 Obsidian 同步知识库"
 
# Obsidian 库路径
obsidian:
  vault_path: "~/Documents/Obsidian Vault"
 
# 同步配置
sync:
  # 输出到 Obsidian 的文件夹
  output_folder: "Hermes Inbox"
 
  # 文件名格式
  filename_format: "{{date}}-{{slugified_title}}.md"
 
  # Frontmatter 配置
  frontmatter:
    enabled: true
    fields:
      - "title"
      - "source"
      - "category"
      - "tags"
      - "collected_at"
      - "summary"
 
  # 双向链接
  backlinks:
    enabled: true
    # 自动在相关笔记之间创建链接
    auto_link:
      enabled: true
      # 基于标签和类别匹配
      match_by: ["tags", "category", "entities"]
 
  # 图谱兼容
  graph_compatible:
    enabled: true
    # 使用 Obsidian 的图谱格式
    format: "obsidian"

7.7 案例:研究人员的文献管理助手

这个案例专门为学术研究人员设计,帮助管理论文、笔记和研究思路。

# ============================================================
# 研究人员文献管理助手
# ============================================================
 
name: "research_paper_manager"
description: "学术研究人员的智能文献管理助手"
 
# 论文收集
paper_collection:
  # arXiv 监控
  arxiv:
    enabled: true
    # 监控的分类
    categories:
      - "cs.AI"
      - "cs.CL"
      - "cs.LG"
      - "cs.MA"
    # 关键词过滤
    keywords:
      - "agent"
      - "large language model"
      - "RAG"
      - "multi-agent"
    # 每日推送新论文
    daily_digest: true
 
  # Google Scholar 监控(需要配置)
  google_scholar:
    enabled: true
    # 监控的学者
    authors:
      - "Yann LeCun"
      - "Yoshua Bengio"
      - "Geoffrey Hinton"
    # 监控的论文引用
    citation_alerts:
      - "paper_id_1"
      - "paper_id_2"
 
# 论文处理
paper_processing:
  # 自动下载 PDF
  auto_download:
    enabled: true
    save_path: "./papers/{{year}}/{{title}}.pdf"
 
  # 提取元数据
  metadata_extraction:
    enabled: true
    fields:
      - "title"
      - "authors"
      - "abstract"
      - "keywords"
      - "publication_date"
      - "doi"
      - "citation_count"
 
  # 生成论文摘要
  summarization:
    enabled: true
    model: "gpt-4o"
    # 摘要风格
    style: "academic"
    # 摘要长度
    max_length: 500
    # 提取关键贡献
    extract_contributions: true
    # 提取实验结果
    extract_results: true
    # 提取方法论
    extract_methodology: true
 
  # 相关性评分
  relevance_scoring:
    enabled: true
    # 基于你的研究兴趣评分
    research_interests:
      - "AI Agent"
      - "Memory Systems"
      - "Tool Learning"
    # 高分论文优先推送
    threshold: 0.7
 
# 笔记管理
note_management:
  # 论文阅读笔记模板
  note_template: |
    # {{paper.title}}
 
    **作者**:{{paper.authors}}
    **发表**:{{paper.publication_date}}
    **arXiv**:{{paper.url}}
 
    ---
 
    ## 一句话总结
 
    {{summary.one_liner}}
 
    ## 研究问题
 
    {{summary.research_question}}
 
    ## 核心方法
 
    {{summary.methodology}}
 
    ## 主要贡献
 
    {{summary.contributions}}
 
    ## 实验结果
 
    {{summary.results}}
 
    ## 我的思考
 
    - 这篇论文的创新点是什么?
    - 有哪些局限性?
    - 对我的研究有什么启发?
    - 有哪些值得跟进的工作?
 
    ## 关联论文
 
    {{related_papers}}
 
  # 与 Zotero 同步
  zotero_sync:
    enabled: true
    library_id: "${ZOTERO_LIBRARY_ID}"
    api_key: "${ZOTERO_API_KEY}"
 
# 研究趋势分析
trend_analysis:
  enabled: true
  # 每周分析你的阅读数据
  weekly_report:
    includes:
      - "本周阅读论文数"
      - "研究领域分布"
      - "高频关键词"
      - "新兴研究方向"
      - "推荐阅读"

8. 实战案例:客服机器人

8.1 需求分析:7x24 智能客服

对于电商、SaaS、在线教育等业务,客服是一个刚需但成本很高的环节:

  • 人工客服需要轮班,7×24 覆盖成本高
  • 80% 的问题都是重复性的("怎么退款"、"密码忘了怎么办")
  • 高峰期(双 11、活动期间)客服压力巨大
  • 培训新客服成本高,且服务质量不稳定

解决方案:用 Hermes 搭建一个智能客服机器人,处理常见问题,复杂问题再转人工。

预期效果

  • 解决 70-80% 的常见问题,无需人工介入
  • 7×24 在线,响应时间 < 3 秒
  • 多语言支持(如果业务有出海需求)
  • 满意度收集和分析,持续优化
  • 大幅降低客服成本

8.2 知识库构建

客服机器人的核心是其知识库。知识库的质量直接决定了回答的准确性。

# customer_service/knowledge_base.yaml
name: "cs_knowledge_base"
description: "客服知识库配置"
 
# 知识来源
sources:
  # 1. FAQ 文档
  faq:
    files:
      - "./knowledge/faq.md"
      - "./knowledge/return_policy.md"
      - "./knowledge/shipping_info.md"
 
  # 2. 产品文档
  product_docs:
    url: "https://docs.yourcompany.com"
    # 自动抓取和更新
    auto_sync:
      enabled: true
      interval: "1d"
 
  # 3. 历史客服记录
  chat_history:
    # 导入历史对话作为训练数据
    import:
      enabled: true
      source: "zendesk" # 或 freshdesk, intercom
      api_key: "${SUPPORT_API_KEY}"
      # 只导入高评分对话
      filter:
        rating: ">= 4"
        # 排除敏感对话
        exclude_tags: ["sensitive", "legal"]
 
  # 4. 商品信息
  product_catalog:
    source: "database"
    connection: "${DATABASE_URL}"
    query: "SELECT id, name, description, price, specs FROM products"
 
# 知识处理
processing:
  # 分块策略
  chunking:
    strategy: "semantic"
    chunk_size: 500
    chunk_overlap: 100
 
  # Embedding 模型
  embedding:
    model: "text-embedding-3-small"
    # 是否缓存 embedding
    cache: true
 
  # 索引构建
  indexing:
    # 向量索引
    vector_index:
      enabled: true
      # 使用 FAISS 或类似的向量索引
      backend: "faiss"
 
    # 关键词索引(用于混合检索)
    keyword_index:
      enabled: true
      # 使用 SQLite FTS5
      backend: "fts5"
 
    # 混合检索权重
    hybrid_weights:
      semantic: 0.7
      keyword: 0.3
 
# 知识库更新
updates:
  # 定期重新索引
  reindex_interval: "7d"
 
  # 增量更新
  incremental:
    enabled: true
    # 检测新内容并自动索引
    watch_files: true

8.3 多轮对话管理

客服场景通常需要多轮对话——不是一问一答就能解决的。

# customer_service/conversation_manager.yaml
name: "conversation_manager"
description: "客服多轮对话管理"
 
# 对话状态跟踪
state_tracking:
  enabled: true
  # 跟踪的上下文信息
  context:
    - "user_intent" # 用户当前意图
    - "intent_history" # 意图历史
    - "collected_info" # 已收集的信息
    - "missing_info" # 还缺的信息
    - "escalation_reason" # 升级原因
 
# 对话流程定义
flows:
  # 流程1:订单查询
  order_inquiry:
    trigger: "intent == 'order_query'"
    steps:
      - ask: "请问您的订单号是多少?"
        extract: "order_id"
        validation: "regex:^[A-Z0-9]{10}$"
 
      - if: "order_id valid"
        then:
          - action: "query_order"
            params:
              order_id: "{{order_id}}"
          - respond: "您的订单 {{order_id}} 当前状态是 {{order.status}},预计 {{order.eta}} 送达。"
        else:
          - ask: "订单号格式不正确,请提供 10 位字母数字组合的订单号。"
            retry: 2
 
      - ask: "还有其他我可以帮您的吗?"
        branch:
          - if: "intent == 'yes'"
            then: "continue"
          - if: "intent == 'no'"
            then: "end"
 
  # 流程2:退款申请
  refund_request:
    trigger: "intent == 'refund'"
    steps:
      - ask: "好的,我来帮您处理退款。请问您要退款的订单号是多少?"
        extract: "order_id"
 
      - ask: "退款原因是什么?"
        extract: "refund_reason"
        options:
          - "商品质量问题"
          - "与描述不符"
          - "不想要了"
          - "其他"
 
      - action: "check_refund_eligibility"
        params:
          order_id: "{{order_id}}"
          reason: "{{refund_reason}}"
 
      - if: "eligible == true"
        then:
          - action: "create_refund_ticket"
          - respond: "退款申请已提交,退款将在 3-5 个工作日原路返回。退款单号:{{ticket_id}}"
        else:
          - respond: "很抱歉,该订单不符合退款条件。原因:{{ineligible_reason}}"
          - offer: "human_handoff"
 
  # 流程3:技术支持
  tech_support:
    trigger: "intent == 'technical_issue'"
    steps:
      - ask: "请描述您遇到的问题,我会尽力帮您解决。"
        extract: "issue_description"
 
      - action: "search_knowledge_base"
        query: "{{issue_description}}"
 
      - if: "solution_found"
        then:
          - respond: "根据我们的知识库,您可以尝试以下解决方案:\n{{solution}}"
          - ask: "问题解决了吗?"
            branch:
              - if: "solved"
                then: "end_with_satisfaction"
              - if: "not_solved"
                then: "escalate_to_human"
        else:
          - respond: "这个问题比较特殊,我为您转接人工客服。"
          - action: "escalate"
 
# 意图识别
intent_detection:
  model: "gpt-4o-mini"
  # 预定义意图
  intents:
    - "order_query"
    - "refund"
    - "shipping"
    - "product_info"
    - "technical_issue"
    - "account"
    - "complaint"
    - "general_chat"
 
  # 置信度阈值
  confidence_threshold: 0.7
  # 低于阈值时询问确认
  ask_confirmation: true

8.4 人机转接机制

客服机器人不是万能的。当遇到以下情况时,应该及时转接人工:

# customer_service/escalation.yaml
name: "escalation_rules"
description: "人机转接规则"
 
# 自动转人工的触发条件
auto_escalate:
  # 条件1:用户明确要求人工
  - condition: "user_says: ['人工', '客服', '找人工', '转人工']"
    action: "immediate_transfer"
    message: "正在为您转接人工客服,请稍候..."
 
  # 条件2:连续 3 次无法回答
  - condition: "consecutive_failures >= 3"
    action: "offer_transfer"
    message: "很抱歉,我暂时无法解决这个问题。是否需要转接人工客服?"
 
  # 条件3:检测到负面情绪升级
  - condition: "sentiment_score < -0.5 AND escalation_count == 0"
    action: "priority_transfer"
    message: "非常抱歉给您带来不好的体验,我立即为您安排资深客服专员。"
 
  # 条件4:涉及敏感话题(退款纠纷、法律问题等)
  - condition: "topic in ['legal', 'complaint_severe', 'fraud']"
    action: "immediate_transfer"
    message: "这个问题需要专人处理,正在为您转接..."
 
  # 条件5:超出知识库范围
  - condition: "kb_confidence < 0.3"
    action: "offer_transfer"
    message: "这个问题超出了我的知识范围,需要人工客服协助。"
 
# 转接信息传递
handoff_context:
  # 转接时传递给人工客服的信息
  include:
    - "conversation_history"
    - "user_intent"
    - "collected_information"
    - "attempted_solutions"
    - "escalation_reason"
    - "user_sentiment"
 
  # 格式化
  format: "structured_summary"
 
# 人工客服状态
agent_availability:
  # 检查人工客服是否在线
  check_online: true
  # 排队管理
  queue:
    enabled: true
    # 预估等待时间
    show_wait_time: true
    # 排队中自动安抚
    queue_messages:
      - "当前排队人数:{{queue_position}},预计等待 {{wait_time}}"
      - "您也可以先描述问题,客服上线后会优先处理"

8.5 满意度收集

# customer_service/satisfaction.yaml
name: "satisfaction_collection"
description: "客服满意度收集"
 
# 满意度调查
collection:
  # 触发时机
  trigger: "conversation_end"
 
  # 调查方式
  method: "inline"
 
  # 调查内容
  survey:
    - question: "请问您对本次服务满意吗?"
      type: "rating"
      scale: 5
      emoji: ["😠", "😞", "😐", "🙂", "😊"]
 
    - question: "我的回答解决了您的问题吗?"
      type: "boolean"
 
    - question: "您还有其他建议吗?"
      type: "text"
      optional: true
 
# 反馈处理
feedback_processing:
  # 实时分析反馈
  real_time_analysis:
    enabled: true
    model: "gpt-4o-mini"
    # 分析维度
    dimensions:
      - "satisfaction_score"
      - "issue_resolved"
      - "sentiment"
      - "specific_complaints"
 
  # 低满意度预警
  alerts:
    - condition: "rating <= 2"
      action: "notify_manager"
      message: "⚠️ 低满意度会话:{{conversation_id}},请及时跟进"
 
    - condition: "rating == 1"
      action: "create_follow_up_ticket"
 
# 数据驱动优化
optimization:
  # 定期分析满意度数据
  weekly_analysis:
    enabled: true
    # 生成改进建议
    generate_insights: true
    # 识别知识库缺口
    identify_kb_gaps: true
    # 更新知识库
    auto_update_kb: false # 建议人工确认后再更新

8.6 多渠道部署(网站、微信、Telegram)

网站接入(Web Widget)

# deployment/web_widget.yaml
name: "web_widget"
description: "网站客服组件"
 
# Widget 配置
widget:
  # 样式
  appearance:
    position: "bottom-right"
    primary_color: "#1890ff"
    welcome_message: "👋 你好!有什么可以帮您的吗?"
    avatar: "./assets/bot-avatar.png"
 
  # 触发方式
  triggers:
    - "user_clicks_button"
    - "time_on_page > 30s"
    - "scroll_depth > 80%"
 
  # 功能
  features:
    - "text_chat"
    - "quick_replies"
    - "file_upload" # 用户可上传图片/截图
 
  # 快捷回复按钮
  quick_replies:
    - "查询订单"
    - "退款申请"
    - "物流查询"
    - "联系人工"
 
# 嵌入代码(给前端开发者)
embed_code: |
  <script>
    (function() {
      var script = document.createElement('script');
      script.src = 'https://hermes.yourcompany.com/widget.js';
      script.async = true;
      script.onload = function() {
        HermesWidget.init({
          apiKey: 'YOUR_API_KEY',
          position: 'bottom-right'
        });
      };
      document.head.appendChild(script);
    })();
  </script>

微信公众号接入

# deployment/wechat_bot.yaml
name: "wechat_customer_service"
description: "微信客服机器人"
 
# 微信公众号配置
wechat:
  app_id: "${WECHAT_APP_ID}"
  app_secret: "${WECHAT_APP_SECRET}"
  token: "${WECHAT_TOKEN}"
  encoding_aes_key: "${WECHAT_AES_KEY}"
 
# 消息处理
message_handling:
  # 接收用户消息
  receive:
    endpoint: "/webhook/wechat"
    method: "POST"
 
  # 消息类型处理
  handlers:
    text:
      action: "process_with_knowledge_base"
    image:
      action: "ocr_and_process" # 图片先 OCR 再处理
    voice:
      action: "stt_and_process" # 语音先转文字再处理
    location:
      action: "provide_local_service" # 基于位置的服务
 
# 被动回复(微信公众号 5 秒超时限制)
response_strategy:
  # 快速回复(必须在 5 秒内)
  immediate:
    enabled: true
    # 如果处理需要时间,先回复"正在处理"
    processing_message: "正在为您查询,请稍候..."
 
  # 异步回复(通过客服消息接口)
  async:
    enabled: true
    # 使用微信客服消息接口(48 小时内可发 20 条)
    use_customer_service_api: true
 
# 菜单配置
menu:
  items:
    - name: "查询订单"
      type: "click"
      key: "QUERY_ORDER"
    - name: "常见问题"
      type: "view"
      url: "https://yourcompany.com/faq"
    - name: "联系客服"
      type: "click"
      key: "CONTACT_SUPPORT"

Telegram Bot 接入

# deployment/telegram_bot.yaml
name: "telegram_customer_service"
description: "Telegram 客服机器人"
 
# Bot 配置
telegram:
  bot_token: "${TELEGRAM_BOT_TOKEN}"
  # Webhook 或轮询
  update_mode: "webhook" # 或 "polling"
  webhook_url: "https://yourdomain.com/webhook/telegram"
 
# 命令列表
commands:
  - command: "start"
    description: "开始使用"
    handler: "welcome"
 
  - command: "help"
    description: "帮助信息"
    handler: "show_help"
 
  - command: "order"
    description: "查询订单"
    handler: "query_order"
 
  - command: "refund"
    description: "申请退款"
    handler: "refund_request"
 
  - command: "human"
    description: "联系人工客服"
    handler: "escalate_to_human"
 
# 内联键盘
inline_keyboards:
  main_menu:
    - buttons:
        - text: "📦 查询订单"
          callback_data: "menu_order"
        - text: "💰 申请退款"
          callback_data: "menu_refund"
    - buttons:
        - text: "📖 常见问题"
          callback_data: "menu_faq"
        - text: "👨‍💼 人工客服"
          callback_data: "menu_human"

8.7 案例:小型电商的客服解决方案

下面是一个完整的小型电商客服系统配置,你可以直接基于它修改使用:

# ============================================================
# 小型电商智能客服系统
# ============================================================
 
name: "ecommerce_customer_service"
description: "小型电商 7x24 智能客服解决方案"
 
# 系统配置
system:
  # 欢迎语
  welcome_message: |
    🛍️ 欢迎来到 {{shop_name}}!
 
    我是您的智能客服助手,可以帮您:
    • 📦 查询订单状态
    • 💰 申请退款/退换货
    • 🚚 查询物流信息
    • 🎁 了解优惠活动
    • 👤 账户相关问题
 
    请直接输入您的问题,或点击下方菜单选择服务。
 
  # 工作时段
  business_hours:
    weekdays: "09:00-22:00"
    weekends: "10:00-21:00"
    # 非工作时间的特殊回复
    after_hours_message: "当前为非工作时间,您的留言将在客服上班后第一时间处理。紧急问题请拨打:{{emergency_phone}}"
 
# 知识库
knowledge_base:
  # FAQ
  faq:
    - question: "多久发货"
      answer: "一般情况下,订单付款后 24 小时内发货。预售商品以商品页面标注的时间为准。"
      keywords: ["发货", "多久发货", "什么时候发货"]
 
    - question: "支持哪些支付方式"
      answer: "我们支持微信支付、支付宝、银行卡支付。部分商品支持货到付款。"
      keywords: ["支付", "付款", "怎么付钱"]
 
    - question: "怎么退货"
      answer: |
        退货流程:
        1. 进入"我的订单"找到对应订单
        2. 点击"申请售后"
        3. 选择退货原因并提交
        4. 审核通过后,按地址寄回商品
        5. 我们收到商品后 3 个工作日内退款
 
        注意:定制类商品不支持退货。
      keywords: ["退货", "怎么退", "退款"]
 
    - question: "运费怎么算"
      answer: "订单满 99 元包邮(偏远地区除外)。不满 99 元收取 6 元运费。"
      keywords: ["运费", "邮费", "多少钱"]
 
    - question: "怎么修改地址"
      answer: "订单未发货前可以修改地址。请提供订单号,我帮您查看是否还可以修改。"
      keywords: ["改地址", "修改地址", "地址错了"]
 
# 订单查询(接入数据库)
order_query:
  enabled: true
  database:
    connection: "${DATABASE_URL}"
 
  # 查询模板
  queries:
    by_order_id: |
      SELECT o.id, o.status, o.total, o.created_at,
             oi.product_name, oi.quantity,
             s.tracking_number, s.carrier, s.status as shipping_status
      FROM orders o
      LEFT JOIN order_items oi ON o.id = oi.order_id
      LEFT JOIN shipments s ON o.id = s.order_id
      WHERE o.id = $1
 
  # 状态映射(数据库状态 -> 用户友好状态)
  status_mapping:
    pending: "待付款"
    paid: "已付款,待发货"
    shipped: "已发货"
    delivered: "已送达"
    completed: "已完成"
    cancelled: "已取消"
    refunding: "退款中"
 
# 退款处理
refund:
  # 退款规则
  rules:
    # 7 天无理由退货
    no_reason_return:
      enabled: true
      period_days: 7
      exclude_categories: ["定制", "生鲜", "贴身衣物"]
 
    # 质量问题退货
    quality_issue:
      enabled: true
      # 免邮费退回
      free_return: true
 
  # 自动退款(小额)
  auto_refund:
    enabled: true
    max_amount: 100 # 100 元以下自动退
    require_approval_above: 100
 
# 部署
channels:
  # 网站 Widget
  web:
    enabled: true
    widget_config: "./web_widget.yaml"
 
  # 微信公众号
  wechat:
    enabled: true
    config: "./wechat_bot.yaml"
 
  # 微信小程序(需要额外配置)
  wechat_mini:
    enabled: false
 
  # 抖音(企业号私信)
  douyin:
    enabled: false
 
# 人工接管
human_handoff:
  # 工作时间配置
  working_hours:
    agents_online: true
    max_queue: 10
 
  # 非工作时间
  after_hours:
    agents_online: false
    leave_message: true
    auto_reply: "客服当前不在线,您的问题已记录,上班后第一时间回复。"
 
# 数据分析
analytics:
  # 每日统计
  daily_report:
    enabled: true
    metrics:
      - "总会话数"
      - "机器人解决率"
      - "平均响应时间"
      - "转人工率"
      - "满意度评分"
      - "高频问题 TOP 10"
 
  # 推送
  notification:
    telegram:
      enabled: true
      bot_token: "${TELEGRAM_BOT_TOKEN}"
      chat_id: "${ADMIN_CHAT_ID}"

9. 实战案例:数据监控与告警

9.1 需求分析:实时监控关键指标

无论是个人用户还是企业,都有很多需要监控的指标:

  • 网站是否正常运行?
  • 关注的商品价格是否降价了?
  • 竞争对手发布了什么新产品?
  • 加密货币价格是否触及了你的买卖点?
  • 服务器资源使用是否超过阈值?

手动检查这些指标既耗时又容易遗漏。让 Hermes 帮你 7×24 监控,异常情况第一时间通知你。

9.2 网站可用性监控

# monitoring/website_monitor.yaml
name: "website_monitor"
description: "网站可用性监控"
 
# 监控目标
targets:
  - name: "主站"
    url: "https://yourwebsite.com"
    method: "GET"
    expected_status: 200
    expected_response_time: 2000 # ms
 
  - name: "API 服务"
    url: "https://api.yourwebsite.com/health"
    method: "GET"
    expected_status: 200
    # 检查返回内容
    expected_body: '{"status":"ok"}'
 
  - name: "博客"
    url: "https://blog.yourwebsite.com"
    method: "GET"
 
# 检查频率
intervals:
  # 主站每 1 分钟检查一次
  critical: "1m"
  # 次要服务每 5 分钟
  normal: "5m"
  # 非核心服务每 15 分钟
  low: "15m"
 
# 告警条件
alerts:
  # 条件1:HTTP 状态码异常
  - condition: "status_code != expected"
    severity: "critical"
    message: "🚨 {{target.name}} 返回异常状态码:{{status_code}}"
 
  # 条件2:响应时间过长
  - condition: "response_time > expected_response_time"
    severity: "warning"
    message: "⚠️ {{target.name}} 响应缓慢:{{response_time}}ms"
 
  # 条件3:SSL 证书即将过期
  - condition: "ssl_expiry_days < 7"
    severity: "warning"
    message: "🔒 {{target.name}} SSL 证书将在 {{ssl_expiry_days}} 天后过期"
 
  # 条件4:DNS 解析失败
  - condition: "dns_resolution_failed"
    severity: "critical"
    message: "🌐 {{target.name}} DNS 解析失败"
 
# 告警渠道
notification_channels:
  telegram:
    enabled: true
    bot_token: "${TELEGRAM_BOT_TOKEN}"
    chat_id: "${ALERT_CHAT_ID}"
 
  email:
    enabled: true
    smtp_server: "smtp.gmail.com"
    to: "${ADMIN_EMAIL}"
 
  # 飞书
  feishu:
    enabled: true
    webhook_url: "${FEISHU_WEBHOOK_URL}"
 
# 告警收敛
alert_grouping:
  # 同一问题 5 分钟内不重复告警
  dedup_window: "5m"
  # 连续失败 2 次才告警(避免抖动)
  min_consecutive_failures: 2

9.3 价格变动追踪

# monitoring/price_tracker.yaml
name: "price_tracker"
description: "商品价格追踪"
 
# 追踪的商品
tracked_products:
  - name: "iPhone 16 Pro"
    url: "https://www.apple.com/iphone-16-pro/"
    # 价格选择器(CSS 或 XPath)
    price_selector: ".price-current"
    # 当前价格(用于计算变动)
    current_price: 7999
    # 目标价格(低于此价格时告警)
    target_price: 6999
 
  - name: "Sony WH-1000XM5"
    url: "https://www.sony.com/headphones"
    price_selector: ".price"
    target_price: 1800
 
# 检查频率
check_interval: "1h"
 
# 价格变动告警
alerts:
  # 降价到目标价以下
  - condition: "price <= target_price"
    severity: "info"
    message: |
      🎉 降价提醒!
 
      {{product.name}} 当前价格:¥{{price}}
      目标价格:¥{{target_price}}
 
      购买链接:{{product.url}}
 
  # 大幅降价(超过 10%)
  - condition: "price_drop_percent >= 10"
    severity: "info"
    message: "📉 {{product.name}} 大幅降价 {{price_drop_percent}}%,当前 ¥{{price}}"
 
# 价格历史
history:
  enabled: true
  # 保存到数据库
  storage: "sqlite"
  # 生成价格走势图
  generate_chart: true

9.4 竞品动态追踪

# monitoring/competitor_tracker.yaml
name: "competitor_tracker"
description: "竞品动态追踪"
 
# 监控的竞争对手
competitors:
  - name: "竞品 A"
    website: "https://competitor-a.com"
    # 监控的页面
    pages:
      - url: "/pricing"
        track_changes: true
      - url: "/changelog"
        track_changes: true
      - url: "/blog"
        track_new_posts: true
 
  - name: "竞品 B"
    twitter: "@competitor_b"
    track_tweets: true
    keywords: ["新品", "更新", "发布"]
 
# 监控内容
tracking:
  # 官网变化
  website_changes:
    enabled: true
    # 检测内容变化
    detect_content_change: true
    # 忽略的部分(如时间戳、广告)
    ignore_selectors:
      - ".timestamp"
      - ".ad-banner"
 
  # 新产品/功能发布
  product_launches:
    enabled: true
    # 检测关键词
    launch_keywords:
      - "发布"
      - "推出"
      - "新品"
      - "new release"
      - "launch"
 
  # 定价变化
  pricing_changes:
    enabled: true
    # 价格页面监控
    price_page_selectors:
      - ".pricing-card"
      - ".price-table"
 
# 告警
alerts:
  - condition: "website_changed"
    message: "🔍 {{competitor.name}} 官网有更新:{{changed_pages}}"
 
  - condition: "new_product_launch"
    message: "🚀 {{competitor.name}} 发布了新产品/功能:{{product_name}}"
 
  - condition: "pricing_changed"
    message: "💰 {{competitor.name}} 调整了定价"

9.5 异常检测与告警

# monitoring/anomaly_detection.yaml
name: "anomaly_detection"
description: "异常检测与智能告警"
 
# 检测方法
methods:
  # 基于阈值的简单检测
  threshold:
    enabled: true
    rules:
      - metric: "cpu_usage"
        warning: 70
        critical: 90
      - metric: "memory_usage"
        warning: 80
        critical: 95
      - metric: "disk_usage"
        warning: 80
        critical: 90
      - metric: "error_rate"
        warning: 5
        critical: 10
 
  # 基于统计的异常检测
  statistical:
    enabled: true
    model: "isolation_forest"
    # 学习历史数据
    training_window: "7d"
    # 异常阈值
    contamination: 0.01 # 期望的异常比例
 
  # 基于 AI 的异常检测
  ai_based:
    enabled: true
    model: "gpt-4o-mini"
    # 分析日志和指标,识别异常模式
    analyze_logs: true
    analyze_metrics: true
 
# 告警升级
escalation:
  # 第一次告警
  first_alert:
    channels: ["telegram"]
 
  # 5 分钟未处理,升级
  escalation_1:
    delay: "5m"
    channels: ["telegram", "email"]
 
  # 15 分钟未处理,再次升级
  escalation_2:
    delay: "15m"
    channels: ["telegram", "email", "phone"]
 
# 告警恢复通知
recovery_notification:
  enabled: true
  message: "✅ {{alert.name}} 已恢复正常"

9.6 案例:加密货币价格监控 + Telegram 告警

下面是一个完整的加密货币价格监控方案:

# ============================================================
# 加密货币价格监控 + Telegram 告警
# ============================================================
 
name: "crypto_price_monitor"
description: "加密货币实时价格监控与告警"
 
# 监控的币种
coins:
  - symbol: "BTC"
    name: "比特币"
    # 当前持仓(用于计算盈亏)
    holding: 0.5
    avg_buy_price: 60000
 
    # 价格告警
    alerts:
      - type: "above"
        price: 75000
        message: "🚀 BTC 突破 $75,000!当前 ${{price}}"
      - type: "below"
        price: 55000
        message: "📉 BTC 跌破 $55,000!当前 ${{price}}"
      - type: "percent_change_24h"
        threshold: 10
        message: "📊 BTC 24h 涨跌 {{change_percent}}%,当前 ${{price}}"
 
  - symbol: "ETH"
    name: "以太坊"
    holding: 5
    avg_buy_price: 3000
 
    alerts:
      - type: "above"
        price: 4000
        message: "🚀 ETH 突破 $4,000!"
      - type: "below"
        price: 2500
        message: "📉 ETH 跌破 $2,500!"
 
  - symbol: "SOL"
    name: "Solana"
    holding: 100
    avg_buy_price: 120
 
# 数据源
price_sources:
  primary: "coingecko"
  fallback: "binance"
 
  coingecko:
    api_key: "${COINGECKO_API_KEY}"
    update_interval: 60 # 秒
 
  binance:
    # 免费,无需 API Key
    update_interval: 30
 
# 持仓盈亏监控
portfolio:
  enabled: true
  # 每天汇总持仓盈亏
  daily_report:
    enabled: true
    cron: "0 9 * * *" # 每天早上 9 点
    timezone: "Asia/Shanghai"
 
  # 大幅波动告警
  portfolio_alerts:
    - condition: "total_pnl_change_24h > 10%"
      message: |
        💼 持仓日报
 
        总持仓价值:${{total_value}}
        24h 盈亏:{{pnl_24h}} ({{pnl_24h_percent}}%)
        累计盈亏:{{total_pnl}} ({{total_pnl_percent}}%)
 
        各币种详情:
        {{#each coins}}
        {{name}}: ${{price}} ({{change_24h}}%)
        {{/each}}
 
# 推送
notifications:
  telegram:
    enabled: true
    bot_token: "${TELEGRAM_BOT_TOKEN}"
    chat_id: "${TELEGRAM_CHAT_ID}"
    # 同时发送价格走势图
    include_chart: true
 
# 命令(通过 Telegram Bot 交互)
commands:
  - command: "/price"
    description: "查询指定币种价格"
    handler: |
      /price BTC -> 返回比特币当前价格
      /price ETH -> 返回以太坊当前价格
 
  - command: "/portfolio"
    description: "查看持仓"
    handler: "show_portfolio"
 
  - command: "/alert"
    description: "设置价格提醒"
    handler: |
      /alert BTC above 70000 -> BTC 突破 70000 时提醒
      /alert ETH below 3000 -> ETH 跌破 3000 时提醒
 
  - command: "/top"
    description: "查看涨幅榜"
    handler: "show_top_gainers"
 
# 存储
storage:
  # 价格历史
  price_history:
    enabled: true
    retention: "90d" # 保留 90 天
 
  # 告警历史
  alert_history:
    enabled: true
    retention: "30d"

启动命令

# 加载监控配置
$ hermes monitor load ./crypto_price_monitor.yaml
 
# 手动测试告警
$ hermes monitor test-alert crypto_price_monitor --coin BTC
 
# 查看价格历史
$ hermes monitor history --coin BTC --days 7
 
# Telegram 交互示例
# 用户发送:/price BTC
# Bot 回复:
# 💰 BTC 当前价格
# 价格:$67,432
# 24h 涨跌:+2.34%
# 7d 涨跌:-1.23%
# 市值:$1.32T

注意

加密货币投资风险极高,本案例仅作为技术演示。任何投资决策请自行判断,切勿依赖自动化工具的输出。设置价格提醒时,建议同时设置止损提醒,控制风险。


10. 企业级应用场景

10.1 企业内部知识库助手

企业内部的文档、制度、流程分散在各个地方——Confluence、Wiki、SharePoint、邮件、聊天记录。新员工入职要花几周才能熟悉,老员工也经常找不到需要的信息。

# enterprise/internal_kb.yaml
name: "enterprise_knowledge_assistant"
description: "企业内部知识库助手"
 
# 数据源集成
data_sources:
  # Confluence
  confluence:
    enabled: true
    url: "https://yourcompany.atlassian.net"
    username: "${CONFLUENCE_USER}"
    api_token: "${CONFLUENCE_TOKEN}"
    spaces:
      - "ENGINEERING"
      - "PRODUCT"
      - "HR"
 
  # 企业微信文档
  wechat_docs:
    enabled: true
    corp_id: "${WECHAT_CORP_ID}"
    secret: "${WECHAT_SECRET}"
 
  # 本地文件
  local_files:
    enabled: true
    paths:
      - "/shared/docs/"
      - "/shared/policies/"
    # 支持的格式
    formats: [".pdf", ".docx", ".md", ".txt"]
 
  # 数据库
  database:
    enabled: true
    queries:
      - name: "员工信息"
        query: "SELECT name, department, email FROM employees"
      - name: "项目信息"
        query: "SELECT name, status, owner FROM projects"
 
# 访问控制
access_control:
  # 基于角色的访问
  rbac:
    enabled: true
    roles:
      - name: "employee"
        access: ["general_docs", "hr_policies"]
      - name: "manager"
        access: ["general_docs", "hr_policies", "management_docs"]
      - name: "engineer"
        access: ["general_docs", "engineering_docs", "api_docs"]
      - name: "hr"
        access: ["*"] # HR 可以访问所有
 
# 问答优化
qa_optimization:
  # 常见问题预设
  faq:
    - question: "请假流程是什么"
      answer: |
        请假流程:
        1. 在 OA 系统提交请假申请
        2. 直属领导审批
        3. 3 天以上需部门总监审批
        4. HR 备案
 
        紧急请假可先口头告知,事后补流程。
 
    - question: "怎么申请报销"
      answer: |
        报销流程:
        1. 收集发票和收据
        2. 在费控系统填写报销单
        3. 上传电子发票
        4. 直属领导审批
        5. 财务审核打款
 
  # 回答风格
  tone: "professional"
  # 引用来源
  cite_sources: true
  # 不确定时提示
  uncertain_response: "这个问题我不确定答案,建议您咨询 {{suggested_contact}}"
 
# 部署方式
deployment:
  # 企业微信机器人
  wechat_work:
    enabled: true
    corp_id: "${WECHAT_CORP_ID}"
    agent_id: "${AGENT_ID}"
    secret: "${AGENT_SECRET}"
 
  # 飞书机器人
  feishu:
    enabled: true
    app_id: "${FEISHU_APP_ID}"
    app_secret: "${FEISHU_APP_SECRET}"
 
  # Web 界面
  web:
    enabled: true
    host: "0.0.0.0"
    port: 8080
    auth: "sso" # 单点登录

10.2 数据库查询助手(接入公司 DB)

让非技术人员也能通过自然语言查询数据库,而不需要写 SQL。

# enterprise/db_assistant.yaml
name: "database_query_assistant"
description: "自然语言数据库查询助手"
 
# 数据库连接
databases:
  - name: "production"
    type: "postgresql"
    host: "${DB_HOST}"
    port: 5432
    database: "analytics"
    username: "${DB_USER}"
    password: "${DB_PASSWORD}"
    # 只读权限
    read_only: true
 
# Schema 描述(帮助 AI 理解表结构)
schema_description:
  tables:
    - name: "orders"
      description: "订单表,存储所有交易订单"
      columns:
        - name: "id"
          description: "订单 ID"
        - name: "user_id"
          description: "用户 ID"
        - name: "total_amount"
          description: "订单总金额"
        - name: "status"
          description: "订单状态:pending, paid, shipped, completed"
        - name: "created_at"
          description: "创建时间"
 
    - name: "users"
      description: "用户表"
      columns:
        - name: "id"
          description: "用户 ID"
        - name: "email"
          description: "邮箱"
        - name: "registration_date"
          description: "注册日期"
 
# 安全限制
security:
  # 只允许 SELECT
  allowed_operations: ["SELECT"]
 
  # 禁止查询敏感表
  forbidden_tables:
    - "passwords"
    - "api_keys"
    - "salary_info"
 
  # 最大返回行数
  max_rows: 1000
 
  # 查询超时
  query_timeout: 30
 
  # 数据脱敏
  data_masking:
    - column_pattern: "email"
      mask: "partial" # 显示为 a***@example.com
    - column_pattern: "phone"
      mask: "full" # 完全隐藏
 
# 查询示例(用于 few-shot 提示)
examples:
  - question: "上个月销售额是多少"
    sql: |
      SELECT SUM(total_amount) as total_sales
      FROM orders
      WHERE status = 'completed'
        AND created_at >= DATE_TRUNC('month', CURRENT_DATE - INTERVAL '1 month')
        AND created_at < DATE_TRUNC('month', CURRENT_DATE)
 
  - question: "哪个地区的用户最多"
    sql: |
      SELECT region, COUNT(*) as user_count
      FROM users
      GROUP BY region
      ORDER BY user_count DESC
      LIMIT 10

10.3 项目管理自动化(接入 Linear/Jira)

# enterprise/project_management.yaml
name: "pm_automation"
description: "项目管理自动化"
 
# 集成的项目管理工具
integrations:
  linear:
    enabled: true
    api_key: "${LINEAR_API_KEY}"
    team_id: "${LINEAR_TEAM_ID}"
 
  jira:
    enabled: false
    url: "https://yourcompany.atlassian.net"
    username: "${JIRA_USER}"
    api_token: "${JIRA_TOKEN}"
 
# 自动化规则
automation_rules:
  # 规则1:每日站会摘要
  - name: "daily_standup_summary"
    trigger:
      schedule: "0 9 * * 1-5" # 工作日早上 9 点
    actions:
      - "fetch_recent_updates"
      - "generate_summary"
      - "post_to_channel"
 
    summary_template: |
      📋 昨日更新({{date}})
 
      **已完成**:{{completed_count}} 个任务
      {{#each completed}}
      - {{title}} ({{assignee}})
      {{/each}}
 
      **进行中**:{{in_progress_count}} 个任务
      {{#each in_progress}}
      - {{title}} ({{assignee}}) - {{progress}}%
      {{/each}}
 
      **阻塞中**:{{blocked_count}} 个任务
      {{#each blocked}}
      - {{title}} ({{assignee}}) - 阻塞原因:{{block_reason}}
      {{/each}}
 
  # 规则2:逾期任务提醒
  - name: "overdue_reminder"
    trigger:
      schedule: "0 10 * * *"
    condition: "due_date < today AND status != 'done'"
    actions:
      - "notify_assignee"
      - "notify_manager"
    message: "⏰ 任务「{{title}}」已逾期 {{overdue_days}} 天,请尽快处理。"
 
  # 规则3:PR 与 Ticket 关联
  - name: "pr_ticket_link"
    trigger: "pr_created"
    condition: "pr.title contains ticket_id"
    actions:
      - "link_pr_to_ticket"
      - "update_ticket_status"
      - "comment_on_ticket"
 
  # 规则4:发布计划自动更新
  - name: "release_tracking"
    trigger: "ticket_status_changed_to_done"
    condition: "ticket.has_label('release')"
    actions:
      - "update_release_notes"
      - "notify_stakeholders"
 
# 通知渠道
notifications:
  slack:
    enabled: true
    channel: "#project-updates"
 
  wechat_work:
    enabled: true
    webhook: "${WECHAT_WEBHOOK}"

10.4 会议纪要自动生成

# enterprise/meeting_notes.yaml
name: "meeting_assistant"
description: "会议纪要自动生成"
 
# 会议录音/转录
input:
  # 方式1:上传录音文件
  audio_upload:
    enabled: true
    formats: [".mp3", ".wav", ".m4a"]
 
  # 方式2:实时转录(配合会议软件)
  live_transcription:
    enabled: true
    # 支持的会议平台
    platforms:
      - "zoom"
      - "teams"
      - "tencent_meeting"
    # 实时转录服务
    stt_engine: "whisper_api"
 
# 纪要生成
generation:
  model: "gpt-4o"
 
  # 输出结构
  output_structure:
    - section: "基本信息"
      fields:
        - "会议主题"
        - "参会人员"
        - "会议时间"
        - "会议地点/链接"
 
    - section: "会议摘要"
      fields:
        - "一句话总结"
        - "主要议题"
 
    - section: "讨论要点"
      fields:
        - "议题1及结论"
        - "议题2及结论"
        - "未决事项"
 
    - section: "行动项"
      fields:
        - "任务描述"
        - "负责人"
        - "截止日期"
 
    - section: "下次会议"
      fields:
        - "待定事项"
        - "建议时间"
 
  # 风格
  style: "concise" # concise / detailed
 
# 后续行动
follow_up:
  # 自动创建任务
  auto_create_tasks:
    enabled: true
    integration: "linear" # 或 jira
 
  # 发送纪要给参会者
  distribute:
    enabled: true
    method: "email"
    # 自动提取参会者邮箱
    extract_attendees: true
 
  # 存档
  archive:
    enabled: true
    location: "confluence"
    space: "MEETING-NOTES"

10.5 企业安全与合规考量

在企业环境中部署 Hermes,安全和合规是不可妥协的底线。

# enterprise/security_compliance.yaml
name: "enterprise_security"
description: "企业安全与合规配置"
 
# 数据安全
data_security:
  # 数据本地化
  local_only: true
  # 禁止上传到云端
  cloud_upload: false
 
  # 加密
  encryption:
    at_rest: true # 静态加密
    in_transit: true # 传输加密
    key_management: "internal" # 内部密钥管理
 
  # 数据分类
  data_classification:
    levels:
      - "public" # 公开
      - "internal" # 内部
      - "confidential" # 机密
      - "restricted" # 受限
 
# 访问控制
access_control:
  # 身份认证
  authentication:
    method: "sso" # SSO / ldap / oauth
    provider: "okta"
    mfa_required: true
 
  # 授权
  authorization:
    rbac: true
    abac: true # 基于属性的访问控制
 
  # 审计日志
  audit_log:
    enabled: true
    log_all_queries: true
    log_all_actions: true
    retention: "1y"
 
# 合规
compliance:
  # GDPR
  gdpr:
    enabled: true
    data_retention_limit: "2y"
    right_to_be_forgotten: true
 
  # 等保 2.0(中国)
  mlps:
    enabled: true
    level: "三级"
 
  # SOC 2
  soc2:
    enabled: true
    type: "Type II"
 
# 模型安全
model_security:
  # 使用私有化部署的模型(如果有)
  private_model:
    enabled: false
    endpoint: "http://internal-llm:8000"
 
  # 敏感信息过滤
  pii_filter:
    enabled: true
    # 检测并脱敏
    patterns:
      - "身份证号"
      - "银行卡号"
      - "手机号"
      - "邮箱"
 
  # 输出审查
  output_filter:
    enabled: true
    # 禁止模型输出敏感信息
    block_pii_in_output: true

10.6 多用户共享实例配置

企业通常需要多个员工共享一个 Hermes 实例,同时保证数据隔离。

# enterprise/multi_user.yaml
name: "multi_user_setup"
description: "多用户共享实例配置"
 
# 用户管理
user_management:
  # 用户认证
  authentication:
    method: "sso"
    provider: "azure_ad" # 或 okta, google_workspace
 
  # 用户目录同步
  directory_sync:
    enabled: true
    sync_interval: "1h"
    auto_create_users: true
    auto_disable_leavers: true
 
# 数据隔离
isolation:
  # 用户级隔离
  user_level:
    enabled: true
    # 每个用户独立的数据空间
    data_per_user: true
    memory_per_user: true
    settings_per_user: true
 
  # 团队级隔离
  team_level:
    enabled: true
    # 团队共享知识库
    shared_kb_per_team: true
    # 团队级权限
    team_admin: true
 
# 资源分配
resource_quota:
  # 每个用户的资源配额
  per_user:
    max_concurrent_sessions: 3
    daily_api_calls: 1000
    storage_limit: "1GB"
 
  # 每个团队的资源配额
  per_team:
    daily_api_calls: 10000
    storage_limit: "10GB"
    max_members: 50
 
# 共享资源
shared_resources:
  # 企业级知识库(全员可读)
  enterprise_kb:
    enabled: true
    access: "all_users"
 
  # 共享技能
  shared_skills:
    enabled: true
    # 管理员审核后全员可用
    approval_required: true
 
  # 共享工具配置
  shared_tools:
    enabled: true
    # 如:数据库连接、API 凭证(只读)
    tools:
      - "db_readonly"
      - "internal_api"

11. 高阶技巧合集

11.1 技巧1:模型热切换(不同任务用不同模型)

不是所有任务都需要最强的模型。学会"按需选模",能帮你省下一大笔 API 费用。

# tips/model_routing.yaml
name: "smart_model_routing"
description: "智能模型路由配置"
 
# 模型路由规则
routing:
  # 简单任务用便宜模型
  - task_type: "summarize"
    model: "gpt-4o-mini"
    reason: "摘要任务对模型能力要求不高"
 
  - task_type: "classify"
    model: "gpt-4o-mini"
    reason: "分类是模型的基础能力"
 
  - task_type: "translate"
    model: "gpt-4o-mini"
    reason: "翻译任务 GPT-4o-mini 已足够优秀"
 
  # 复杂任务用强模型
  - task_type: "analyze"
    model: "gpt-4o"
    reason: "分析需要推理能力"
 
  - task_type: "code"
    model: "gpt-4o"
    reason: "代码生成需要高精度"
 
  - task_type: "creative"
    model: "gpt-4o"
    temperature: 0.8
    reason: "创意写作需要更强的理解和生成能力"
 
  # 超长文本用 Claude
  - condition: "input_tokens > 100000"
    model: "claude-sonnet"
    reason: "Claude 的上下文窗口更大"
 
  # 推理任务用 o1
  - task_type: "reasoning"
    model: "o1-mini"
    reason: "o1 在推理任务上表现更好"
 
# 动态降级
fallback:
  # 如果主模型超时或失败,降级到备选
  enabled: true
  chain:
    - "gpt-4o"
    - "gpt-4o-mini"
    - "claude-haiku"

命令行快速切换

# 查看当前模型
$ hermes config get model
 
# 临时切换模型(单次对话)
$ hermes chat --model gpt-4o "分析这份报告"
 
# 切换默认模型
$ hermes config set model gpt-4o-mini
 
# 查看各模型成本对比
$ hermes model compare --task summarize --input-length 1000

11.2 技巧2:记忆压缩与归档策略

随着时间推移,Hermes 的记忆库会越来越庞大。如果不管理,检索会变慢,成本会增加。

# tips/memory_management.yaml
name: "memory_optimization"
description: "记忆压缩与归档策略"
 
# 自动归档
auto_archive:
  enabled: true
 
  # 归档规则
  rules:
    # 规则1:30 天前的会话记忆归档
    - condition: "age > 30d AND access_count < 3"
      action: "archive"
      destination: "cold_storage"
 
    # 规则2:90 天未访问的记忆归档
    - condition: "last_access > 90d"
      action: "archive"
      destination: "cold_storage"
 
    # 规则3:重复或冗余记忆合并
    - condition: "similarity_to_other > 0.95"
      action: "merge"
      keep: "most_detailed"
 
# 记忆压缩
compression:
  enabled: true
 
  # 压缩策略
  strategies:
    # 摘要压缩
    - type: "summarize"
      # 长对话压缩为摘要
      trigger: "conversation_length > 20"
      model: "gpt-4o-mini"
 
    # 向量化压缩
    - type: "embedding"
      # 用向量表示替代原始文本
      trigger: "storage_size > 100MB"
      model: "text-embedding-3-small"
 
# 分层存储
tiered_storage:
  # 热存储:最近 7 天,内存中
  hot:
    retention: "7d"
    storage: "memory"
    max_size: "50MB"
 
  # 温存储:7-90 天,本地 SQLite
  warm:
    retention: "90d"
    storage: "sqlite"
    path: "./memory/warm.db"
 
  # 冷存储:90 天以上,压缩归档
  cold:
    storage: "file"
    path: "./memory/archive/"
    compression: "gzip"
    # 需要时可以从冷存储恢复
    recoverable: true

11.3 技巧3:技能链式调用

把多个 Skill 串联起来,形成更强大的复合能力。

# tips/skill_chaining.yaml
name: "skill_chain"
description: "技能链式调用示例"
 
# 链式工作流
chains:
  # 链1:研究 -> 写作 -> 发布
  research_to_publish:
    name: "研究到发布"
    steps:
      - skill: "web_search"
        output_var: "search_results"
      - skill: "summarize"
        input: "{{search_results}}"
        output_var: "summary"
      - skill: "write_article"
        input: "{{summary}}"
        params:
          style: "blog"
        output_var: "article"
      - skill: "proofread"
        input: "{{article}}"
        output_var: "final_article"
      - skill: "publish_to_wordpress"
        input: "{{final_article}}"
 
  # 链2:数据分析 -> 可视化 -> 报告
  data_to_report:
    name: "数据到报告"
    steps:
      - skill: "run_sql"
        query: "SELECT * FROM sales WHERE date > NOW() - INTERVAL '30 days'"
        output_var: "data"
      - skill: "analyze_data"
        input: "{{data}}"
        output_var: "insights"
      - skill: "generate_chart"
        input: "{{data}}"
        chart_type: "line"
        output_var: "chart_path"
      - skill: "generate_report"
        data: "{{data}}"
        insights: "{{insights}}"
        charts: ["{{chart_path}}"]
        output_var: "report"
 
# 条件分支
conditional_chains:
  - name: "智能客服处理"
    steps:
      - skill: "intent_detect"
        output_var: "intent"
      - branch:
          - condition: "intent == 'order_query'"
            chain: "order_lookup_chain"
          - condition: "intent == 'refund'"
            chain: "refund_chain"
          - condition: "intent == 'human'"
            chain: "escalate_chain"

11.4 技巧4:并行任务加速

当多个任务之间没有依赖关系时,可以并行执行,大幅缩短总时间。

# tips/parallel_execution.yaml
name: "parallel_tasks"
description: "并行任务执行配置"
 
# 并行配置
parallel:
  # 默认并行度
  default_workers: 4
 
  # 最大并发数
  max_concurrent: 10
 
# 并行工作流示例
workflows:
  # 同时收集多个数据源
  multi_source_collection:
    steps:
      - parallel:
          - skill: "fetch_hacker_news"
            output_var: "hn_data"
          - skill: "fetch_reddit"
            output_var: "reddit_data"
          - skill: "fetch_github"
            output_var: "github_data"
          - skill: "fetch_twitter"
            output_var: "twitter_data"
      - skill: "merge_data"
        inputs:
          - "{{hn_data}}"
          - "{{reddit_data}}"
          - "{{github_data}}"
          - "{{twitter_data}}"
        output_var: "all_data"
 
  # 同时为多个平台生成内容
  multi_platform_generation:
    steps:
      - skill: "select_topic"
        output_var: "topic"
      - parallel:
          - skill: "write_for_wechat"
            input: "{{topic}}"
            output_var: "wechat_article"
          - skill: "write_for_xiaohongshu"
            input: "{{topic}}"
            output_var: "xhs_article"
          - skill: "write_for_douyin"
            input: "{{topic}}"
            output_var: "douyin_script"
      - skill: "batch_publish"
        articles:
          wechat: "{{wechat_article}}"
          xiaohongshu: "{{xhs_article}}"
          douyin: "{{douyin_script}}"
 
# 批处理
batch_processing:
  enabled: true
  # 批量 API 调用(减少网络开销)
  api_batch_size: 20
  # 批处理超时
  batch_timeout: 60

11.5 技巧5:自定义工具开发

Hermes 内置了 47 个工具,但你可能需要开发自己的工具。

# custom_tools/my_tool.py
# 自定义工具开发示例
 
from hermes.tools import Tool, ToolParameter
 
class MyCustomTool(Tool):
    """
    自定义工具示例:汇率转换器
    """
 
    name = "currency_converter"
    description = "转换货币汇率"
 
    parameters = [
        ToolParameter(
            name="amount",
            type="number",
            description="金额",
            required=True
        ),
        ToolParameter(
            name="from_currency",
            type="string",
            description="源货币",
            required=True
        ),
        ToolParameter(
            name="to_currency",
            type="string",
            description="目标货币",
            required=True
        )
    ]
 
    async def execute(self, amount: float, from_currency: str, to_currency: str):
        """执行汇率转换"""
        # 调用汇率 API
        import aiohttp
 
        url = f"https://api.exchangerate-api.com/v4/latest/{from_currency}"
 
        async with aiohttp.ClientSession() as session:
            async with session.get(url) as response:
                data = await response.json()
                rate = data["rates"][to_currency]
                converted = amount * rate
 
                return {
                    "original_amount": amount,
                    "original_currency": from_currency,
                    "converted_amount": round(converted, 2),
                    "target_currency": to_currency,
                    "rate": rate,
                    "date": data["date"]
                }
 
# 注册工具
def register():
    return [MyCustomTool]

工具注册配置

# config.yaml 中的工具注册
tools:
  # 内置工具
  builtin:
    - "web_search"
    - "file_read"
    - "code_execution"
 
  # 自定义工具
  custom:
    - path: "./custom_tools/my_tool.py"
      enabled: true
    - path: "./custom_tools/company_api.py"
      enabled: true
 
  # MCP 工具
  mcp:
    servers:
      - command: "npx"
        args: ["-y", "@modelcontextprotocol/server-filesystem", "./data"]

11.6 技巧6:Webhook 集成

Webhook 让外部系统能够主动通知 Hermes,是实现实时响应的关键。

# tips/webhook_integration.yaml
name: "webhook_setup"
description: "Webhook 集成配置"
 
# Hermes 作为 Webhook 接收端
incoming_webhooks:
  # GitHub Webhook
  github:
    endpoint: "/webhook/github"
    secret: "${GITHUB_WEBHOOK_SECRET}"
    events:
      - "pull_request"
      - "issues"
      - "push"
    handlers:
      pull_request:
        action: "trigger_code_review"
      issues:
        action: "create_support_ticket"
 
  # Stripe Webhook(支付事件)
  stripe:
    endpoint: "/webhook/stripe"
    secret: "${STRIPE_WEBHOOK_SECRET}"
    events:
      - "payment_intent.succeeded"
      - "invoice.payment_failed"
    handlers:
      payment_intent.succeeded:
        action: "send_welcome_email"
      invoice.payment_failed:
        action: "notify_customer_and_retry"
 
  # 自定义 Webhook
  custom:
    endpoint: "/webhook/custom"
    auth:
      type: "api_key"
      header: "X-API-Key"
    handlers:
      default:
        action: "process_custom_event"
 
# Hermes 作为 Webhook 发送端
outgoing_webhooks:
  # 通知外部系统
  notifications:
    - name: "slack_notification"
      url: "${SLACK_WEBHOOK_URL}"
      events: ["task_completed", "alert_triggered"]
 
    - name: "zapier_trigger"
      url: "${ZAPIER_WEBHOOK_URL}"
      events: ["new_lead", "order_created"]

11.7 技巧7:日志分析与调试

当 Hermes 出现问题时,日志是你最好的朋友。

# tips/logging_config.yaml
name: "advanced_logging"
description: "高级日志配置"
 
# 日志级别
logging:
  # 全局级别
  level: "INFO"
 
  # 按模块设置
  modules:
    "hermes.agent": "DEBUG"
    "hermes.memory": "DEBUG"
    "hermes.tools": "INFO"
    "hermes.sandbox": "WARNING"
 
  # 输出格式
  format: "json" # 或 "text"
 
  # 输出目标
  outputs:
    - type: "console"
      level: "INFO"
    - type: "file"
      path: "./logs/hermes.log"
      level: "DEBUG"
      rotation: "daily"
      max_files: 30
    - type: "file"
      path: "./logs/hermes.error.log"
      level: "ERROR"
      rotation: "daily"
 
# 调试模式
debug:
  # 显示详细的工具调用过程
  show_tool_calls: true
 
  # 显示 LLM 的完整输入输出
  show_llm_io: false # 生产环境建议关闭,可能包含敏感信息
 
  # 显示记忆检索过程
  show_memory_retrieval: true
 
  # 性能分析
  profiling:
    enabled: true
    # 记录每个步骤的耗时
    track_timing: true
    # 慢操作阈值
    slow_threshold_ms: 1000

常用调试命令

# 查看实时日志
$ hermes logs --follow
 
# 查看特定任务的日志
$ hermes logs --task-id abc123
 
# 查看错误日志
$ hermes logs --level ERROR --last 50
 
# 调试模式运行(显示详细信息)
$ hermes run --debug
 
# 性能分析
$ hermes profile --command "execute my_skill"
 
# 检查配置
$ hermes doctor
# 输出示例:
# ✓ Python version: 3.11
# ✓ Hermes version: 1.2.3
# ✓ Database connection: OK
# ✓ API Key (OpenAI): Valid
# ⚠ Memory usage: 85% (consider archiving)
# ✗ Sandbox Docker: Not running (docker service not found)

11.8 技巧8:性能监控与优化

# tips/performance_monitoring.yaml
name: "performance_monitor"
description: "性能监控与优化"
 
# 监控指标
metrics:
  # 响应时间
  response_time:
    enabled: true
    percentiles: [50, 95, 99]
 
  # 吞吐量
  throughput:
    enabled: true
    # 每秒请求数
    rps: true
 
  # 错误率
  error_rate:
    enabled: true
    # 按类型分类
    by_type: true
 
  # 资源使用
  resources:
    cpu: true
    memory: true
    disk: true
    network: true
 
# 告警
alerts:
  - condition: "response_time_p95 > 5000"
    message: "响应时间过高:{{value}}ms"
 
  - condition: "error_rate > 5%"
    message: "错误率过高:{{value}}%"
 
  - condition: "memory_usage > 90%"
    message: "内存使用率过高:{{value}}%"
 
# 自动优化
auto_optimization:
  enabled: true
 
  # 自动扩容
  scaling:
    enabled: true
    # 并发过多时增加 worker
    max_workers: 20
    scale_up_threshold: 80 # CPU 使用率
    scale_down_threshold: 20
 
  # 缓存优化
  caching:
    enabled: true
    # 自动缓存高频查询
    auto_cache:
      enabled: true
      min_frequency: 3 # 3 次以上查询自动缓存
      ttl: 3600
 
  # 模型降级
  model_fallback:
    enabled: true
    # 强模型超时时降级到快模型
    timeout_threshold: 10000 # 10 秒
    fallback_model: "gpt-4o-mini"

本章小结

恭喜你读完了第十二册!这一章的信息量非常大,让我们回顾一下你学到了什么。

沙箱配置与安全调优:

你学会了 Hermes 的四级安全沙箱体系,理解了如何为不同任务配置合适的安全等级。你掌握了命令审批机制的自定义方法,学会了设置信任级别和生产环境安全清单。最重要的是,你知道了如何安全地运行未知来源的代码——先用 analyze 静态分析,再用 Level 0 沙箱隔离执行。

语音交互高阶玩法:

你了解了多种 STT 和 TTS 引擎的选择策略,学会了配置语音活动检测(VAD)和唤醒词。你掌握了多语言语音切换的方法,理解了语音触发工作流的原理。你还学会了为车载和穿戴设备场景优化语音配置。纯语音驱动的投研助手案例,展示了"动口不动手"的 AI 交互体验。

六大实战案例:

  1. AI 投研流水线:从多源数据收集到清洗、分析、报告生成和推送的完整自动化流程,每日成本仅 $0.1-0.5。

  2. 内容自动化工厂:选题 Agent、写作 Agent、审校 Agent 的多 Agent 协作系统,支持公众号、小红书、抖音的多平台内容自动生成。

  3. 代码质量守护者:Git Hook 集成、PR 自动审查、安全漏洞扫描、CI/CD 集成的完整 DevOps 方案。

  4. 个人知识管理系统:RSS/邮件/书签的自动收集、智能分类、知识图谱构建、与 Notion/Obsidian 的集成。

  5. 客服机器人:知识库构建、多轮对话管理、人机转接、满意度收集、多渠道部署的 7×24 智能客服方案。

  6. 数据监控与告警:网站可用性、价格变动、竞品动态、异常检测的监控体系,以及加密货币价格监控的完整 Telegram Bot 案例。

企业级应用场景:

你了解了企业内部知识库助手、数据库查询助手、项目管理自动化、会议纪要生成等企业级应用的配置方案。你掌握了企业安全与合规的核心考量,以及多用户共享实例的隔离配置。

八大高阶技巧:

模型热切换帮你节省成本,记忆压缩与归档保持系统轻量,技能链式调用构建复合能力,并行任务加速提升效率,自定义工具开发扩展边界,Webhook 集成实现实时响应,日志分析帮你快速排障,性能监控确保系统稳定。

下一步建议

本章的六个实战案例不需要一次性全部搭建。选择你最感兴趣或最急需的那个,从最小可用版本(MVP)开始,逐步迭代完善。记住,最好的自动化系统不是一次性设计出来的,而是在使用过程中不断打磨出来的。

如果你在搭建过程中遇到问题,第十五册「社区生态与资源」提供了丰富的社区支持渠道。记住:遇到困难不要独自纠结,社区里有很多热心的玩家愿意帮忙。