工作流语法参考
用本页编写工作流 YAML。DSL 固定为 1.0.3;通过 schema 校验不代表可以执行。示例为完整工作流或 do 片段;片段需加上下列 document 头。执行前须在账户中保存示例引用的 Action 和子编排。
工作流与 document
Serverless Workflow 1.0.3 · document
document: dsl: "1.0.3" namespace: docs-samples name: example version: "1.0.0"input: schema: format: json document: { type: object }do: - ready: { set: { ready: true } }document 必填 dsl、namespace、name 和精确 semver 的 version。根级 do 必填。timeout 可内联(after: { seconds: 30 })或引用 use.timeouts。元数据不改变执行。
| Field | Schema type | Presence |
|---|---|---|
document | object | required |
document.dsl | string | required |
document.namespace | string | required |
document.name | string | required |
document.version | string | required |
document.title | string | optional |
document.summary | string | optional |
document.tags | object | optional |
document.metadata | object | optional |
input | input | optional |
use | object | optional |
use.authentications | object | optional |
use.errors | object | optional |
use.extensions | array | optional |
use.functions | object | optional |
use.retries | object | optional |
use.secrets | array | optional |
use.timeouts | object | optional |
use.catalogs | object | optional |
do | taskList | required |
timeout | union | optional |
output | output | optional |
schedule | object | optional |
schedule.timezone | string | optional |
schedule.every | duration | optional |
schedule.cron | string | optional |
schedule.after | duration | optional |
schedule.on | eventConsumptionStrategy | optional |
| Field | Schema type | Presence |
|---|---|---|
dsl | string | required |
namespace | string | required |
name | string | required |
version | string | required |
title | string | optional |
summary | string | optional |
tags | object | optional |
metadata | object | optional |
数据流
Input · Output · Export · Schema
表达式使用 jq,必须占据整个字符串 ${ … } 才求值。YAML 中始终加引号,行内映射也一样;表达式含对象花括号时外层使用单引号。其他字符串为字面量,不做插值。缺失的对象字段求值为 null;可选字段必须省略,不要传 null。
| 值 | 含义 |
|---|---|
. | 上一步输出;第一步接收工作流输入。转换表达式接收当前阶段的值。 |
input.from | 输入 schema 校验后替换输入。 |
output.as | 输出 schema 校验前替换任务或工作流输出。 |
export.as | 将任务输出转换的求值结果整个替换 $context。 |
$context | 共享上下文,初始为转换后的工作流输入。 |
$workflow.input | 原始运行输入。 |
$input | 转换后的任务输入(input.from 求值时为转换前输入)。 |
$output | 当前任务输出;根级 output.as 中为最终数据。 |
保留已有上下文并保存本步结果,使用 export: { as: '${ $context + { name: . } }' },之后读取 '${ $context.name }'。
schema 使用内联 JSON Schema:schema: { format: json, document: { type: object } }。运行时不加载外部 schema 资源。
| Field | Schema type | Presence |
|---|---|---|
schema | schema | optional |
from | union | optional |
| Field | Schema type | Presence |
|---|---|---|
schema | schema | optional |
as | union | optional |
| Field | Schema type | Presence |
|---|---|---|
schema | schema | optional |
as | union | optional |
| Field | Schema type | Presence |
|---|---|---|
if | string | optional |
input | input | optional |
output | output | optional |
export | export | optional |
timeout | union | optional |
then | flowDirective | optional |
metadata | object | optional |
use
errors、retries、timeouts 定义可引用的运行时值。secrets、authentications 只接受语法声明,运行时 Vault 与认证解析不可用。functions、catalogs、extensions 和根级 evaluate 不会安装函数目录、扩展处理器或表达式引擎;请使用 Action id 与 jq。
| Field | Schema type | Presence |
|---|---|---|
authentications | object | optional |
errors | object | optional |
extensions | array | optional |
functions | object | optional |
retries | object | optional |
secrets | array | optional |
timeouts | object | optional |
catalogs | object | optional |
schedule
使用 cron 或 every,可选 IANA timezone(默认 UTC)。调度校验拒绝 after、on;它不是事件订阅。
| Field | Schema type | Presence |
|---|---|---|
timezone | string | optional |
every | duration | optional |
cron | string | optional |
after | duration | optional |
on | eventConsumptionStrategy | optional |
document: dsl: "1.0.3" namespace: docs-samples name: example version: "1.0.0"schedule: { cron: "0 9 * * *", timezone: Asia/Shanghai }do: - ready: { set: { ready: true } }call
调用 Action。call 为 namespace/name,短名解析到 praxis;with 是参数,省略为 {}。输出是 Action 的结果。内置 Action 可写 praxis/...。这里不执行上游 HTTP、OpenAPI、gRPC、AsyncAPI、A2A 或 MCP 协议调用。
| Field | Schema type | Presence |
|---|---|---|
if | string | optional |
input | input | optional |
output | output | optional |
export | export | optional |
timeout | union | optional |
then | flowDirective | optional |
metadata | object | optional |
call | string | required |
with | object | optional |
do: - callAction: call: demo/add-one with: { n: 1 }run
运行已保存的脚本或工作流。run.script、run.workflow 接受 ns/name@range 或 {namespace, name, version, input};对象的输入省略为 {},字符串形式的输入来自任务 with。await 默认 true,输出为子运行结果;false 返回 {run_id}。内联脚本、shell、container 不在执行范围内。
| Field | Schema type | Presence |
|---|---|---|
if | string | optional |
input | input | optional |
output | output | optional |
export | export | optional |
timeout | union | optional |
then | flowDirective | optional |
metadata | object | optional |
run | object | required |
run.workflow | union | optional |
run.workflow.namespace | string | required |
run.workflow.name | string | required |
run.workflow.version | string | required |
run.workflow.input | object | optional |
run.script | union | optional |
run.script.namespace | string | required |
run.script.name | string | required |
run.script.version | string | required |
run.script.input | object | optional |
run.await | boolean | optional |
with | object | optional |
do: - child: run: script: { namespace: demo, name: summarize, version: "1.0.0", input: { text: hello } }wait
暂停指定时长,输出保持输入。使用 days、hours、minutes、seconds、milliseconds 的非负数字对象或 PT1S 这样的时长。不要使用年月单位。
| Field | Schema type | Presence |
|---|---|---|
if | string | optional |
input | input | optional |
output | output | optional |
export | export | optional |
timeout | union | optional |
then | flowDirective | optional |
metadata | object | optional |
wait | duration | required |
do: - pause: wait: { seconds: 1 }set
将对象或表达式的求值结果作为输出。不会自动把字段合并到输入或 $context。
| Field | Schema type | Presence |
|---|---|---|
if | string | optional |
input | input | optional |
output | output | optional |
export | export | optional |
timeout | union | optional |
then | flowDirective | optional |
metadata | object | optional |
set | union | required |
do: - value: set: { greeting: hello } export: { as: '${ $context + { name: . } }' }for
顺序遍历数组或对象的值。each 默认 item,at 默认 index(从 0 开始);用 $item、$index 访问。while 在每轮前求值,只有 true 继续。输出是最后一轮的最终输出,空集合保留输入,不自动收集为数组。
| Field | Schema type | Presence |
|---|---|---|
if | string | optional |
input | input | optional |
output | output | optional |
export | export | optional |
timeout | union | optional |
then | flowDirective | optional |
metadata | object | optional |
for | object | required |
for.each | string | optional |
for.in | string | required |
for.at | string | optional |
while | string | optional |
do | taskList | required |
do: - items: for: { each: item, at: index, in: '${ [1, 2] }' } do: - value: set: { value: '${ $item }', index: '${ $index }' }fork
并行执行 branches。compete 默认 false,输出按分支顺序组成数组;true 取首先成功的分支输出。分支内不能 listen 或发起审批。最多 10 个分支,嵌套扇出最多 25。
| Field | Schema type | Presence |
|---|---|---|
if | string | optional |
input | input | optional |
output | output | optional |
export | export | optional |
timeout | union | optional |
then | flowDirective | optional |
metadata | object | optional |
fork | object | required |
fork.branches | taskList | required |
fork.compete | boolean | optional |
do: - parallel: fork: branches: - first: { set: { value: 1 } } - second: { set: { value: 2 } }try
执行 try 列表,catch 用 errors.with 静态匹配错误字段;as 默认 error,when/exceptWhen 控制捕获,do 执行恢复。retry 可内联或引用 use.retries,支持 delay、backoff、jitter、limit、when/exceptWhen。attempt.count 不含首次执行;attempt.duration 限每次重试,limit.duration 从首次失败计时。输出为成功执行或恢复列表的最终输出。没有匹配的 catch 时错误继续传播。
| Field | Schema type | Presence |
|---|---|---|
if | string | optional |
input | input | optional |
output | output | optional |
export | export | optional |
timeout | union | optional |
then | flowDirective | optional |
metadata | object | optional |
try | taskList | required |
catch | object | required |
catch.errors | object | optional |
catch.errors.with | errorFilter | optional |
catch.as | string | optional |
catch.when | string | optional |
catch.exceptWhen | string | optional |
catch.retry | union | optional |
catch.do | taskList | optional |
do: - guarded: try: - fail: raise: error: { type: "https://example.com/errors/rejected", status: 400 } catch: as: error retry: delay: { seconds: 1 } limit: { attempt: { count: 1 } } do: - recover: { set: { recovered: true } }switch
按顺序选择第一个 when 为 true 的分支,无 when 的分支作默认。then 为 continue、end、exit 或同一列表的步骤名。输出保持输入;分支不是任务列表。
| Field | Schema type | Presence |
|---|---|---|
if | string | optional |
input | input | optional |
output | output | optional |
export | export | optional |
timeout | union | optional |
then | flowDirective | optional |
metadata | object | optional |
switch | array | required |
do: - choose: switch: - yes: { when: '${ .enabled == true }', then: end } - otherwise: { then: continue } - finish: { set: { done: true } }raise
抛出内联 error 或 use.errors 中的名字,要求 type 与 status;title、detail 保留。没有正常输出,可由 try/catch 捕获。
| Field | Schema type | Presence |
|---|---|---|
if | string | optional |
input | input | optional |
output | output | optional |
export | export | optional |
timeout | union | optional |
then | flowDirective | optional |
metadata | object | optional |
raise | object | required |
raise.error | union | required |
do: - fail: raise: error: { type: "https://example.com/errors/rejected", status: 400, detail: "Review required" }listen
只支持 fork 外的 to.one,或含 1–8 个过滤器的 to.any。with.type 必须是字面字符串,source/subject 可选且为字面字符串,data 可为 jq 布尔表达式。read 默认 data,输出事件 data;envelope 输出完整事件。to.all、until、foreach、raw、动态 type 不能运行。timeout 可内联或引用 use.timeouts。
| Field | Schema type | Presence |
|---|---|---|
if | string | optional |
input | input | optional |
output | output | optional |
export | export | optional |
timeout | union | optional |
then | flowDirective | optional |
metadata | object | optional |
listen | object | required |
listen.to | eventConsumptionStrategy | required |
listen.read | data / envelope / raw | optional |
foreach | subscriptionIterator | optional |
do: - received: listen: to: one: with: { type: "order.ready" } read: datado
顺序执行命名任务列表,输出为最后一步的输出。同一列表的名字必须唯一;每个任务恰有一个任务种类(for 同时带 do)。
| Field | Schema type | Presence |
|---|---|---|
if | string | optional |
input | input | optional |
output | output | optional |
export | export | optional |
timeout | union | optional |
then | flowDirective | optional |
metadata | object | optional |
do | taskList | required |
do: - group: do: - value: { set: { ready: true } }praxis/approval
call: praxis/approval 是内置异步函数,不是 Action。with 在创建人工任务前校验,工作流等待结算,以 outcome 作为步骤输出。不能放在 fork 分支中。完整输入与结果契约见审批指南。
emit
不能执行:schema 校验可接受 emit,但创建运行时返回 DEFINITION_INVALID,没有输出。
错误
catch 对完整 type URI 和其他字段做精确匹配。标准 type 前缀为 https://serverlessworkflow.io/spec/1.0.0/errors/,后接 validation、expression、configuration、authentication、authorization、communication、timeout 或 runtime。错误含 type、status、instance(任务指针),可选 title、detail、code、request_id、errors、upstream。自定义 raise 保留 type URI。服务预算与深度失败使用 BUDGET_EXCEEDED / DEPTH_LIMIT_EXCEEDED,截止时间使用 TIMEOUT;catch 不能绕过运行硬限制或工作流截止时间。
校验响应的 errors[] 每项含 pointer(JSON Pointer 或源码行列路径)、detail(失败原因)、可选 hint(修复建议)。先读第一条,修复后重新校验。
| Field | Schema type | Presence |
|---|---|---|
type | union | required |
status | integer | required |
instance | union | optional |
title | union | optional |
detail | union | optional |
| Field | Schema type | Presence |
|---|---|---|
when | string | optional |
exceptWhen | string | optional |
delay | duration | optional |
backoff | object | optional |
backoff.constant | object | required |
backoff.exponential | object | required |
backoff.linear | object | required |
limit | object | optional |
limit.attempt | object | optional |
limit.attempt.count | integer | optional |
limit.attempt.duration | duration | optional |
limit.duration | duration | optional |
jitter | object | optional |
jitter.from | duration | required |
jitter.to | duration | required |
Serverless Workflow 1.0.3 支持矩阵
supported 表示可执行;planned 表示目前被拒绝;not supported by design 表示按设计拒绝。accepted-inert:目前会被接受,但没有运行时效果(计划支持)。具体而言,use.secrets / use.authentications 不解析密钥或认证;call: a2a / call: mcp 分别按 praxis 中名为 a2a / mcp 的 Action 解析,而这些 Action 不存在,不会调用协议运行时。表中也逐项列出其他目前会被接受的声明与形似协议的 Action 名称。
| Construct | Status | Main fields | Runtime boundary |
|---|---|---|---|
| document | supported | dsl, namespace, name, version, title, summary, tags, metadata | Executed by the workflow input/task/output pipeline. |
| input | supported | schema, from | Executed by the workflow input/task/output pipeline. |
| output | supported | schema, as | Executed by the workflow input/task/output pipeline. |
| do | supported | Executed by the workflow input/task/output pipeline. | |
| timeout | supported | after | Executed by the workflow input/task/output pipeline. |
| use | supported | authentications, errors, extensions, functions, retries, secrets, timeouts, catalogs | Named errors, retries and timeouts are resolved by the interpreter. |
| schedule | supported | timezone, every, cron, after, on | cron/every with optional timezone; after/on are refused. |
| evaluate | accepted-inert | Expression-engine selection is not wired; jq is used. Declaration is accepted without runtime resolution. | |
| use.secrets | accepted-inert | Declaration is accepted but Vault/authentication resolution has no runtime effect. | |
| use.authentications | accepted-inert | Declaration is accepted but Vault/authentication resolution has no runtime effect. | |
| use.functions | accepted-inert | No runtime resolver/handler; declaration syntax is accepted. | |
| use.catalogs | accepted-inert | No runtime resolver/handler; declaration syntax is accepted. | |
| use.extensions | accepted-inert | No runtime resolver/handler; declaration syntax is accepted. | |
| call | supported | if, input, output, export, timeout, then, metadata, call, with | See the task section for output and runtime restrictions. |
| run | supported | if, input, output, export, timeout, then, metadata, run, run.workflow, run.workflow.namespace, run.workflow.name, run.workflow.version, run.workflow.input, run.script, run.script.namespace, run.script.name, run.script.version, run.script.input | See the task section for output and runtime restrictions. |
| wait | supported | if, input, output, export, timeout, then, metadata, wait | See the task section for output and runtime restrictions. |
| set | supported | if, input, output, export, timeout, then, metadata, set | See the task section for output and runtime restrictions. |
| for | supported | if, input, output, export, timeout, then, metadata, for, for.each, for.in, for.at, while, do | See the task section for output and runtime restrictions. |
| fork | supported | if, input, output, export, timeout, then, metadata, fork, fork.branches, fork.compete | See the task section for output and runtime restrictions. |
| try | supported | if, input, output, export, timeout, then, metadata, try, catch, catch.errors, catch.errors.with, catch.as, catch.when, catch.exceptWhen, catch.retry, catch.do | See the task section for output and runtime restrictions. |
| switch | supported | if, input, output, export, timeout, then, metadata, switch | See the task section for output and runtime restrictions. |
| raise | supported | if, input, output, export, timeout, then, metadata, raise, raise.error | See the task section for output and runtime restrictions. |
| listen | supported | if, input, output, export, timeout, then, metadata, listen, listen.to, listen.read, foreach | See the task section for output and runtime restrictions. |
| do | supported | if, input, output, export, timeout, then, metadata, do | See the task section for output and runtime restrictions. |
| emit | planned | if, input, output, export, timeout, then, metadata, emit, emit.event, emit.event.with | Event publishing runtime is not wired; run creation refuses emit. |
| call: http | accepted-inert | Resolved as the Action ID http in praxis, not an upstream protocol transport. This does not activate the upstream protocol-call configuration. | |
| call: openapi | accepted-inert | Resolved as the Action ID openapi in praxis, not an upstream protocol transport. This does not activate the upstream protocol-call configuration. | |
| call: grpc | accepted-inert | Resolved as the Action ID grpc in praxis, not an upstream protocol transport. This does not activate the upstream protocol-call configuration. | |
| call: asyncapi | accepted-inert | Resolved as the Action ID asyncapi in praxis, not an upstream protocol transport. This does not activate the upstream protocol-call configuration. | |
| call: a2a | accepted-inert | Resolved as the Action ID a2a in praxis, not an upstream protocol transport. No built-in Action with that name exists. | |
| call: mcp | accepted-inert | Resolved as the Action ID mcp in praxis, not an upstream protocol transport. No built-in Action with that name exists. | |
| run.shell | not supported by design | Only saved scripts and workflows execute. | |
| run.container | not supported by design | Only saved scripts and workflows execute. | |
| run.script.code | not supported by design | Scripts are saved and versioned before reference. | |
| listen.to.all | planned | Not executable in the event-wait subset; run creation refuses this form. | |
| listen.read.raw | planned | Not executable in the event-wait subset; run creation refuses this form. | |
| listen.foreach | planned | Not executable in the event-wait subset; run creation refuses this form. | |
| listen in fork | planned | Not executable in the event-wait subset; run creation refuses this form. | |
| approval in fork | planned | Not executable in the event-wait subset; run creation refuses this form. | |
| listen dynamic type | planned | Not executable in the event-wait subset; run creation refuses this form. | |
| listen.until | planned | Not executable in the event-wait subset; run creation refuses this form. | |
| schedule.after | planned | Schedule trigger supports cron/every only. | |
| schedule.on | planned | Schedule trigger supports cron/every only. |