实战:用定时任务自动化一切
Hermes 实战教程第8篇:定时任务自动化。让 AI 按时干活。
实战:用定时任务自动化一切
上一期我们聊了每日简报机器人,今天来点更硬核的——用 Cron 定时任务把重复劳动全丢给 Hermes。官方文档这次给了五个实战套路,我挑最实用的四个讲,保证看完你就能上手。
先记住一个关键点
Cron 任务跑在全新的会话里,它不记得你当前聊天的任何内容。所以你的提示词必须自包含——把 agent 需要知道的一切都写进去。就像给一个失忆的同事留便条,信息不全他就懵了。
套路一:网站变更监控
想知道某个网页什么时候更新了?让脚本干脏活,agent 干脑力活。
先建个监控脚本:
mkdir -p ~/.hermes/scripts
然后写个 Python 脚本(抓取网页、算哈希、对比上次状态),脚本输出 CHANGE DETECTED 或 NO_CHANGE。接着设置定时任务:
/cron add "every 1h" "If the script output says CHANGE DETECTED, summarize what changed on the page and why it might matter. If it says NO_CHANGE, respond with just [SILENT]." --script ~/.hermes/scripts/watch-site.py --name "Pricing monitor" --deliver telegram
这里有个 [SILENT] 小技巧:让 agent 没事就回 [SILENT],Cron 投递会自动静默,你只在真正有变化时才收到通知——半夜不会被垃圾消息吵醒。
套路二:每周自动报告
每周一早上 9 点,自动搜集 AI 新闻、GitHub 趋势、Hacker News 热帖,整理成摘要发给你:
/cron add "0 9 * * 1" "Generate a weekly report covering:
1. Search the web for the top 5 AI news stories from the past week
2. Search GitHub for trending repositories in the 'machine-learning' topic
3. Check Hacker News for the most discussed AI/ML posts
Format as a clean summary with sections for each source. Include links.
Keep it under 500 words — highlight only what matters." --name "Weekly AI digest" --deliver telegram
0 9 * * 1 是标准 cron 表达式:每周一 9:00。命令行党也可以用 hermes cron create 加同样的参数。
套路三:GitHub 仓库盯梢
监控仓库的新 issue、PR 和 release:
/cron add "every 6h" "Check the GitHub repository NousResearch/hermes-agent for:
- New issues opened in the last 6 hours
- New PRs opened or merged in the last 6 hours
- Any new releases
Use the terminal to run gh commands:
gh issue list --repo NousResearch/hermes-agent --state open --json number,title,author,createdAt --limit 10
gh pr list --repo NousResearch/hermes-agent --state all --json number,title,author,createdAt,mergedAt --limit 10
Filter to only items from the last 6 hours. If nothing new, respond with [SILENT].
Otherwise, provide a concise summary of the activity." --name "Repo watcher" --deliver discord
注意提示词里写死了具体的 gh 命令——因为 cron agent 没有历史对话,必须把每一步都交代清楚。持久记忆(MEMORY.md)会加载,但别指望它记住关键细节。
套路四:数据采集管道
定时抓数据存文件,让 agent 分析趋势。脚本负责采集,agent 负责解读。比如每 30 分钟抓一次加密货币价格,追加到 history.jsonl,然后让 agent 对比历史数据、发现异常波动。
不需要 LLM 的两种零 Token 方案
如果脚本已经能产出最终消息(比如内存告警、磁盘告警),别浪费 token 给 LLM:
- 周期性看门狗:用纯脚本 cron 任务(
no_agent=True),调度器照跑,不调 LLM。直接在聊天里让 Hermes 帮你配就行。 - 一次性脚本输出:如果脚本本来就在跑(CI 步骤、部署脚本),用
hermes send把 stdout 或文件直接管道到 Telegram / Discord,连 cron 都不用建。
写在最后
这四个套路覆盖了监控、报告、盯梢、采集四大场景。核心心法就一句:脚本干机械活,agent 干思考活,提示词写完整。去翻翻官方文档的完整参考,动手配一个属于你的自动化任务吧。
📖 官方文档
本文根据 Hermes Agent 官方文档编写,原文见:官方文档 › guides/automate-with-cron