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:
- 1. 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 INLINECODE13
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:
- 1. 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:
- 1. 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:
- 1. 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:
- 1. 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:
- 1. 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:
- 1. 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.
OpenClaw 自动化架构
概述
优先围绕 OpenClaw 的原生原语设计自动化。只有当任务确实依赖于 OpenClaw 无法干净覆盖的第三方应用粘合、Webhook 或认证模式时,才考虑使用外部工作流工具。
在选择执行平面时,请阅读 references/decision-matrix.md。当用户需要现成的工作流模式时,请阅读 references/patterns.md。
核心原则
- - 优先使用 OpenClaw 原生 构建模块,而非 Zapier、Make 或 n8n。
- 优先使用 小型可靠系统,而非庞大脆弱的流程。
- 分离 触发、执行、状态、交付 和 恢复。
- 选择能够胜任工作的最廉价原语。
- 除非权衡会实质性影响行为、成本或可靠性,否则不要让用户在多个原语之间选择。
快速选择
按此顺序使用:
- 1. 直接工具调用 — 当用户想要即时结果,而非自动化时。
- cron — 当时间很重要或任务必须独立运行时。
- HEARTBEAT.md — 当任务是周期性维护、上下文感知维护或容忍漂移的批量检查时。
- 衍生会话 / 专家代理 — 当运行任务繁重、多步骤或属于专门角色时。
- 本地脚本 / MCP — 当相同的确定性操作将重复执行时。
- 外部工作流平台 — 仅当原生 OpenClaw 构建模块不足时。
执行平面规则
当时间就是产品时使用 cron
当用户需要以下内容时使用 cron:
- - 一次性提醒
- 每日或每周报告
- 定时监控
- 应在聊天静默时持续运行的独立任务
- 模型隔离或上下文隔离的任务
规则:
- - 仅当 sessionTarget=main 时使用 payload.kind=systemEvent。
- 对于隔离任务使用 payload.kind=agentTurn。
- 如果运行应通知特定聊天或收件人,优先使用带有 channel / to 的 delivery.mode=announce,而不是在运行内部手动发送消息。
- 编写提醒文本,使其在触发时读起来自然,并包含足够的上下文以便后续理解。
当容忍漂移且上下文有帮助时使用 HEARTBEAT.md
当任务是以下情况时使用心跳:
- - 维护
- 定期审查
- 记忆整合
- 廉价检查后接可选深度工作
- 受益于当前对话上下文的工作
不要将心跳用于:
- - 精确警报
- 外部可见的 SLA
- 高频扇出任务
- 任何必须准时运行的任务
当工作是真正的任务而非回调时使用衍生会话
当任务是以下情况时衍生会话:
- - 长时间运行的研究
- 编码或重构
- 多文件内容生产
- 研究、写作、交易、规划或类似角色的专家工作
- 更适合由 ACP 工具(如 Codex 或 Claude Code)处理
规则:
- - 如果用户明确要求 Codex / Claude Code / Gemini 风格,使用 ACP 工具意图。
- 不要将 ACP 意图包装在本地 shell 技巧中。
- 不要循环轮询衍生工作进程;让完成基于推送机制。
当确定性很重要时使用脚本或 MCP
在以下情况下创建或重用本地脚本 / MCP:
- - 相同的转换重复执行
- 工作很脆弱,不应每次都依赖自由形式的推理
- 工作流需要稳定的解析、规范化或批处理
- 任务已经可以干净地映射到外部 API 或本地工具
示例:
- - 信息源规范化
- CSV 数据丰富
- 内容后处理
- 报价/基本面数据拉取
- 知识库导入
仅将 Zapier / Make / n8n 用作边缘适配器
仅在需要以下内容时才升级到外部工作流工具:
- - 工具或 MCP 未覆盖的第三方应用认证
- 跨 SaaS 产品的 Webhook 优先集成
- 面向非技术协作者的拖放操作交接
- 本地重建比外部消费更慢的应用连接器
将它们视为适配器,而非大脑。
设计工作流
对于每个自动化,按顺序定义以下五个部分。
1. 结果
用一句话说明业务结果。
示例:
- - 当一篇论文发布映射到我追踪的股票或主题时提醒我。
- 每天早上,生成一份候选名单并起草一篇文章。
2. 触发
选择一个:
- - 用户即时请求
- 计划
- 心跳轮询
- 新文件 / 新数据到达
- 外部事件 / Webhook
如果触发条件弱或噪音大,在昂贵工作之前添加廉价检查。
3. 执行平面
选择一个主要平面:
- - 直接工具调用
- cron 主会话提醒/事件
- cron 隔离代理运行
- 心跳任务
- 衍生专家代理
- 确定性脚本 / MCP
除非有明确的交接,否则不要混合使用平面。
4. 状态与去重
始终决定:
- - 状态存储在哪里
- 如何防止重复
- 什么算作成功
- 什么可以安全重试
典型状态位置:
- - 工作区中的 JSON 状态文件
- 精选记忆文件
- 仅追加日志
- 项目产物,如 today-briefing.md
5. 交付与恢复
定义:
- - 结果去向
- 失败如何呈现
- 何时保持静默 vs 通知
- 回退方案是什么
优先使用单一通知路径。仅在必要时拆分成功和失败通道。
架构模式
模式 A:监控 → 过滤 → 通知
用于新闻、价格、发布、主题监控和警报。
结构:
- 1. 定时触发
- 获取候选
- 去重
- 评分重要性
- 仅在达到阈值时宣布
- 保存中等优先级项目用于摘要
模式 B:收集 → 提炼 → 生产
用于内容工厂和报告生成。
结构:
- 1. 收集器收集原始材料
- 产物文件存储候选名单或简报
- 生产者将产物转化为最终输出
- 可选的审查或交付步骤
模式 C:导入 → 规范化 → 索引
用于 RAG 和知识管道。
结构:
- 1. 检测来源
- 提取文本/内容
- 规范化元数据
- 分块/索引
- 可选地总结或标记
模式 D:扫描 → 决定 → 行动
用于运维检查和维护。
结构:
- 1. 廉价检查
- 仅在需要时进行深度扫描
- 尽可能使用确定性决策规则
- 行动或警报
模式 E:扇出专家工作
当用户请求一个自然分解的结果时使用。
结构:
- 1. 编排器定义子任务
- 按专业委派
- 将输出收集到一个产物中
- 在顶层进行一次综合
护栏
- - 不要自动化一个糟糕的流程。先简化。
- 如果 cron + 工具 + 脚本已经解决,不要添加外部平台。
- 当两个带有文件交接的小任务更清晰时,不要构建庞大的全能型任务。
- 如果事件驱动或更长的等待有效,不要依赖重复轮询。
- 当需要批准时,未经批准不要发送外部消息。
- 不要仅将业务逻辑放在你的头脑中;将其存储在文件、提示、脚本或配置中。
- 不要让每次失败都通知用户。某些失败应静默记录并稍后重试。
输出期望
在帮助处理自动化请求时,按此形式生成具体建议:
- 1. 最佳执行平面
- 为什么该平面胜出
- 状态 + 去重计划
- 失败处理
- 原生 OpenClaw 是否足够,或外部工作流工具是否合理
如果用户要求实际构建,首先实现最小的端到端版本。
示例请求
- - 在 OpenClaw 中设置每日报告。
- 这应该是 cron 任务还是心跳任务?
- 帮我用原生 OpenClaw 自动化替换这个 Zapier 流程。
- 为主题监控设计一个警报管道。
- 我应该如何在代理、脚本和计划任务之间拆分这个?
参考
- - 使用 references/decision-matrix.md 进行原语选择和反模式识别。
- 使用 references/patterns.md 获取 OpenClaw 术语中的现成工作流模板。