Cron 定时任务

让 Agent 按时间表自动执行任务。

{
  cron: {
    enabled: true,
    maxConcurrentRuns: 2,
  },
}

通过聊天创建定时任务

你:每天早上9点帮我总结一下昨天的邮件
Agent:好的,我来创建一个定时任务...

通过 CLI 创建

# 每天9点执行
openclaw cron add --schedule "0 9 * * *" \
  --message "总结昨天的邮件并发到 Telegram" \
  --channel telegram --target 你的ChatID

# 查看所有定时任务
openclaw cron list

# 删除任务
openclaw cron remove <cron-id>

使用场景

  • ☀️ 每日早报(新闻/天气/日程)
  • 📧 定期检查邮箱
  • 📊 定时生成报告
  • ⏰ 提醒事项

Heartbeat 心跳机制

心跳是 Agent 的"自主意识"——定期醒来检查是否有事情需要处理。

{
  agents: {
    defaults: {
      heartbeat: {
        every: "30m",        // 每30分钟检查一次
        target: "last",      // 发送到最近活跃的渠道
        model: "openai/gpt-5-mini",  // 用便宜的模型省钱
      },
    },
  },
}

HEARTBEAT.md

在工作空间创建 HEARTBEAT.md 告诉 Agent 心跳时该做什么:

# HEARTBEAT.md

## 定期检查清单
- [ ] 检查 Gmail 是否有未读重要邮件
- [ ] 看看日历今天有没有即将到来的会议
- [ ] 如果有新的 GitHub 通知,总结一下

## 规则
- 晚上23:00-早上8:00 不要打扰
- 如果没什么重要的,回复 HEARTBEAT_OK 就好
- 不要每次都检查所有项目,轮流检查

Heartbeat vs Cron 怎么选?

场景用 Heartbeat用 Cron
批量检查多项
精确时间触发
需要会话上下文
一次性提醒
省 token✅ 合并检查❌ 每次独立

MCP 集成

OpenClaw 支持 Model Context Protocol (MCP),可以连接 MCP 服务器扩展能力:

{
  // 通过 Skills 配置 MCP
  // 或在 Agent 聊天中让 Agent 直接连接 MCP 服务器
}

Tailscale 远程访问

通过 Tailscale 安全地远程访问你的 OpenClaw Gateway。

配置步骤

  1. 安装 Tailscale:curl -fsSL https://tailscale.com/install.sh | sh
  2. 登录:sudo tailscale up
  3. 配置 OpenClaw:
{
  gateway: {
    tailscale: {
      mode: "serve",     // serve=仅 tailnet, funnel=公网可访问
    },
  },
}

使用场景

  • 🏠 家里的 Mac mini 运行 Gateway,手机 Telegram 随时访问
  • 🖥️ 公司服务器运行 Gateway,在家也能用
  • 📱 macOS App 远程连接到 Linux 服务器上的 Gateway

多 Gateway 配置

在同一台机器上运行多个独立的 Gateway 实例:

# 实例 A
OPENCLAW_CONFIG_PATH=~/.openclaw/a.json \
OPENCLAW_STATE_DIR=~/.openclaw-a \
openclaw gateway --port 19001

# 实例 B
OPENCLAW_CONFIG_PATH=~/.openclaw/b.json \
OPENCLAW_STATE_DIR=~/.openclaw-b \
openclaw gateway --port 19002

或使用内置 profile 功能:

openclaw --profile work gateway    # 用 ~/.openclaw-work 配置
openclaw --dev gateway             # 用 ~/.openclaw-dev 配置

Node 设备配对

将 iOS/Android 设备与 Gateway 配对,实现:

  • 📱 移动端 Canvas 展示
  • 📷 远程拍照
  • 📍 位置获取
  • 🔊 语音对话

配对流程

# 查看待配对设备
openclaw node pending

# 批准配对
openclaw node approve <device-id>

或通过 Telegram:

/pair              # 生成配对码
/pair approve      # 批准最新的配对请求

Webhook 集成

OpenClaw 支持 HTTP Webhook 接收外部事件:

{
  hooks: {
    enabled: true,
    token: "shared-secret",
    presets: ["gmail"],
    mappings: [{
      match: { path: "deploy" },
      action: "agent",
      messageTemplate: "部署通知:{{body}}",
      deliver: true,
      channel: "telegram",
    }],
  },
}

Gmail 监控

{
  hooks: {
    gmail: {
      account: "your@gmail.com",
      includeBody: true,
    },
  },
}

设置后,新邮件会自动推送给 Agent 处理。