Hermes 实战教程 · 第16篇2026/8/9· Easy Understand Hermes Agent
实战:纯脚本定时任务
Hermes 实战教程第16篇:纯脚本定时任务。不用 AI 也能定时跑。
實戰:純腳本定時任務
上一期我們聊了每日簡報機器人,今天來點更硬核的——純腳本定時任務。啥意思?就是讓 Hermes 定時跑一個腳本,把結果餵給 AI 分析,或者乾脆連 AI 都不用,腳本自己就能搞定一切。
先搞懂核心概念
定時任務跑在一個全新的會話裡,它不記得你之前聊過啥。所以你的提示詞必須自包含——把該說的全寫進去,別指望它「猜」你的意思。
兩個零 Token 的騷操作
如果你根本不需要 AI 參與,有兩個省錢路子:
- 循環看門狗:腳本已經能生成完整訊息(比如記憶體告警、磁碟告警),用
no_agent=True的純腳本任務就行。在聊天裡直接讓 Hermes 幫你建,cronjob工具會自動判斷該不該帶 AI。 - 一次性推送:腳本已經在跑了(CI 步驟、部署腳本裡),用
hermes send把 stdout 或檔案直接怼到 Telegram / Discord,連定時任務都不用建。
模式一:網站變更監控
這是 script 參數的殺手級用法。腳本先跑,stdout 變成 AI 的上下文。腳本乾機械活(抓取、比對),AI 乾腦力活(這變化有意思嗎?)。
先建監控腳本:
import hashlib, json, os, urllib.request
URL = "https://example.com/pricing"
STATE_FILE = os.path.expanduser("~/.hermes/scripts/.watch-site-state.json")
req = urllib.request.Request(URL, headers={"User-Agent": "Hermes-Monitor/1.0"})
content = urllib.request.urlopen(req, timeout=30).read().decode()
current_hash = hashlib.sha256(content.encode()).hexdigest()
prev_hash = None
if os.path.exists(STATE_FILE):
with open(STATE_FILE) as f:
prev_hash = json.load(f).get("hash")
with open(STATE_FILE, "w") as f:
json.dump({"hash": current_hash, "url": URL}, f)
if prev_hash and prev_hash != current_hash:
print(f"CHANGE DETECTED on {URL}")
print(f"Previous hash: {prev_hash}")
print(f"Current hash: {current_hash}")
print(f"\nCurrent content (first 2000 chars):\n{content[:2000]}")
else:
print("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] 是靜默標記。沒變化時 AI 只回這個,系統就不推送——安靜時段不騷擾你,有變化才響。
模式二:每週報告
每週一早上 9 點自動彙總各路資訊:
/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 點。
模式三: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
注意提示詞裡寫明了具體命令——因為定時任務沒有上次對話的記憶,得把每一步都交代清楚。持久記憶(MEMORY.md)會載入,但別指望它記關鍵細節。
模式四:資料採集管道
定時抓資料存檔案,讓 AI 分析趨勢。腳本負責採集,AI 負責解讀——完美分工。
import json, os, urllib.request
from datetime import datetime
DATA_DIR = os.path.expanduser("~/.hermes/data/prices")
os.makedirs(DATA_DIR, exist_ok=True)
url = "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,ethereum&vs_currencies=usd"
data = json.loads(urllib.request.urlopen(url, timeout=30).read())
entry = {"timestamp": datetime.now().isoformat(), "prices": data}
history_file = os.path.join(DATA_DIR, "history.jsonl")
with open(history_file, "a") as f:
f.write(json.dumps(entry) + "\n")
print(f"Collected prices at {entry['timestamp']}: BTC ${data['bitcoin']['usd']}, ETH ${data['ethereum']['usd']}")
然後讓 AI 定期分析這些歷史資料,找出趨勢和異常。
小結
純腳本定時任務的核心思路:腳本乾重活,AI 乾判斷。配合 [SILENT] 靜默機制,你只會在真正需要關注的時候收到通知。動手試試吧,讓 Hermes 幫你盯著那些不想盯的事。
📖 官方文档
本文根据 Hermes Agent 官方文档编写,原文见:官方文档 › guides/automate-with-cron