stp结构化任务规划与分步执行 V2(异步子代理架构)。支持将每个步骤通过 session_spawn 创建子代理异步执行,主会话保持非阻塞。功能包括:步骤分解、子代理执行、子代理检验(LLM判断)、状态跟踪、Heartbeat 监控、任务中断。触发词:/stp、任务规划、步骤执行。
Install via ClawdBot CLI:
clawdbot install scotthuang/stp路径变量说明(本文档通用):
-=~/.openclaw/workspace/skills/stp
-=/scripts
-=~/.openclaw/workspace/task-list
-=~/.openclaw/workspace/tasks
重大更新:V2 采用子代理异步架构,每个步骤通过 session_spawn 创建独立的子代理执行,主会话保持非阻塞,彻底解决了 V1 长任务阻塞主会话的问题。
session_spawn 创建子代理执行,主会话非阻塞主会话 (非阻塞)
│
├── session_spawn (步骤执行) → 执行子代理
│ │
│ └──→ announce 完成/失败
│
├── session_spawn (步骤检验) → 检验子代理 (LLM)
│ │
│ └──→ 返回通过/不通过
│
└── heartbeat (定时检查) → 监控子代理状态
# 任务名称
## 任务描述
用户原始需求的简要描述
## 技术方案
- 使用的工具/库/API
- 关键技术约束
## 全局设置
- 步骤超时时间: [无超时 / N 分钟]
- 任务完成后删除目录: [是 / 否](默认否,保留任务记录)
## 核心执行步骤
- [ ] 步骤 1:具体描述
- **执行 Prompt**: 给执行子代理的具体指令
- **检验标准**: 给检验子代理(LLM)的验证条件,用于判断步骤是否成功完成
- [ ] 步骤 2:具体描述
- **执行 Prompt**: xxx
- **检验标准**: xxx
...
## 预期产出
- 输出文件/结果说明
📋 任务计划书已生成
任务名称:xxx
文件位置:~/.openclaw/workspace/tasks/task-xxx/task_steps.md
步骤数:3
全局设置:
- 步骤超时时间:无超时
- 任务完成后删除目录:否(默认保留)
核心执行步骤:
- [ ] 步骤 1:编写股票查询脚本
- 执行 Prompt:编写 Python 脚本,使用 AkShare 查询股票数据
- 检验标准:脚本存在于 temp/scripts/stock_query.py,可执行无报错
- [ ] 步骤 2:查询贵州茅台收盘价
- 执行 Prompt:运行脚本查询 600519.SH
- 检验标准:输出包含"600519.SH"和收盘价数值
...
========================================
确认执行:
输入 "ok" 或 "确认" → 开始执行
输入 "取消" → 放弃此任务
输入 "修改" → 调整计划
输入 "超时 30" → 设置每个步骤超时 30 分钟
输入 "删除" 或 "清理" → 任务完成后删除目录
========================================
~/.openclaw/workspace/tasks/
└── task-{ID}/
├── stp-plan-{ID}.md # 计划书
├── task_steps.md # 步骤文档(含状态、子代理ID、超时计数)
└── temp/
├── scripts/
└── downloads/
## 任务基础信息
- 任务名称:xxx
- 任务ID:task-1
- 创建时间:2026-02-28 22:00:00
- 步骤超时时间:无超时
## 核心执行步骤
### 步骤 1:编写股票查询脚本
- **状态**: 执行中
- **执行子代理**: subagent:abc (runId: xyz)
- **检验子代理**: 待创建
- **超时计数**: 执行(0/2) | 检验(0/2)
- **执行 Prompt**: 编写 Python 脚本...
- **检验标准**: 脚本存在于 temp/scripts/stock_query.py
### 步骤 2:查询贵州茅台
- **状态**: 待执行
...
待执行 → 执行中 → 待检验 → 检验中 → (通过) → 待执行(下一步)
↓ (不通过)
等待用户决策(调整/重试/终止)
⚠️ 注意:执行中 → 待检验 → 检验中 是必经步骤,禁止跳过!
⚠️ 重要:必须先展示计划书并确认,才能执行!
完整流程:
~/.openclaw/workspace/tasks/ 下创建新的 task-{ID} 目录(ID 自增)task-{ID}/stp-plan-{ID}.mdstp_orchestrator.py start 初始化任务
sessions_spawn(
task="<步骤 1 的执行 Prompt>",
label="task-{ID}-step-1-exec",
cleanup="keep"
)
禁止跳过确认步骤!
⚠️ 重要:每个任务必须独立思考!
sessions_spawn(
task="<步骤的执行 Prompt>",
label="task-{ID}-step-{N}-exec",
cleanup="keep"
)
⚠️ 重要:执行子代理完成后,必须先检验才能执行下一步!禁止跳过检验步骤!禁止让主会话 LLM 直接判断检验结果!
sessions_spawn(
task="请根据以下检验标准判断步骤是否成功完成。
检验标准:{步骤的检验标准}
执行结果:{执行子代理的输出}
请返回:通过 / 不通过,并说明原因",
label="task-{ID}-step-{N}-verify",
cleanup="keep"
)
start 命令自动创建 cron job(stp-heartbeat-{task_id})heartbeat sessions_history_sync 获取实际状态tool_count == 0:pending(等待开始)is_running == true(正在等待工具返回或最近 5 分钟有活动):running(执行中)is_running == false 且超过 5 分钟无活动:completed(已完成)| 字段 | 说明 |
|------|------|
| tool_count | 工具调用次数 |
| tool_call_count | toolCall 数量 |
| tool_result_count | toolResult 数量 |
| is_waiting | 等待工具返回中(toolCall > toolResult) |
| is_running | 正在执行(is_waiting 或最近 5 分钟有活动) |
| is_recent | 最近 5 分钟有活动 |
| 状态 | 条件 | 处理 |
|------|------|------|
| pending | tool_count == 0 | 等待 |
| running | 最近 5 分钟有活动 | 正常 |
| completed | 超过 5 分钟无活动 | 通知用户,更新状态 |
| stuck | 超过 30 分钟无活动 | 增加超时计数,>= 2 则告知用户 |
completed_subagents 有内容:通知用户子任务完成,需要继续检验stuck_count > 0 且超时计数 >= 2:提示用户决定是否重试或终止⚠️ 步骤 2 可能已挂死
执行子代理已等待 30+ 分钟无响应
Tool: exec (git clone ...)
请选择:
- 继续等待 → 再次等待 10 分钟
- 重试 → 终止当前子代理,重新执行
- 终止 → 结束整个任务
用户输入:中断 {任务名称} 或 中断 task-{ID}
task-23 → 23)python3 /stp_orchestrator.py interrupt subagent_ids_for_kill 列表
subagents(action="kill", target="agent:main:subagent:xxx")
(注意:target 需要完整的 session key,如 agent:main:subagent:xxx)
sessions_history 获取其执行历史details.pid(进程 PID)kill 杀掉进程# 启动任务(自动创建 cron job 用于 heartbeat)
python3 <STP_SCRIPTS>/stp_orchestrator.py start <plan_file>
# 查看任务状态
python3 <STP_SCRIPTS>/stp_orchestrator.py status <task_id>
# 检查 heartbeat(需要传入 task_id)
python3 <STP_SCRIPTS>/stp_orchestrator.py heartbeat <task_id>
# 中断任务(自动删除对应的 cron job)
python3 <STP_SCRIPTS>/stp_orchestrator.py interrupt <task_id>
start 命令自动创建 cron job(stp-heartbeat-{task_id}),每 10 分钟检查一次heartbeat interrupt 命令自动删除对应的 cron job无需配置 HEARTBEAT.md,完全自动化。
# 用户:帮我查三支股票价格
# AI 自动生成计划书,用户确认后:
python3 <STP_SCRIPTS>/stp_orchestrator.py start ~/.openclaw/workspace/tasks/task-xxx/stp-plan-xxx.md
用户: 帮我查三支股票价格
[AI 根据用户需求动态生成计划书]
📋 任务计划书已生成
文件:~/.openclaw/workspace/tasks/task-xxx/stp-plan-xxx.md
步骤数:3
...
用户: ok
✅ 任务已启动 (task-1)
你可以继续做其他事,我会定期汇报进度
⚠️ **如需终止任务**,请输入:中断 task-{ID}
---
### 7.4 主会话中断任务示例
用户: 中断 task-23
[主会话执行:]
```
task-{ID}/,用户取消后也保留stp-plan-{ID}.mdresult.txt 和 task_execution.logexecute、verify、retry 命令Generated Mar 1, 2026
An investment firm needs to generate daily stock performance reports by querying multiple APIs, processing data, and compiling PDFs. This involves sequential steps like data extraction, analysis, and formatting, which can be long-running and prone to blocking in synchronous setups.
An online retailer automates order processing from payment confirmation to shipping label generation. Steps include inventory checks, payment verification, and logistics coordination, requiring isolated execution to handle failures without disrupting the main workflow.
A tech company automates code deployment across staging and production environments. Steps involve building, testing, and deploying applications, with validation checks at each stage to ensure stability and compliance before proceeding.
A hospital system processes patient records by anonymizing data, running analytics, and generating compliance reports. Each step must be verified for accuracy and privacy before moving to the next, with monitoring for long-running tasks.
A marketing agency automates multi-channel campaigns by scheduling social media posts, email blasts, and ad placements. Steps are planned and executed asynchronously, with validation to ensure content alignment and performance metrics.
Offer a cloud-based service where businesses can upload task plans, and the platform handles execution via subagents. Revenue comes from subscription tiers based on task complexity and volume, with premium support for custom integrations.
Provide expert services to design and deploy structured task plans for clients in specific industries. Revenue is generated through project-based fees and ongoing maintenance contracts for monitoring and optimization.
License the skill package to other software vendors or enterprises for embedding into their own products. Revenue streams include upfront licensing fees and royalties based on usage or transaction volumes.
💬 Integration Tip
Ensure robust error handling and user confirmation flows to prevent unintended task executions, and leverage the heartbeat monitoring for reliability in production environments.
Manage Trello boards, lists, and cards via the Trello REST API.
Sync and query CalDAV calendars (iCloud, Google, Fastmail, Nextcloud, etc.) using vdirsyncer + khal. Works on Linux.
Manage tasks and projects in Todoist. Use when user asks about tasks, to-dos, reminders, or productivity.
Master OpenClaw's timing systems. Use for scheduling reliable reminders, setting up periodic maintenance (janitor jobs), and understanding when to use Cron v...
Calendar management and scheduling. Create events, manage meetings, and sync across calendar providers.
Kanban-style task management dashboard for AI assistants. Manage tasks via CLI or dashboard UI. Use when user mentions tasks, kanban, task board, mission con...