每天闭店前要查库存、清理设备,忙起来容易漏一项。OpenClaw 可以按设定的时间启动 Agent,让它读取工作区里的清单,再整理成一段提醒。下面给出每天上午 9 点的配置,并先用一分钟后触发的一次性任务实测;演示只读虚构简报,不接微信或邮箱,也不改文件。
你需要准备
| 准备 | 说明 |
|---|---|
| OpenClaw | 本次使用 2026.10.1;官方文档把计划任务命令称为 cron / automations |
| 本地模型 | 本次使用 Ollama 0.35.1 和 Qwen3.8 27B Q4_K_M(模型文件约 18.4GB);内存较小的电脑可换更小的工具调用模型 |
| 资料 | 放进 OpenClaw 工作区的一份待整理清单,先用虚构内容练习 |
| 电脑 | 本次实测为 Apple M1 Max、64GB 内存、macOS 27.0.1 |
| 费用 | 本机推理没有云端模型 API 账单;模型下载、磁盘和电力另计 |
实测命令、虚构简报和运行记录放在定时任务练习包。
定时任务是怎么跑的
OpenClaw 的计划任务由 Gateway 调度。Gateway 需要一直运行,任务才会按时触发;电脑关机或 Gateway 停止时,就不能按计划启动。任务定义和运行记录会保存在本机状态数据库里。
--cron "0 9 * * *" 表示每天 9 点。加上 --tz Asia/Shanghai,这个时间就按中国标准时间解释。--session isolated 会为每次运行开一个独立会话,避免把之前聊天里的内容带进来。
建一个只读的本机练习环境
先为练习建立单独 profile 和工作区,避免和日常使用的配置混在一起:
openclaw --profile daily-check setup --baseline \\
--workspace "$HOME/.openclaw-daily-check/workspace"
把 Ollama 地址、模型名和最小权限写入这个 profile。下面以 qwen3.8-27b:latest 为例;如果你的电脑上模型标签不同,换成 ollama list 中的名称。模型需要支持工具调用。
openclaw --profile daily-check config set gateway.mode local
openclaw --profile daily-check config set gateway.bind loopback
openclaw --profile daily-check config set gateway.port 19269
openclaw --profile daily-check config set models.providers.ollama.baseUrl http://127.0.0.1:11434
openclaw --profile daily-check config set models.providers.ollama.api ollama
openclaw --profile daily-check config set models.providers.ollama.apiKey ollama-local
openclaw --profile daily-check config set models.providers.ollama.models '[{"id":"qwen3.8-27b:latest","name":"qwen3.8-27b:latest","api":"ollama","reasoning":false,"input":["text"],"contextTokens":32768,"maxTokens":2048}]' --strict-json
openclaw --profile daily-check config set agents.defaults.model.primary "ollama/qwen3.8-27b:latest"
openclaw --profile daily-check config set tools.allow '["read"]' --strict-json
openclaw --profile daily-check config set tools.fs.workspaceOnly true
openclaw --profile daily-check config set agents.defaults.sandbox.workspaceAccess ro
openclaw --profile daily-check config set models.mode replace
openclaw --profile daily-check config set plugins.allow '["ollama"]' --strict-json
openclaw --profile daily-check config set plugins.slots.memory none
openclaw --profile daily-check config set discovery.mdns.mode off
openclaw --profile daily-check config set telemetry.enabled false
openclaw --profile daily-check config set update.checkOnStart false
这里把文件工具限制在工作区,并且只开放读取;只加载本地模型插件,关闭记忆插件、局域网广播、遥测和启动更新检查。演示先不要放客户资料、账号口令或付款信息进去。
在工作区新建 daily-brief.md,填一份虚构数据:
今日营业至:20:30
纸杯库存:180只;补货提醒线:200只
磨豆机清洁:尚未完成
联系人、采购金额和供应商:未提供
设置每天运行
在一个终端里启动本机 Gateway,并保持它运行:
openclaw --profile daily-check gateway run --port 19269 --bind loopback
再开一个终端,添加定时任务。提示词要说清资料在哪、要输出什么;工具白名单仍限制为 read:
openclaw --profile daily-check cron add \\
--cron "0 9 * * *" --tz Asia/Shanghai \\
--name "每日闭店清单" --agent main --session isolated \\
--model "ollama/qwen3.8-27b:latest" \\
--tools read --no-deliver \\
--message "读取 daily-brief.md,列出打烊时间、低于补货线的库存和未完成的清洁事项。只根据文件回答,不补充联系人或金额。"
--no-deliver 关闭的是 OpenClaw 的自动结果投递;它本身不会撤掉 Agent 可用的消息工具。本练习同时只允许 read,不配置消息渠道,因此 Agent 没有发消息的工具。若你自己给 Agent 开放了 message 等工具,不能把 --no-deliver 当成禁止外发的权限边界。
先用一次性任务试跑
第一次设置时,可以先用一分钟后触发的一次性任务,确认 Gateway、模型和资料路径都正常。把上一条命令里的计划参数换成 --at 1m,并加上 --keep-after-run:
openclaw --profile daily-check cron add \\
--at 1m --keep-after-run \\
--name "闭店清单试跑" --agent main --session isolated \\
--model "ollama/qwen3.8-27b:latest" \\
--tools read --no-deliver \\
--message "读取 daily-brief.md,列出打烊时间、低于补货线的库存和未完成的清洁事项。只根据文件回答。"
命令会返回任务 ID。运行后,用它查看结果:
openclaw --profile daily-check cron runs <任务ID> --json
本机把任务设为一分钟后触发。运行历史为 succeeded,会话记录确认 Agent 调用了 read 工具读取简报,随后给出 20:30 打烊、纸杯比补货线少 20 只、磨豆机清洁未完成。两次单次试跑分别约 79.3 秒和 78.3 秒;输出均未投递。这只是小样本核对,没有等待每天的任务连续运行,也不代表其他模型的速度。
确认试跑正常后,再添加每天运行的 --cron 任务。试跑的一次性任务可用 openclaw --profile daily-check cron rm <任务ID> 删除;日常任务会一直保留,直到你删除或停用它。
没按时运行时检查什么
- 先看 Gateway 是否仍在运行,以及电脑是否关机或休眠。
- 用
openclaw --profile daily-check cron status检查调度器,再用cron list和cron runs <任务ID>看任务状态与运行记录。 - 确认
--tz写的是你要用的时区;没有指定时区的 cron 表达式会使用 Gateway 主机时区。 - 如果提示模型不能调用工具,换成已安装且支持工具调用的本地模型,再检查工作区文件名和
--tools read权限。
工具清单
| 工具 | 用途 | 入口 |
|---|---|---|
| OpenClaw | 在本机运行 Agent 和定时任务 | 官方文档 |
| Ollama | 下载并运行本机模型 | 官方下载页 |
| Qwen3.8 | 本次实测使用的本机模型系列 | Ollama 模型页 |
接下来可以做什么
- 本地模型做 Agent:能力边界在哪:给 Agent 配置本机资料和只读权限。
- MCP 是什么:让 Agent 连上各种工具:了解 Agent 如何连接外部工具;接真实业务前先核对工具读写范围。