OpenClaw Automation: Build AI Workflows That Run 24/7
AI agents are most powerful when they work without you watching. This guide covers everything you need to run OpenClaw agents around the clock — from HEARTBEAT.md scheduling to Docker deployment, Telegram notifications, and monitoring strategies that keep your automated workflows reliable.
What Is Agent Automation?
Agent automation means your AI agents perform tasks on a schedule without you manually sending messages. Instead of opening a terminal and typing a command every morning, the agent wakes up on its own, executes a predefined task, and delivers the result to you via Telegram, a log file, or any output channel you configure.
OpenClaw supports automation through two mechanisms: the HEARTBEAT.md file for periodic scheduled tasks, and the gateway for always-on availability. Combined with process managers like pm2 or Docker, you get an AI agent that runs 24/7 with automatic recovery from crashes and reboots.
Common automation use cases include daily content summaries, weekly SEO reports, scheduled social media drafts, periodic data monitoring, and content calendar management. If you have already set up your first agent using the agent creation guide, automation is the natural next step.
How HEARTBEAT.md Works
HEARTBEAT.md is an optional configuration file that sits in your agent's workspace alongside SOUL.md. It contains instructions that the gateway sends to the agent at a regular interval. Think of it as a cron job, but instead of running a shell script, it sends a prompt to your AI agent.
Basic HEARTBEAT.md Structure
# HEARTBEAT.md — Daily Content Summary Agent
## Schedule
Every 24 hours
## Instructions
1. Review all content tasks completed in the last 24 hours
2. Compile a summary with the following format:
- Total tasks completed
- Key highlights from each piece of content
- Any pending items that need attention
3. Send the summary as a daily report
4. Flag any overdue tasks that were not completedHEARTBEAT.md for an SEO Monitor
# HEARTBEAT.md — Weekly SEO Report
## Schedule
Every 168 hours
## Instructions
1. Analyze the current keyword rankings for our target terms
2. Compare this week's performance with last week
3. Identify any keywords that dropped more than 3 positions
4. Suggest 3 new content topics based on trending search queries
5. Format the report with sections: Rankings, Changes, OpportunitiesThe schedule interval is defined in hours. Common intervals include 1 (hourly checks), 24 (daily reports), 168 (weekly summaries), and 720 (monthly reviews).
Setting Up a 24/7 Agent
Running an agent around the clock requires the OpenClaw gateway running continuously and a process manager that restarts it if it crashes. Here are three approaches.
Option 1: pm2 (Recommended for Most Users)
pm2 is a Node.js process manager that keeps your gateway alive, handles log rotation, and restarts the process after crashes or server reboots.
# Install pm2 globally
npm install -g pm2
# Start the OpenClaw gateway with pm2
pm2 start "openclaw gateway start" --name openclaw-gateway
# Ensure it starts on system boot
pm2 startup
pm2 save
# View logs
pm2 logs openclaw-gateway
# Restart after config changes
pm2 restart openclaw-gatewayOption 2: systemd (Linux Servers)
# /etc/systemd/system/openclaw.service
[Unit]
Description=OpenClaw AI Agent Gateway
After=network.target
[Service]
Type=simple
User=your-username
WorkingDirectory=/home/your-username/my-agents
ExecStart=/usr/bin/npx openclaw gateway start
Restart=always
RestartSec=10
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.target# Enable and start the service
sudo systemctl daemon-reload
sudo systemctl enable openclaw
sudo systemctl start openclaw
# View logs
journalctl -u openclaw -fOption 3: Docker (Portable & Reproducible)
Docker packages your entire agent setup into a container that runs identically on any machine. If you purchased a CrewClaw deploy package, it already includes a Dockerfile and docker-compose.yml configured for 24/7 operation.
# docker-compose.yml
version: "3.8"
services:
openclaw:
build: .
restart: always
ports:
- "18789:18789"
env_file:
- .env
volumes:
- ./agents:/app/agents
# Start in the background
docker-compose up -d
# View logs
docker-compose logs -f openclawTelegram Notifications for Completed Tasks
The most practical way to receive automated task results is through Telegram. When your agent completes a heartbeat task, the output appears as a message in your Telegram chat. For a detailed walkthrough, see the Telegram integration guide.
# 1. Create a bot with @BotFather on Telegram
# Send /newbot and follow the prompts — copy the bot token
# 2. Add the token to your .env file
TELEGRAM_BOT_TOKEN=your-bot-token-here
# 3. Start the gateway (Telegram connects automatically)
openclaw gateway start
# 4. Open your bot in Telegram and send /startTo format heartbeat outputs for Telegram readability, add a rule to your agent's SOUL.md:
## Rules
- Start every automated report with a one-line summary
- Use bullet points for key findings
- Keep total output under 500 words for mobile readability
- Include a "Next Steps" section at the end of each reportScheduling Patterns: Real-World Examples
Daily Summary (Every 24 Hours)
A coordinator agent that reviews the day's activity and sends a digest. Ideal for content teams or any workflow where you need a daily status update.
Weekly Report (Every 168 Hours)
An analyst agent that compiles weekly metrics, trends, and recommendations. Works well for SEO tracking, marketing performance, or sales pipeline reviews.
Content Calendar (Every 168 Hours)
A content strategist agent that plans the upcoming week's content based on trending topics and content gaps. This agent can work with a multi-agent team where it delegates writing to a content writer agent.
Hourly Monitor (Every 1 Hour)
A monitoring agent that checks for specific conditions and only alerts you when something needs attention. Use the "All clear" pattern to keep token costs low:
# HEARTBEAT.md — Hourly Status Check
## Schedule
Every 1 hour
## Instructions
Check the current status of all active tasks.
Only report if:
- A task has been stuck for more than 4 hours
- A deadline is within the next 2 hours
- An error or failure was detected
If everything is normal, respond with "All clear" only.Monitoring and Restart Strategies
# pm2 monitoring
pm2 logs openclaw-gateway # Real-time logs
pm2 monit # CPU/memory metrics
pm2 status # Quick overview
# Docker monitoring
docker-compose logs -f # Follow container logs
docker stats # Resource usage
# Session cleanup (run weekly via cron)
rm ~/.openclaw/agents/*/sessions/sessions.json
pm2 restart openclaw-gatewayLong-running agents accumulate conversation history in session files. Schedule a periodic session cleanup to keep response times fast. See the CLI commands reference for more session management details.
Best Practices for Agent Automation
Start with long intervals, then shorten
Begin with a 24-hour heartbeat to validate that your agent produces useful output. Once the quality meets your expectations, reduce the interval if needed.
Write specific heartbeat instructions
Vague instructions like "check on things" produce vague results. Write concrete steps: what to check, what format to use, and what thresholds trigger alerts.
Separate automation agents from interactive agents
Create dedicated agents for automated tasks rather than adding heartbeats to agents you also use interactively. Automated agents can have specialized SOUL.md rules for report formatting.
Monitor token usage
Automated agents can consume significant API credits. Consider using a local model via Ollama for high-frequency heartbeats to eliminate API costs entirely.
Complete Example: Automated Content Team
# Create workspaces
mkdir -p agents/orion agents/echo agents/radar
# Register all agents
openclaw agents add orion --workspace ./agents/orion --non-interactive
openclaw agents add echo --workspace ./agents/echo --non-interactive
openclaw agents add radar --workspace ./agents/radar --non-interactive
# Orion gets a daily heartbeat, Radar gets a weekly one
# Echo has no heartbeat — it only works when Orion delegates
# Start with pm2 for 24/7 operation
pm2 start "openclaw gateway start" --name openclaw-gateway
pm2 startup
pm2 saveWith this setup, you receive a daily team summary every morning and a comprehensive SEO report every week — all delivered to your Telegram. The content writer agent (Echo) has no heartbeat because it only works when the coordinator delegates a writing task to it.
Frequently Asked Questions
What is HEARTBEAT.md and how does it work?
HEARTBEAT.md is a configuration file that lives in an agent's workspace directory alongside SOUL.md. It contains periodic instructions that the gateway executes on a schedule. Think of it as a cron job for your AI agent. When the gateway is running, it reads HEARTBEAT.md at the defined interval and sends the instructions to the agent as if a user had sent the message. The agent processes the task using its SOUL.md personality and rules, then outputs the result.
Can I run OpenClaw agents 24/7 without a cloud server?
Yes. You can run OpenClaw agents continuously on any machine that stays powered on, including a home desktop, a Raspberry Pi, or an old laptop. Use pm2 or systemd to keep the gateway process alive and automatically restart it if it crashes. For the most reliable setup, a $5/month VPS from providers like Hetzner or DigitalOcean gives you a dedicated always-on environment with better uptime than a home machine.
How do I get Telegram notifications when an automated task completes?
Connect your agent to Telegram by creating a bot through BotFather, adding the bot token to your .env file, and starting the gateway with Telegram integration enabled. When the agent completes a heartbeat task, the output is sent to your Telegram chat automatically. You can also configure the agent's SOUL.md to format notifications in a specific way, such as including a summary line or status emoji at the top of each message.
What happens if a heartbeat task fails?
If a heartbeat task fails due to a model API error, network issue, or timeout, the gateway logs the failure and moves on. The next scheduled heartbeat runs at its normal interval. The agent does not retry failed tasks automatically, but you can add retry logic by including instructions in HEARTBEAT.md like 'If the previous task was incomplete, attempt to finish it before starting new work.' Monitoring with pm2 logs or journalctl helps you catch and diagnose repeated failures.
Can I have different schedules for different tasks?
HEARTBEAT.md supports a single schedule interval per agent. To run tasks at different frequencies, create separate agents with different heartbeat intervals. For example, a daily-reporter agent with a 24-hour heartbeat for daily summaries, and a monitor agent with a 1-hour heartbeat for frequent checks. Each agent runs independently with its own schedule, SOUL.md, and workspace.
How do I stop automated tasks without shutting down the gateway?
Remove or rename the HEARTBEAT.md file in the agent's workspace directory and restart the gateway. The agent will continue to respond to manual messages but will no longer execute periodic tasks. You can also comment out the contents of HEARTBEAT.md by removing the task instructions while keeping the file. To pause all heartbeats across all agents, restart the gateway with heartbeat processing disabled in the configuration.
Deploy an Always-On AI Agent in Minutes
CrewClaw deploy packages include Docker, Telegram bot setup, and pre-configured SOUL.md files — everything you need to run automated AI agents around the clock.