字节笔记本
2026年5月16日
Hermes Agent 脚本定时任务:无需 LLM 的纯脚本 Cron 作业
Hermes Agent 提供了一种纯脚本的 Cron 作业模式(no-agent mode),让你可以在不调用任何 LLM 的情况下运行定时任务。脚本按计划执行,stdout 输出会直接投递到 Telegram / Discord / Slack / Signal 等消息平台,适用于内存监控、磁盘告警、CI 通知、定期指标上报等轻量级自动化场景。
核心概念
当你已经明确知道要发送什么消息时,不需要 Agent 来推理——你只需要一个脚本按计划运行,其输出(如果有)直接送达消息平台。Hermes 将此称为 no-agent 模式,即 Cron 系统减去 LLM。
┌──────────────────┐ ┌──────────────────┐
│ scheduler tick │ every │ run script │
│ (every N minutes)│ ──────▶ │ (bash or python) │
└──────────────────┘ └──────────────────┘
│
│ stdout
▼
┌──────────────────┐
│ delivery router │
│ (telegram/disc…) │
└──────────────────┘- 无 LLM 调用。 零 token 消耗,零 Agent 循环,零模型支出。
- 脚本即任务。 脚本决定是否告警。有输出则发送消息,无输出则静默通过。
- Bash 或 Python。
.sh/.bash文件以/bin/bash执行;其他扩展名以当前 Python 解释器执行。~/.hermes/scripts/下的脚本均可使用。 - 共享调度器。 与 LLM 驱动的任务共用
cronjob系统——暂停、恢复、列表、日志、投递目标等功能完全一致。
适用场景
使用 no-agent 模式的典型场景:
- 内存 / 磁盘 / GPU 监控。 每 5 分钟运行一次,仅在超过阈值时告警。
- CI 钩子。 部署完成 → 发送 commit SHA;构建失败 → 发送最后 100 行日志。
- 定期指标。 "每天早上 9 点获取 Stripe 收入"——一次简单的 API 调用加格式化输出。
- 外部事件轮询。 检查 API 状态变化并告警。
- 心跳检测。 每 N 分钟向仪表板发送心跳,证明主机存活。
当你需要 Agent 来决定说什么时(如总结长文档、从信息流中挑选有趣条目、起草人性化消息),请使用普通(LLM 驱动的)Cron 任务。no-agent 模式适用于脚本输出本身就是最终消息的场景。
从聊天创建
no-agent 模式的真正优势在于:Agent 本身可以为你设置监控——无需编辑器、无需终端、无需记忆 CLI 参数。你只需描述需求,Hermes 编写脚本、设置计划并告知触发时间。
对话示例
You: ping me on telegram if RAM is over 85% every 5 minutes
Hermes: (writes
~/.hermes/scripts/memory-watchdog.sh, then callscronjob(...)withno_agent=true)Set up. Runs every 5 min, alerts Telegram only when RAM is over 85%. Script:
memory-watchdog.sh. Job ID:abc123.
底层实现中,Agent 做了两次工具调用:
# 1. Write the check script
write_file(
path="~/.hermes/scripts/memory-watchdog.sh",
content='''#!/usr/bin/env bash
ram_pct=$(free | awk '/^Mem:/ {printf "%d", $3 * 100 / $2}')
if [ "$ram_pct" -ge 85 ]; then
echo "RAM ${ram_pct}% on $(hostname)"
fi
# Empty stdout = silent tick; no message sent.
''',
)
# 2. Schedule it — no_agent=True skips the LLM on every tick
cronjob(
action="create",
schedule="every 5m",
script="memory-watchdog.sh",
no_agent=True,
deliver="telegram",
name="memory-watchdog",
)此后每次触发都是免费的:调度器运行脚本,将非空的 stdout 发送到 Telegram,整个过程不涉及任何模型调用。
Agent 自动判断逻辑
当你用"当 X 时提醒我"或"每 N 分钟检查 Y 并在 Z 时通知我"这样的表述时,Hermes 的 cronjob 工具描述会指示它在消息内容完全由脚本决定时自动选择 no_agent=True。当请求需要推理时(如"总结新 issue"、"挑选最有趣的头条"、"起草一条友好的提醒"),它会回退到 LLM 驱动的模式。
你无需手动指定 --no-agent,只需描述期望行为即可。
从聊天管理监控任务
Agent 可以像创建任务一样暂停、恢复、编辑和删除任务:
You: stop the memory watchdog for tonight
Hermes: (calls
cronjob(action='pause', job_id='abc123'))Paused. Resume with "turn it back on" or via
hermes cron resume abc123.
You: change it to every 15 minutes
Hermes: (calls
cronjob(action='update', job_id='abc123', schedule='every 15m'))
完整的生命周期(create / list / update / pause / resume / run-now / remove)都可由 Agent 操作,无需学习任何 CLI 命令。
从 CLI 创建
更喜欢命令行?CLI 方式只需三条命令即可完成:
# 1. Write your script
cat > ~/.hermes/scripts/memory-watchdog.sh <<'EOF'
#!/usr/bin/env bash
# Alert when RAM usage is over 85%. Silent otherwise.
RAM_PCT=$(free | awk '/^Mem:/ {printf "%d", $3 * 100 / $2}')
if [ "$RAM_PCT" -ge 85 ]; then
echo "⚠ RAM ${RAM_PCT}% on $(hostname)"
fi
# Empty stdout = silent run; no message sent.
EOF
chmod +x ~/.hermes/scripts/memory-watchdog.sh
# 2. Schedule it
hermes cron create "every 5m" \
--no-agent \
--script memory-watchdog.sh \
--deliver telegram \
--name "memory-watchdog"
# 3. Verify
hermes cron list
hermes cron run <job_id> # fire it once to test就这么简单。无需 prompt,无需 skill,无需模型。
脚本输出与消息投递的映射
| 脚本行为 | 结果 |
|---|---|
| Exit 0,stdout 非空 | stdout 原样投递 |
| Exit 0,stdout 为空 | 静默通过——不发送消息 |
Exit 0,stdout 最后一行包含 {"wakeAgent": false} | 静默通过(与 LLM 任务共享的门控逻辑) |
| 非零退出码 | 投递错误告警(确保故障监控不会静默失败) |
| 脚本超时 | 投递错误告警 |
"输出为空则静默"的行为是经典监控模式的关键:脚本可以每分钟运行,但频道只在真正需要关注时才收到消息。
脚本规则
脚本必须放在 ~/.hermes/scripts/ 目录下。此规则在任务创建时和运行时均会强制执行——绝对路径、~/ 展开和路径遍历模式(../)都会被拒绝。该目录与 LLM 任务使用的预检查脚本门控共享。
解释器选择依据文件扩展名:
| 扩展名 | 解释器 |
|---|---|
.sh, .bash | /bin/bash |
| 其他 | sys.executable(当前 Python) |
Hermes 故意不遵循 #!/... shebang——保持解释器集合明确且精简,可以减少调度器信任的攻击面。
调度语法
与其他所有 Cron 任务相同:
hermes cron create "every 5m" # interval
hermes cron create "every 2h"
hermes cron create "0 9 * * *" # standard cron: 9am daily
hermes cron create "30m" # one-shot: run once in 30 minutes完整语法请参阅 Cron 功能参考文档。
投递目标
--deliver 参数支持 gateway 已知的所有目标。常用格式:
--deliver telegram # platform home channel
--deliver telegram:-1001234567890 # specific chat
--deliver telegram:-1001234567890:17585 # specific Telegram forum topic
--deliver discord:#ops
--deliver slack:#engineering
--deliver signal:+15551234567
--deliver local # just save to ~/.hermes/cron/output/对于 bot-token 平台(Telegram、Discord、Slack、Signal、SMS、WhatsApp),脚本运行时无需运行中的 gateway——工具直接使用 ~/.hermes/.env / ~/.hermes/config.yaml 中已有的凭据调用各平台的 REST 端点。
编辑与生命周期管理
hermes cron list # see all jobs
hermes cron pause <job_id> # stop firing, keep definition
hermes cron resume <job_id>
hermes cron edit <job_id> --schedule "every 10m" # adjust cadence
hermes cron edit <job_id> --agent # flip to LLM mode
hermes cron edit <job_id> --no-agent --script … # flip back
hermes cron remove <job_id> # delete it所有对 LLM 任务有效的操作(暂停、恢复、手动触发、更改投递目标)同样适用于 no-agent 任务。
完整示例:磁盘空间告警
cat > ~/.hermes/scripts/disk-alert.sh <<'EOF'
#!/usr/bin/env bash
# Alert when / or /home is over 90% full.
THRESHOLD=90
df -h / /home 2>/dev/null | awk -v t="$THRESHOLD" '
NR > 1 && $5+0 >= t {
printf "⚠ Disk %s full on %s\n", $5, $6
}
'
EOF
chmod +x ~/.hermes/scripts/disk-alert.sh
hermes cron create "*/15 * * * *" \
--no-agent \
--script disk-alert.sh \
--deliver telegram \
--name "disk-alert"当两个文件系统使用率均低于 90% 时静默;当任一文件系统超过阈值时,每个超限文件系统输出一行告警。
与其他模式的对比
| 方案 | 运行内容 | 适用场景 |
|---|---|---|
cronjob --no-agent(本文) | 你的脚本在 Hermes 调度器上运行 | 不需要推理的周期性监控 / 告警 / 指标 |
cronjob(默认,LLM 模式) | Agent + 可选预检查脚本 | 消息内容需要对数据进行推理 |
OS cron + curl 到 Webhook 订阅 | 你的脚本在 OS 调度器上运行 | 当 Hermes 本身可能不可用时(你监控的对象) |
对于必须在 gateway 宕机时也能触发的关键系统健康监控,请使用 OS 级别的 cron 配合 curl 调用 Hermes Webhook 订阅(或任何外部告警端点)——这些作为独立 OS 进程运行,不依赖 Hermes 是否在线。当被监控对象是外部系统时,Hermes 内置调度器是正确选择。
相关资源
- Automate Anything with Cron — LLM 驱动的 Cron 模式
- Scheduled Tasks (Cron) reference — 完整的调度语法、生命周期、投递路由
- Webhook Subscriptions — 面向外部调度器的即发即弃 HTTP 入口
- Gateway Internals — 投递路由器内部实现