自动化中等风险

TaskFlow 持久化任务流编排

OpenClaw 平台下的持久化任务流(TaskFlow)运行时技能,用于跨多步、跨 detached 子任务的工作编排,提供流程标识、状态持久化、子任务关联、等待与版本化变更等能力。

by @yihuiv1.0.06 浏览3 下载
#durable-state#OpenClaw#orchestration#revision-checked#runtime#subagent#task-management
推荐方式

直接交给 AI

无需安装文件。复制一句话,让 AI 在线读取这个 Skill。

下载 Skill ZIP ↓ 查看 SKILL.md 原文 ↗
01

它能帮你做什么

先看懂,再决定要不要交给 AI。

TaskFlow 是一个面向 OpenClaw 运行时的"持久化流程底座"。当一项工作需要跨越多个 prompt、多个 detached 子任务(如 ACP、子代理、插件任务)时,TaskFlow 会将其视作同一个作业,维护统一的 owner 会话、统一的返回上下文,以及单一可恢复的状态。技能覆盖典型 managed-flow 生命周期:createManaged → runTask → setWaiting → resume → finish/fail/requestCancel/cancel。状态通过 stateJson 持久化,所有变更采用 revision-checked 模式以避免冲突,适合需要等待外部信号、需要可中断恢复、需要在升级前清理活动子任务的工作。与 Lobster、acpx、插件或普通调用代码配合使用:把分支与业务逻辑保留在调用方,TaskFlow 只承担流程标识、子任务链接、等待状态、版本化变更与用户面呈现等职责。

✓跨多步后台工作并保持单一 owner 上下文
✓编排等待 detached ACP 或子代理任务的作业
✓为工作流增加可恢复的等待/阻塞状态
✓在插件或工具中持久化跨重启的中间状态
✓对需要处理版本冲突的多步流程进行安全变更
02

怎么交给 AI

在线读取优先,本地安装作为备选。

◎
在线读取推荐 · 不需要安装

适合能访问网页的 ChatGPT、Agent 或其他 AI。

AI Prompt请访问 https://skills.dhmip.cn/skills/yihui/yihui-taskflow/SKILL.md,读取并按照该 Skill 完成任务;如当前环境支持本地安装,也可以下载该 Skill。
↓
下载安装到 Agent适合支持 Skills 的客户端

未登录时可使用公共安装文档;登录后可以按不同 AI 分开管理。

Install Prompt请根据 https://skills.dhmip.cn/install/skillhub.md,安装 @yihui/yihui-taskflow。
登录后管理多个 AI →
03

兼容性与要求

安装或使用前,先确认环境是否匹配。

适用客户端

openclaw

使用要求

  • OpenClaw 兼容运行平台
  • 宿主上下文中存在 api.runtime.tasks.flow 入口(或其别名 api.runtime.taskFlow)
  • 调用方具备可信 tool context 中的 sessionKey 或可自行解析 bindSession
  • 调用方负责托管状态与决定分支逻辑(如 Lobster / acpx / 普通代码)
⌘技术详情查看完整 SKILL.md 与原始内容
⌄
SKILL.mdRaw ↗

name: taskflow
description: Use when work should span one or more detached tasks but still behave like one job with a single owner context. TaskFlow is the durable flow substrate under authoring layers like Lobster, ACPX, plugins, or plain code. Keep conditional logic in the caller; use TaskFlow for flow identity, child-task linkage, waiting state, revision-checked mutations, and user-facing emergence.
metadata: { "openclaw": { "emoji": "🪝" } }


tags:

  • workflow
  • orchestration
  • task-management

compatibility: openclaw
license: MIT

TaskFlow

Use TaskFlow when a job needs to outlive one prompt or one detached run, but you still want one owner session, one return context, and one place to inspect or resume the work.

When to use it

  • Multi-step background work with one owner
  • Work that waits on detached ACP or subagent tasks
  • Jobs that may need to emit one clear update back to the owner
  • Jobs that need small persisted state between steps
  • Plugin or tool work that must survive restarts and revision conflicts cleanly

