计划任务(Cron)
使用自然语言或 cron 表达式安排任务自动运行。Hermes 通过带有操作风格 cronjob 工具来管理 cron,而不是单独的 schedule/list/remove 工具。
Cron 现在可以做什么
Cron 作业可以:
- 安排一次性或循环任务
- 暂停、恢复、编辑、触发和删除作业
- 附加零个、一个或多个 skills 到作业
- 将结果传递回原始聊天、本地文件或配置的 platform 目标
- 在具有正常静态工具列表的新鲜 agent 会话中运行
Cron 运行的会话不能递归创建更多 cron 作业。Hermes 在 cron 执行内部禁用 cron 管理工具,以防止失控的调度循环。
创建计划任务
在聊天中使用 /cron
/cron add 30m "Remind me to check the build"
/ron add "every 2h" "Check server status"
/ron add "every 1h" "Summarize new feed items" --skill blogwatcher
/ron add "every 1h" "Use both skills and combine the result" --skill blogwatcher --skill find-nearby
从独立 CLI
hermes cron create "every 2h" "Check server status"
hermes cron create "every 1h" "Summarize new feed items" --skill blogwatcher
hermes cron create "every 1h" "Use both skills and combine the result" \
--skill blogwatcher \
--skill find-nearby \
--name "Skill combo"
通过自然对话
正常询问 Hermes:
Every morning at 9am, check Hacker News for AI news and send me a summary on Telegram.
Hermes 会在内部使用统一的 cronjob 工具。
Skill 支持的 cron 作业
Cron 作业可以在运行提示之前加载一个或多个 skills。
单个 skill
cronjob(
action="create",
skill="blogwatcher",
prompt="Check the configured feeds and summarize anything new.",
schedule="0 9 * * *",
name="Morning feeds",
)
多个 skills
Skills 按顺序加载。提示成为叠加在这些 skills 之上的任务指令。
cronjob(
action="create",
skills=["blogwatcher", "find-nearby"],
prompt="Look for new local events and interesting nearby places, then combine them into one short brief.",
schedule="every 6h",
name="Local brief",
)
当您希望计划的 agent 继承可重用的工作流而不必将完整 skill 文本塞入 cron 提示本身时,这很有用。
编辑作业
您不需要仅仅为了更改作业而删除和重新创建作业。
聊天
/cron edit <job_id> --schedule "every 4h"
/ron edit <job_id> --prompt "Use the revised task"
/ron edit <job_id> --skill blogwatcher --skill find-nearby
/cron edit <job_id> --remove-skill blogwatcher
/ron edit <job_id> --clear-skills
独立 CLI
hermes cron edit <job_id> --schedule "every 4h"
hermes cron edit <job_id> --prompt "Use the revised task"
hermes cron edit <job_id> --skill blogwatcher --skill find-nearby
hermes cron edit <job_id> --add-skill find-nearby
hermes cron edit <job_id> --remove-skill blogwatcher
hermes cron edit <job_id> --clear-skills
注意:
- 重复的
--skill替换作业的附加 skill 列表 --add-skill追加到现有列表而不替换--remove-skill移除特定的附加 skills--clear-skills移除所有附加的 skills
生命周期操作
Cron 作业现在具有比 create/remove 更完整的生命周期。
聊天
/cron list
/cron pause <job_id>
/ron resume <job_id>
/ron run <job_id>
/ron remove <job_id>
独立 CLI
hermes cron list
hermes cron pause <job_id>
hermes cron resume <job_id>
hermes cron run <job_id>
hermes cron remove <job_id>
hermes cron status
hermes cron tick
功能:
pause— 保留作业但停止调度它resume— 重新启用作业并计算下一次未来运行run— 在下一个调度器 tick 时触发作业remove— 完全删除它
工作原理
Cron 执行由 gateway 守护进程处理。 Gateway 每 60 秒 tick 一次调度器,在隔离的 agent 会话中运行任何到期的作业。
hermes gateway install # 安装为用户服务
sudo hermes gateway install --system # Linux:开机时间系统服务用于服务器
hermes gateway # 或在前台运行
hermes cron list
hermes cron status
Gateway 调度器行为
在每次 tick,Hermes:
- 从
~/.hermes/cron/jobs.json加载作业 - 检查
next_run_at与当前时间的比较 - 为每个到期的作业启动一个新的
AIAgent会话 - 可选地将一个或多个附加的 skills 注入那个新会话
- 运行提示直到完成
- 传递最终响应
- 更新运行元数据和下一次计划时间
文件锁 ~/.hermes/cron/.tick.lock 防止重叠的调度器 tick 双运行同一批作业。
传递选项
安排作业时,您指定输出到哪里:
| 选项 | 描述 | 示例 |
|---|---|---|
"origin" | 返回创建作业的位置 | 消息平台上的默认设置 |
"local" | 仅保存到本地文件(~/.hermes/cron/output/) | CLI 上的默认设置 |
"telegram" | Telegram 主页频道 | 使用 TELEGRAM_HOME_CHANNEL |
"telegram:123456" | 按 ID 的特定 Telegram 聊天 | 直接传递 |
"telegram:-100123:17585" | 特定 Telegram 主题 | chat_id:thread_id 格式 |
"discord" | Discord 主页频道 | 使用 DISCORD_HOME_CHANNEL |
"discord:#engineering" | 特定 Discord 频道 | 按频道名称 |
"slack" | Slack 主页频道 | |
"whatsapp" | WhatsApp 主页 | |
"signal" | Signal | |
"matrix" | Matrix 主页房间 | |
"mattermost" | Mattermost 主页频道 | |
"email" | ||
"sms" | 通过 Twilio 的 SMS | |
"homeassistant" | Home Assistant | |
"dingtalk" | DingTalk | |
"feishu" | Feishu/Lark | |
"wecom" | WeCom | |
"weixin" | 微信(WeChat) | |
"bluebubbles" | BlueBubbles(iMessage) | |
"qqbot" | QQ Bot(腾讯 QQ) |
Agent 的最终响应自动传递。您不需要在 cron 提示中调用 send_message。
响应包装
默认情况下,传递的 cron 输出带有页眉和页脚,以便接收者知道它来自计划任务:
Cronjob Response: Morning feeds
-------------
<agent output here>
Note: The agent cannot see this message, and therefore cannot respond to it.
要在没有包装器的情况下传递原始 agent 输出,请设置 cron.wrap_response 为 false:
# ~/.hermes/config.yaml
cron:
wrap_response: false
静默抑制
如果 agent 的最终响应以 [SILENT] 开头,则完全抑制传递。输出仍然保存到本地以供审计(~/.hermes/cron/output/),但不发送到传递目标。
这对于仅在出现问题时才报告的监控作业很有用:
Check if nginx is running. If everything is healthy, respond with only [SILENT].
Otherwise, report the issue.
失败的作业始终传递,不管 [SILENT] 标记 — 仅成功的运行可以被抑制。
脚本超时
预运行脚本(通过 script 参数附加)默认超时为 120 秒。如果您的脚本需要更长时间 — 例如,包含避免机器人式时间模式的随机延迟 — 您可以增加此时间:
# ~/.hermes/config.yaml
cron:
script_timeout_seconds: 300 # 5 分钟
或设置 HERMES_CRON_SCRIPT_TIMEOUT 环境变量。解析顺序是:env var → config.yaml → 120s 默认。
Provider 恢复
Cron 作业继承您配置的备用 provider 和凭证池轮换。如果主要 API 密钥被速率限制或 provider 返回错误,cron agent 可以:
- 回退到备用 provider 如果您在
config.yaml中配置了fallback_providers(或遗留的fallback_model) - 轮换到凭证池中的下一个凭证 如果您在同一 provider 的凭证池中
这意味着在高峰时段或高频运行的 cron 作业更有弹性 — 单个速率限制的密钥不会导致整个运行失败。
调度格式
Agent 的最终响应自动传递 — 您不需要在 cron 提示中包含 send_message。如果 cron 运行调用 send_message 到调度器已经传递到的确切目标,Hermes 会跳过该重复发送并告诉模型将面向用户的内容放在最终响应中。仅对其他或不同目标使用 send_message。
相对延迟(一次性)
30m → 30分钟后运行一次
2h → 2小时后运行一次
1d → 1天后运行一次
间隔(循环)
every 30m → 每 30 分钟
every 2h → 每 2 小时
every 1d → 每天
Cron 表达式
0 9 * * * → 每天早上 9:00
0 9 * * 1-5 → 工作日早上 9:00
0 */6 * * * → 每 6 小时
30 8 1 * * → 每月 1 日早上 8:30
0 0 * * 0 → 每周日午夜
ISO 时间戳
2026-03-15T09:00:00 → 2026 年 3 月 15 日早上 9:00 一次性
重复行为
| 调度类型 | 默认重复 | 行为 |
|---|---|---|
一次性(30m、时间戳) | 1 | 运行一次 |
间隔(every 2h) | 永远 | 运行直到被移除 |
| Cron 表达式 | 永远 | 运行直到被移除 |
您可以覆盖它:
cronjob(
action="create",
prompt="...",
schedule="every 2h",
repeat=5,
)
以编程方式管理作业
Agent-facing API 是一个工具:
cronjob(action="create", ...)
cronjob(action="list")
cronjob(action="update", job_id="...")
cronjob(action="pause", job_id="...")
cronjob(action="resume", job_id="...")
cronjob(action="run", job_id="...")
cronjob(action="remove", job_id="...")
对于 update,传递 skills=[] 以移除所有附加的 skills。
作业存储
作业存储在 ~/.hermes/cron/jobs.json。作业运行的输出保存到 ~/.hermes/cron/output/{job_id}/{timestamp}.md。
存储使用原子文件写入,因此中断的写入不会留下部分写入的作业文件。
独立提示仍然重要
Cron 作业在完全新鲜 agent 会话中运行。提示必须包含 agent 需要的所有内容,这些内容不是已经由附加的 skills 提供。
不好: "Check on that server issue"
好: "SSH into server 192.168.1.100 as user 'deploy', check if nginx is running with 'systemctl status nginx', and verify https://example.com returns HTTP 200."
安全
计划任务提示在创建和更新时扫描提示注入和凭证泄露模式。包含不可见 Unicode 技巧、SSH 后门尝试或明显密钥泄露有效载荷的提示被阻止。