Advanced Automation with OpenClaw

Heartbeats, webhooks, multi-step workflows, and production patterns

This tutorial builds on the basic automation tutorial (cron jobs and webhooks). Here you add heartbeats for periodic checks, webhook-triggered flows, multi-step and multi-agent patterns, and error handling. Plan for about 30-40 minutes. Full options: Automation Reference.

What You Will Build

  • Heartbeat automation (e.g. every N minutes) for monitoring or recurring tasks
  • Webhook-triggered automation (e.g. GitHub, Sentry, or custom HTTP)
  • Multi-step workflows that chain agent runs or use sub-agents
  • Error handling and logging so failures do not go silent
  • Optional: model routing (cheaper model for simple cron, strong model for complex tasks)

Prerequisites

Step 1: Heartbeat Automation

Heartbeats run on an interval (e.g. every 5 or 15 minutes). Use for monitoring, health checks, or lightweight recurring tasks.

Heartbeat example
{
  "heartbeat": {
    "intervalMinutes": 15,
    "command": "agent --message 'Check for urgent items: unread important emails, calendar in next 2 hours. Reply only if something needs attention.'"
  }
}

Configure in the same config file as cron. Restart the Gateway after changes. For heavy workloads use a less frequent cron to avoid overlapping runs.

Step 2: Webhook-Triggered Automation

Webhooks let external systems (GitHub, Sentry, CI/CD) trigger the agent via HTTP. Exact schema and auth are in the Automation Reference. Always secure webhook endpoints: bind to localhost and put a reverse proxy with TLS and auth in front.

Step 3: Multi-Step and Multi-Agent

Chained cron jobs: one cron writes to a file or queue; another picks it up and runs the agent. Or use sub-agents: Set Up a Sub-Agent, Multi-Agent Team. Use Shared Context so multiple agents read/write the same state.

Step 4: Error Handling and Logging

Check Gateway logs for cron/heartbeat/webhook runs. In the command you can ask the agent to send you a message only on failure. Design commands to be idempotent so re-running after a crash does not duplicate side effects.

Step 5: Model Routing (Optional)

Use a cheaper model for simple scheduled tasks and a stronger model for complex or user-facing work. See ClawRouter and Configuration reference.

Related Tutorials