What TaskFlow owns

  • flow identity
  • owner session and requester origin
  • currentStep, stateJson, and waitJson
  • linked child tasks and their parent flow id
  • finish, fail, cancel, waiting, and blocked state
  • revision tracking for conflict-safe mutations

It does not own branching or business logic. Put that in Lobster, acpx, or the calling code.

Current runtime shape

Canonical plugin/runtime entrypoint:

  • api.runtime.tasks.flow
  • api.runtime.taskFlow still exists as an alias, but api.runtime.tasks.flow is the canonical shape

Binding:

  • api.runtime.tasks.flow.fromToolContext(ctx) when you already have trusted tool context with sessionKey
  • api.runtime.tasks.flow.bindSession({ sessionKey, requesterOrigin }) when your binding layer already resolved the session and delivery context

Managed-flow lifecycle:

  1. createManaged(...)
  2. runTask(...)
  3. setWaiting(...) when waiting on a person or an external system
  4. resume(...) when work can continue
  5. finish(...) or fail(...)
  6. requestCancel(...) or cancel(...) when the whole job should stop

Design constraints

  • Use managed TaskFlows when your code owns the orchestration.
  • One-task mirrored flows are created by core runtime for detached ACP/subagent work; this skill is mainly about managed flows.
  • Treat stateJson as the persisted state bag. There is no separate setFlowOutput or appendFlowOutput API.
  • Every mutating method after creation is revision-checked. Carry forward the latest flow.revision after each successful mutation.
  • runTask(...) links the child task to the flow. Use it instead of manually creating detached tasks when you want parent orchestration.

Example shape

const taskFlow = api.runtime.tasks.flow.fromToolContext(ctx);

const created = taskFlow.createManaged({
  controllerId: "my-plugin/inbox-triage",
  goal: "triage inbox",
  currentStep: "classify",
  stateJson: {
    businessThreads: [],
    personalItems: [],
    eodSummary: [],
  },
});

const classify = taskFlow.runTask({
  flowId: created.flowId,
  runtime: "acp",
  childSessionKey: "agent:main:subagent:classifier",
  runId: "inbox-classify-1",
  task: "Classify inbox messages",
  status: "running",
  startedAt: Date.now(),
  lastEventAt: Date.now(),
});

if (!classify.created) {
  throw new Error(classify.reason);
}

const waiting = taskFlow.setWaiting({
  flowId: created.flowId,
  expectedRevision: created.revision,
  currentStep: "await_business_reply",
  stateJson: {
    businessThreads: ["slack:thread-1"],
    personalItems: [],
    eodSummary: [],
  },
  waitJson: {
    kind: "reply",
    channel: "slack",
    threadKey: "slack:thread-1",
  },
});

if (!waiting.applied) {
  throw new Error(waiting.code);
}

const resumed = taskFlow.resume({
  flowId: waiting.flow.flowId,
  expectedRevision: waiting.flow.revision,
  status: "running",
  currentStep: "finalize",
  stateJson: waiting.flow.stateJson,
});

if (!resumed.applied) {
  throw new Error(resumed.code);
}

taskFlow.finish({
  flowId: resumed.flow.flowId,
  expectedRevision: resumed.flow.revision,
  stateJson: resumed.flow.stateJson,
});

Keep conditionals above the runtime

Use the flow runtime for state and task linkage. Keep decisions in the authoring layer:

  • business → post to Slack and wait
  • personal → notify the owner now
  • later → append to an end-of-day summary bucket

Operational pattern

  • Store only the minimum state needed to resume.
  • Put human-readable wait reasons in blockedSummary or structured wait metadata in waitJson.
  • Use getTaskSummary(flowId) when the orchestrator needs a compact health view of child work.
  • Use requestCancel(...) when a caller wants the flow to stop scheduling immediately.
  • Use cancel(...) when you also want active linked child tasks cancelled.

Examples

  • See skills/taskflow/examples/inbox-triage.lobster
  • See skills/taskflow/examples/pr-intake.lobster
  • See skills/taskflow-inbox-triage/SKILL.md for a concrete routing pattern