OpenClaw Automation Architecture
Overview
Design automations around OpenClaw's native primitives first. Reach for external workflow tools only when the job truly depends on third-party app glue, webhooks, or auth patterns that OpenClaw cannot cover cleanly.
Read references/decision-matrix.md when choosing the execution plane. Read references/patterns.md when the user needs a ready-made workflow pattern.
Core Doctrine
- Prefer OpenClaw-native building blocks before Zapier, Make, or n8n.
- Prefer small reliable systems over giant brittle flows.
- Separate trigger, execution, state, delivery, and recovery.
- Pick the cheapest primitive that can do the job well.
- Do not ask the user to choose among primitives unless the trade-off materially affects behavior, cost, or reliability.
Quick Selection
Use this order:
- Direct tool call now — when the user wants an immediate result, not automation.
cron — when timing matters or the task must run independently.
HEARTBEAT.md — when the task is periodic housekeeping, context-aware maintenance, or a drift-tolerant batch check.
- Spawned session / specialist agent — when the run is heavy, multi-step, or belongs to a dedicated role.
- Local script / MCP — when the same deterministic operation will repeat.
- External workflow platforms — only if native OpenClaw building blocks are not enough.
Execution Plane Rules
Use cron when time is the product
Reach for cron when the user wants:
- one-shot reminders
- daily or weekly reports
- scheduled monitoring
- isolated runs that should survive chat silence
- model-isolated or context-isolated jobs
Rules:
- Use
payload.kind="systemEvent" only for sessionTarget="main".
- Use
payload.kind="agentTurn" for isolated jobs.
- If the run should notify a specific chat or recipient, prefer
delivery.mode="announce" with channel / to instead of sending messages manually inside the run.
- Write reminder text so it reads naturally when fired, including enough context to make sense later.
Use HEARTBEAT.md when drift is fine and context helps
Reach for heartbeat when the task is:
- maintenance
- periodic review
- memory consolidation
- cheap-gate checks followed by optional deeper work
- work that benefits from current conversation context
Do not use heartbeat for:
- precise alarms
- externally visible SLAs
- high-frequency fan-out jobs
- anything that must run exactly on time
Use spawned sessions when the work is a real job, not a callback
Spawn a session when the task is:
- long-running research
- coding or refactoring
- multi-file content production
- specialist work for research, writing, trading, planning, or similar roles
- better handled by ACP harnesses such as Codex or Claude Code
Rules:
- If the user explicitly asks for Codex / Claude Code / Gemini in that style, use ACP harness intent.
- Do not wrap ACP intent in local shell hacks.
- Do not poll spawned workers in loops; let completion be push-based.
Use a script or MCP when determinism matters
Create or reuse a local script / MCP when:
- the same transformation repeats
- the work is fragile and should not rely on free-form reasoning every time
- the workflow needs stable parsing, normalization, or batching
- the task already maps to an external API or local tool cleanly
Examples:
- feed normalization
- CSV enrichment
- content post-processing
- quote/fundamental data pulls
- knowledge-base ingest
Use Zapier / Make / n8n only as the edge adapter
Escalate to external workflow tools only when you need:
- third-party app auth not covered by tools or MCPs
- webhook-first integrations across SaaS products
- drag-and-drop ops handoff for nontechnical collaborators
- app connectors that would be slower to recreate locally than to consume externally
Treat them as adapters, not the brain.
Design Workflow
For every automation, define these five pieces in order.
1. Outcome
State the business result in one sentence.
Example:
- "Alert me when a paper release maps to a stock or theme I track."
- "Every morning, produce a shortlist and draft one article."
2. Trigger
Pick one:
- user request now
- schedule
- heartbeat poll
- new file / new data arrival
- external event / webhook
If the trigger is weak or noisy, add a cheap gate before expensive work.
3. Execution plane
Choose one primary plane:
- direct tool call
- cron main-session reminder/event
- cron isolated agent run
- heartbeat task
- spawned specialist agent
- deterministic script / MCP
Do not mix planes unless there is a clear handoff.
4. State and dedup
Always decide:
- where state lives
- how duplicates are prevented
- what counts as success
- what can be retried safely
Typical state locations:
- JSON state file in workspace
- curated memory file
- append-only log
- project artifact such as
today-briefing.md
5. Delivery and recovery
Define:
- where the result goes
- how failures surface
- when to stay silent vs notify
- what the fallback is
Prefer a single notification path. Split success and failure channels only when necessary.
Architecture Patterns
Pattern A: Monitor → Filter → Notify
Use for news, prices, releases, topic monitoring, and alerts.
Structure:
- scheduled trigger
- fetch candidates
- deduplicate
- score importance
- announce only if threshold met
- save medium-priority items for digest
Pattern B: Collect → Distill → Produce
Use for content factories and report generation.
Structure:
- collector gathers raw material
- artifact file stores shortlist or briefing
- producer turns artifact into final output
- optional review or delivery step
Pattern C: Ingest → Normalize → Index
Use for RAG and knowledge pipelines.
Structure:
- detect source
- extract text/content
- normalize metadata
- chunk/index
- optionally summarize or tag
Pattern D: Scan → Decide → Act
Use for operations checks and maintenance.
Structure:
- cheap gate
- deeper scan only if needed
- deterministic decision rule where possible
- action or alert
Pattern E: Fan-out specialist work
Use when the user asks for one outcome that naturally decomposes.
Structure:
- orchestrator defines subtasks
- delegate by specialty
- collect outputs into one artifact
- synthesize once at the top
Guardrails
- Do not automate a bad process. Simplify first.
- Do not add an external platform if
cron + tools + scripts already solve it.
- Do not build giant all-in-one jobs when two small jobs with a file handoff are clearer.
- Do not rely on repeated polling if eventing or longer waits work.
- Do not send external messages without approval when approval is required.
- Do not put business logic only in your head; store it in files, prompts, scripts, or config.
- Do not make every failure page the user. Some failures should log quietly and retry later.
Output Expectations
When helping with an automation request, produce a concrete recommendation in this shape:
- Best execution plane
- Why this plane wins
- State + dedup plan
- Failure handling
- Whether native OpenClaw is enough or an external workflow tool is justified
If the user asks to actually build it, implement the smallest end-to-end version first.
Example Requests
- "Set up a daily report in OpenClaw."
- "Should this be a cron job or a heartbeat task?"
- "Help me replace this Zapier flow with native OpenClaw automation."
- "Design an alerting pipeline for topic monitoring."
- "How should I split this across agents, scripts, and scheduled jobs?"
References
- Use
references/decision-matrix.md for primitive selection and anti-patterns.
- Use
references/patterns.md for ready-made workflow templates in OpenClaw terms.
1---2name: openclaw-automation-architecture3description: Design OpenClaw-native automation systems using cron, HEARTBEAT.md, spawned sessions, specialist-agent delegation, first-class tools, MCPs, and local scripts. Use when the user wants to automate a workflow, set up reminders, schedule recurring reports, monitor topics, build alerting pipelines, design agent orchestration, choose between cron vs heartbeat vs spawned session vs script vs MCP vs Zapier/Make/n8n, or replace brittle no-code flows with an OpenClaw-first architecture. Trigger on requests like "automate this", "build a workflow", "set up a cron", "heartbeat task", "reminder", "scheduled report", "monitor this", "alert me when", "pipeline", "agent orchestration", "Zapier", "Make", "n8n", "save time", or "OpenClaw automation".4---56# OpenClaw Automation Architecture78## Overview910Design automations around OpenClaw's native primitives first. Reach for external workflow tools only when the job truly depends on third-party app glue, webhooks, or auth patterns that OpenClaw cannot cover cleanly.1112Read `references/decision-matrix.md` when choosing the execution plane. Read `references/patterns.md` when the user needs a ready-made workflow pattern.1314## Core Doctrine1516- Prefer **OpenClaw-native** building blocks before Zapier, Make, or n8n.17- Prefer **small reliable systems** over giant brittle flows.18- Separate **trigger**, **execution**, **state**, **delivery**, and **recovery**.19- Pick the cheapest primitive that can do the job well.20- Do not ask the user to choose among primitives unless the trade-off materially affects behavior, cost, or reliability.2122## Quick Selection2324Use this order:25261. **Direct tool call now** — when the user wants an immediate result, not automation.272. **`cron`** — when timing matters or the task must run independently.283. **`HEARTBEAT.md`** — when the task is periodic housekeeping, context-aware maintenance, or a drift-tolerant batch check.294. **Spawned session / specialist agent** — when the run is heavy, multi-step, or belongs to a dedicated role.305. **Local script / MCP** — when the same deterministic operation will repeat.316. **External workflow platforms** — only if native OpenClaw building blocks are not enough.3233## Execution Plane Rules3435### Use `cron` when time is the product3637Reach for `cron` when the user wants:38- one-shot reminders39- daily or weekly reports40- scheduled monitoring41- isolated runs that should survive chat silence42- model-isolated or context-isolated jobs4344Rules:45- Use `payload.kind="systemEvent"` only for `sessionTarget="main"`.46- Use `payload.kind="agentTurn"` for isolated jobs.47- If the run should notify a specific chat or recipient, prefer `delivery.mode="announce"` with `channel` / `to` instead of sending messages manually inside the run.48- Write reminder text so it reads naturally when fired, including enough context to make sense later.4950### Use `HEARTBEAT.md` when drift is fine and context helps5152Reach for heartbeat when the task is:53- maintenance54- periodic review55- memory consolidation56- cheap-gate checks followed by optional deeper work57- work that benefits from current conversation context5859Do not use heartbeat for:60- precise alarms61- externally visible SLAs62- high-frequency fan-out jobs63- anything that must run exactly on time6465### Use spawned sessions when the work is a real job, not a callback6667Spawn a session when the task is:68- long-running research69- coding or refactoring70- multi-file content production71- specialist work for research, writing, trading, planning, or similar roles72- better handled by ACP harnesses such as Codex or Claude Code7374Rules:75- If the user explicitly asks for Codex / Claude Code / Gemini in that style, use ACP harness intent.76- Do not wrap ACP intent in local shell hacks.77- Do not poll spawned workers in loops; let completion be push-based.7879### Use a script or MCP when determinism matters8081Create or reuse a local script / MCP when:82- the same transformation repeats83- the work is fragile and should not rely on free-form reasoning every time84- the workflow needs stable parsing, normalization, or batching85- the task already maps to an external API or local tool cleanly8687Examples:88- feed normalization89- CSV enrichment90- content post-processing91- quote/fundamental data pulls92- knowledge-base ingest9394### Use Zapier / Make / n8n only as the edge adapter9596Escalate to external workflow tools only when you need:97- third-party app auth not covered by tools or MCPs98- webhook-first integrations across SaaS products99- drag-and-drop ops handoff for nontechnical collaborators100- app connectors that would be slower to recreate locally than to consume externally101102Treat them as adapters, not the brain.103104## Design Workflow105106For every automation, define these five pieces in order.107108### 1. Outcome109110State the business result in one sentence.111112Example:113- "Alert me when a paper release maps to a stock or theme I track."114- "Every morning, produce a shortlist and draft one article."115116### 2. Trigger117118Pick one:119- user request now120- schedule121- heartbeat poll122- new file / new data arrival123- external event / webhook124125If the trigger is weak or noisy, add a cheap gate before expensive work.126127### 3. Execution plane128129Choose one primary plane:130- direct tool call131- cron main-session reminder/event132- cron isolated agent run133- heartbeat task134- spawned specialist agent135- deterministic script / MCP136137Do not mix planes unless there is a clear handoff.138139### 4. State and dedup140141Always decide:142- where state lives143- how duplicates are prevented144- what counts as success145- what can be retried safely146147Typical state locations:148- JSON state file in workspace149- curated memory file150- append-only log151- project artifact such as `today-briefing.md`152153### 5. Delivery and recovery154155Define:156- where the result goes157- how failures surface158- when to stay silent vs notify159- what the fallback is160161Prefer a single notification path. Split success and failure channels only when necessary.162163## Architecture Patterns164165### Pattern A: Monitor → Filter → Notify166167Use for news, prices, releases, topic monitoring, and alerts.168169Structure:1701. scheduled trigger1712. fetch candidates1723. deduplicate1734. score importance1745. announce only if threshold met1756. save medium-priority items for digest176177### Pattern B: Collect → Distill → Produce178179Use for content factories and report generation.180181Structure:1821. collector gathers raw material1832. artifact file stores shortlist or briefing1843. producer turns artifact into final output1854. optional review or delivery step186187### Pattern C: Ingest → Normalize → Index188189Use for RAG and knowledge pipelines.190191Structure:1921. detect source1932. extract text/content1943. normalize metadata1954. chunk/index1965. optionally summarize or tag197198### Pattern D: Scan → Decide → Act199200Use for operations checks and maintenance.201202Structure:2031. cheap gate2042. deeper scan only if needed2053. deterministic decision rule where possible2064. action or alert207208### Pattern E: Fan-out specialist work209210Use when the user asks for one outcome that naturally decomposes.211212Structure:2131. orchestrator defines subtasks2142. delegate by specialty2153. collect outputs into one artifact2164. synthesize once at the top217218## Guardrails219220- Do not automate a bad process. Simplify first.221- Do not add an external platform if `cron` + tools + scripts already solve it.222- Do not build giant all-in-one jobs when two small jobs with a file handoff are clearer.223- Do not rely on repeated polling if eventing or longer waits work.224- Do not send external messages without approval when approval is required.225- Do not put business logic only in your head; store it in files, prompts, scripts, or config.226- Do not make every failure page the user. Some failures should log quietly and retry later.227228## Output Expectations229230When helping with an automation request, produce a concrete recommendation in this shape:2312321. **Best execution plane**2332. **Why this plane wins**2343. **State + dedup plan**2354. **Failure handling**2365. **Whether native OpenClaw is enough or an external workflow tool is justified**237238If the user asks to actually build it, implement the smallest end-to-end version first.239240## Example Requests241242- "Set up a daily report in OpenClaw."243- "Should this be a cron job or a heartbeat task?"244- "Help me replace this Zapier flow with native OpenClaw automation."245- "Design an alerting pipeline for topic monitoring."246- "How should I split this across agents, scripts, and scheduled jobs?"247248## References249250- Use `references/decision-matrix.md` for primitive selection and anti-patterns.251- Use `references/patterns.md` for ready-made workflow templates in OpenClaw terms.