心跳在主会话中运行周期性 Agent 轮次,让模型可以主动关注需要处理的事项。
注意:心跳不创建后台任务记录(任务记录用于后台工作)。
快速配置
{
agents: {
defaults: {
heartbeat: {
every: "30m", // 间隔(0m 禁用)
target: "last", // none | last | <channel:id>
directPolicy: "allow", // allow | block(DM 投递策略)
lightContext: true, // 仅注入 HEARTBEAT.md(轻量上下文)
isolatedSession: true, // 每次运行新鲜会话(无对话历史)
skipWhenBusy: true, // 子 Agent 或嵌套通道忙时推迟
// activeHours: { start: "08:00", end: "24:00" },
// includeReasoning: true, // 同时发送推理消息
ackMaxChars: 100, // HEARTBEAT_OK 最大填充字符数
},
},
},
}默认行为
- 默认间隔:30 分钟(Anthropic OAuth/token auth 为 1 小时)
- 默认提示词:
Read HEARTBEAT.md if it exists. Follow it strictly. If nothing needs attention, reply HEARTBEAT_OK. HEARTBEAT.md为空(仅空行/标题)→ 跳过心跳(empty-heartbeat-file)- Agent 回复
HEARTBEAT_OK→ 抑制出站投递
HEARTBEAT.md 格式
# Heartbeat checklist
- Check inbox for urgent messages
- Review calendar for upcoming events
tasks:
- id: daily-report
due: "09:00"
prompt: "Generate daily status report"心跳 vs Cron
| 心跳 | Cron | |
|---|---|---|
| 时间精度 | 近似(约 30 分钟) | 精确 |
| 会话上下文 | 完整主会话 | 新鲜/隔离 |
| 任务记录 | 不创建 | 始终创建 |
| 适合 | 收件箱检查、日历监控 | 报告、提醒 |
相关
- concepts/automation-overview — 自动化机制选择
- concepts/automation-cron — 定时任务
- commitments — 推断承诺