Quick Tasks (respond directly)【免费下载链接】picoclawTiny, Fast, and Deployable anywhere — automate the mundane, unleash your creativity项目地址: https://gitcode.com/gh_mirrors/pi/picoclawReport current timeLong Tasks (use spawn for async)Search the web for AI news and summarizeCheck email and report important messages值得注意首次运行时如果工作区中不存在 HEARTBEAT.mdHeartbeatService 会自动生成一份默认模板见 [pkg/heartbeat/service.go](https://link.gitcode.com/i/65ddc60fb4a9245dcef5d1306639c35e)。模板末尾有一行固定标记Add your heartbeat tasks below this line:模板要求代理执行以下列出的所有任务不要跳过任何一项简单任务直接回答复杂任务使用 spawn 创建子代理spawn 是异步的子代理结果会自动发送给用户生成子代理后继续处理剩余任务只有当所有任务完成且无需关注时才回复 HEARTBEAT_OK。heartbeatHasUserTasks 函数[pkg/heartbeat/service.go](https://link.gitcode.com/i/8346840a67bf3b67efdca25b9c0ac385)会检查该标记下方的非注释、非空行来判断用户是否已填写任务如果 HEARTBEAT.md 缺失或任务为空则跳过本轮心跳。 ## 二、核心行为spawn 如何做到非阻塞 原文档用一张表格概括了 spawn 的关键特性 | Feature | Description | | ----------------------- | --------------------------------------------------------- | | **spawn** | Creates async subagent, doesnt block heartbeat | | **Independent context** | Subagent has its own context, no session history | | **message tool** | Subagent communicates with user directly via message tool | | **Non-blocking** | After spawning, heartbeat continues to next task | 即spawn 创建的是**异步子代理**它拥有独立的上下文没有父会话历史可以通过 message 工具直接与用户通信而父代理在发起 spawn 后立即继续处理下一项任务互不阻塞。 ### 子代理通信的完整流程 原文档给出了如下流程图Heartbeat triggers (心跳被触发) ↓ Agent reads HEARTBEAT.md (代理读取 HEARTBEAT.md) ↓ For long task: spawn subagent (对长任务spawn 子代理) ↓ ↓ Continue to next task Subagent works independently (继续下一项任务) (子代理独立工作) ↓ ↓ All tasks done Subagent uses message tool (所有任务完成) (子代理使用 message 工具) ↓ ↓ Respond HEARTBEAT_OK User receives result directly (回复 HEARTBEAT_OK) (用户直接收到结果)子代理可以访问各类工具message、web_search 等并能够**绕过主代理、独立地与用户沟通**——这就是异步模式的核心价值心跳循环不等待长任务完成用户体验到的是任务派发后结果自动送达。 ### 源码印证HeartbeatService 的执行逻辑 从 [pkg/heartbeat/service.go](https://link.gitcode.com/i/7a8ed14c6b43dc22ede3f8b350a06e45) 的 executeHeartbeat 可以看到心跳处理结果被分为四种类型分支 1. **result.IsError**记录错误日志后返回 2. **result.Async**记录异步任务已启动直接返回——这正是 spawn 走的路径心跳不等待子代理结果 3. **result.Silent**记录 Heartbeat OK - silent 后静默返回message 工具发送完消息后返回 Silent: true避免重复播报 4. **其余情况**将 ForUser或 ForLLM内容通过消息总线发送给用户。 结果投递由 sendResponse 完成[pkg/heartbeat/service.go](https://link.gitcode.com/i/f14ac4199e18cb962da5f16f6c273c3d)它会读取 state 中记录的最后活跃频道格式为 platform:user_id如 telegram:123456跳过内部频道后通过 bus.PublishOutbound 发送。每次心跳的调试与错误信息会追加写入工作区的 heartbeat.log 文件[pkg/heartbeat/service.go](https://link.gitcode.com/i/9b601828a3f15b0dfd03bd9cd6c758d1)。 ## 三、Heartbeat 配置JSON 配置与参数说明 ### 配置文件方式 在 PicoClaw 的 JSON 配置文件中完整示例见 [config/config.example.json](https://link.gitcode.com/i/aa2031ff21094e718055bb8ea994eb17)心跳配置位于 heartbeat 字段 json { heartbeat: { enabled: true, interval: 30 } }两个参数的语义如下与原文档参数表一致OptionDefaultDescriptionenabledtrueEnable/disable heartbeatinterval30Check interval in minutes (min: 5)源码中的默认值与下限约束上述默认值在 pkg/config/defaults.go 中定义Enabled: true, Interval: 30。结构体定义见 pkg/config/config.go。值得注意的下限约束在 pkg/heartbeat/service.go 的NewHeartbeatService中实现const ( minIntervalMinutes 5 defaultIntervalMinutes 30 ) // 小于 5 分钟会被钳制到 5为 0 时使用默认值 30 if intervalMinutes minIntervalMinutes intervalMinutes ! 0 { intervalMinutes minIntervalMinutes } if intervalMinutes 0 { intervalMinutes defaultIntervalMinutes }【免费下载链接】picoclawTiny, Fast, and Deployable anywhere — automate the mundane, unleash your creativity项目地址: https://gitcode.com/gh_mirrors/pi/picoclaw创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
