OpenClaw automation lets agents act on their own, without waiting for a user message. HEARTBEAT.md defines periodic check-ins where the agent wakes up, performs tasks, and reports results. Cron jobs schedule one-off or recurring commands. Event hooks trigger agent actions in response to system events. Webhooks let external services push data into agent conversations. Together, these mechanisms turn OpenClaw from a reactive chat system into a proactive automation platform.
Master openclaw heartbeat & automation
Take the OpenClaw Automation & Workflows course with hands-on lessons and challenges.
This HEARTBEAT.md instructs the agent to perform health checks every 6 hours. The agent runs the checks using its configured tools (health-checker, ssh-executor), generates a summary, and sends it to the broadcast group. Escalation rules ensure critical issues get human attention immediately.
Cron jobs use standard cron syntax. The first job runs at 2 AM daily and tells the deployer agent to perform a database backup. The second runs at 9 AM every Monday and triggers a weekly report. Unlike heartbeat (which is agent-directed), cron jobs send a specific message to a specific agent at scheduled times.
Hooks fire in response to system events. The onNewMessage hook detects messages containing '#urgent' on Discord and routes them to the triage agent with high priority. The onChannelDisconnect hook sends an alert when any channel goes offline. The onAgentError hook notifies ops when an agent encounters an error.
This creates a webhook endpoint that forwards GitHub PR events to the code-reviewer agent. When a new PR is opened, GitHub sends a POST request to the webhook URL, the Gateway verifies the signature using the shared secret, and the code-reviewer agent receives the PR data as a message it can process and respond to.
Heartbeat is for tasks where the agent needs to assess the situation and decide what to do. Cron is for tasks where the exact action is known in advance. Use heartbeat when you want the agent to think. Use cron when you just need something to run on schedule.
Setting heartbeat intervals too short (every minute) without considering the cost of model API calls for each check-in
Each heartbeat invocation costs tokens. A 6-hour or daily interval is appropriate for most monitoring tasks. If you need minute-level checks, use a cron job with a shell command instead of an agent heartbeat.
Creating webhook endpoints without configuring a shared secret, allowing anyone to trigger agent actions by POSTing to the URL
Always configure a webhook secret and validate signatures on incoming requests. Without this, anyone who discovers the URL can inject messages into your agent's conversation.
Building complex multi-step workflows entirely in HEARTBEAT.md instead of splitting them into separate agents with orchestration
For workflows with more than 3-4 steps, use multi-agent orchestration. An orchestrator agent coordinates specialist agents, each responsible for one step. This is more reliable and easier to debug than a single long heartbeat.
Not monitoring failed automations, causing silent failures when a cron job or heartbeat stops working
Set up alerting for automation failures. Use the onAgentError hook to notify ops when an agent errors during a scheduled task. Check `openclaw cron list` and `openclaw logs` regularly.
OpenClaw automation turns agents into proactive workers. HEARTBEAT.md defines periodic agent check-ins for tasks requiring judgment. Cron jobs schedule fixed commands at specific times. Event hooks react to system events (messages, disconnects, errors). Webhooks let external services trigger agent actions. Use heartbeat for adaptive tasks, cron for fixed routines, and always validate webhook signatures. Monitor automation logs and set up alerting for failures.
Interactive lessons and challenges on Stanza, practice in VS Code, Cursor, or the web.
Interactive lessons and challenges, right in your code editor.
Check the free courses. No credit card.