Appearance
自动化总览
OpenClaw 提供三种自动化机制,让 Agent 无需用户手动触发就能完成任务:
三种自动化方式
| 机制 | 适用场景 |
|---|---|
| Hooks | 响应 Agent 内部事件(命令、会话、消息) |
| Cron 定时任务 | 定时或周期性执行(每天早报、定时提醒) |
| Webhook | 外部系统触发(邮件到达、GitHub 推送) |
快速对比
Hooks(内部事件钩子)
当 OpenClaw 内部发生某些事件时自动触发小型 TypeScript 函数:
/new、/reset、/stop命令发出时- 会话开始、上下文压缩前后
- 消息收到/发出时
典型用途:发送命令时自动保存会话记忆、记录审计日志、注入额外工作区文件。
Cron 定时任务
Gateway 内置调度器,持久化保存任务,Gateway 重启不丢失:
bash
# 每天早上 7 点发送今日摘要
openclaw cron add \
--name "Morning brief" \
--cron "0 7 * * *" \
--tz "America/Los_Angeles" \
--session isolated \
--message "Summarize overnight updates." \
--announce \
--channel slack \
--to "channel:C1234567890"Webhook(外部触发)
暴露 HTTP 端点,让外部系统触发 Agent 操作:
bash
# 收到 GitHub 推送时立即唤醒 Agent
curl -X POST http://127.0.0.1:18789/hooks/wake \
-H 'Authorization: Bearer SECRET' \
-H 'Content-Type: application/json' \
-d '{"text":"New push to main branch","mode":"now"}'消息处理流程
外部事件(Webhook)
↓
/hooks/wake 或 /hooks/agent
↓
Gateway 调度器(Cron)
↓
内部事件(Hooks)
↓
Agent 运行循环
↓
回复到渠道配置概览
所有自动化功能都在 openclaw.json 中集中配置:
json5
{
// Webhook 入口
hooks: {
enabled: true,
token: "${OPENCLAW_HOOKS_TOKEN}",
path: "/hooks",
},
// Cron 调度器
cron: {
enabled: true,
maxConcurrentRuns: 1,
},
// 内部事件钩子(通过 CLI 管理)
// openclaw hooks enable session-memory
}