跳转到内容
EN

工作流语法参考

用本页编写工作流 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。元数据不改变执行。

FieldSchema typePresence
documentobjectrequired
document.dslstringrequired
document.namespacestringrequired
document.namestringrequired
document.versionstringrequired
document.titlestringoptional
document.summarystringoptional
document.tagsobjectoptional
document.metadataobjectoptional
inputinputoptional
useobjectoptional
use.authenticationsobjectoptional
use.errorsobjectoptional
use.extensionsarrayoptional
use.functionsobjectoptional
use.retriesobjectoptional
use.secretsarrayoptional
use.timeoutsobjectoptional
use.catalogsobjectoptional
dotaskListrequired
timeoutunionoptional
outputoutputoptional
scheduleobjectoptional
schedule.timezonestringoptional
schedule.everydurationoptional
schedule.cronstringoptional
schedule.afterdurationoptional
schedule.oneventConsumptionStrategyoptional
FieldSchema typePresence
dslstringrequired
namespacestringrequired
namestringrequired
versionstringrequired
titlestringoptional
summarystringoptional
tagsobjectoptional
metadataobjectoptional

数据流

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 资源。

FieldSchema typePresence
schemaschemaoptional
fromunionoptional
FieldSchema typePresence
schemaschemaoptional
asunionoptional
FieldSchema typePresence
schemaschemaoptional
asunionoptional
FieldSchema typePresence
ifstringoptional
inputinputoptional
outputoutputoptional
exportexportoptional
timeoutunionoptional
thenflowDirectiveoptional
metadataobjectoptional

use

Use

errors、retries、timeouts 定义可引用的运行时值。secrets、authentications 只接受语法声明,运行时 Vault 与认证解析不可用。functions、catalogs、extensions 和根级 evaluate 不会安装函数目录、扩展处理器或表达式引擎;请使用 Action id 与 jq。

FieldSchema typePresence
authenticationsobjectoptional
errorsobjectoptional
extensionsarrayoptional
functionsobjectoptional
retriesobjectoptional
secretsarrayoptional
timeoutsobjectoptional
catalogsobjectoptional

schedule

Schedule

使用 cron 或 every,可选 IANA timezone(默认 UTC)。调度校验拒绝 after、on;它不是事件订阅。

FieldSchema typePresence
timezonestringoptional
everydurationoptional
cronstringoptional
afterdurationoptional
oneventConsumptionStrategyoptional
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

call

调用 Action。call 为 namespace/name,短名解析到 praxis;with 是参数,省略为 {}。输出是 Action 的结果。内置 Action 可写 praxis/...。这里不执行上游 HTTP、OpenAPI、gRPC、AsyncAPI、A2A 或 MCP 协议调用。

FieldSchema typePresence
ifstringoptional
inputinputoptional
outputoutputoptional
exportexportoptional
timeoutunionoptional
thenflowDirectiveoptional
metadataobjectoptional
callstringrequired
withobjectoptional
do:
- callAction:
call: demo/add-one
with: { n: 1 }

run

run

运行已保存的脚本或工作流。run.script、run.workflow 接受 ns/name@range 或 {namespace, name, version, input};对象的输入省略为 {},字符串形式的输入来自任务 with。await 默认 true,输出为子运行结果;false 返回 {run_id}。内联脚本、shell、container 不在执行范围内。

FieldSchema typePresence
ifstringoptional
inputinputoptional
outputoutputoptional
exportexportoptional
timeoutunionoptional
thenflowDirectiveoptional
metadataobjectoptional
runobjectrequired
run.workflowunionoptional
run.workflow.namespacestringrequired
run.workflow.namestringrequired
run.workflow.versionstringrequired
run.workflow.inputobjectoptional
run.scriptunionoptional
run.script.namespacestringrequired
run.script.namestringrequired
run.script.versionstringrequired
run.script.inputobjectoptional
run.awaitbooleanoptional
withobjectoptional
do:
- child:
run:
script: { namespace: demo, name: summarize, version: "1.0.0", input: { text: hello } }

wait

wait

暂停指定时长,输出保持输入。使用 days、hours、minutes、seconds、milliseconds 的非负数字对象或 PT1S 这样的时长。不要使用年月单位。

FieldSchema typePresence
ifstringoptional
inputinputoptional
outputoutputoptional
exportexportoptional
timeoutunionoptional
thenflowDirectiveoptional
metadataobjectoptional
waitdurationrequired
do:
- pause:
wait: { seconds: 1 }

set

set

将对象或表达式的求值结果作为输出。不会自动把字段合并到输入或 $context。

FieldSchema typePresence
ifstringoptional
inputinputoptional
outputoutputoptional
exportexportoptional
timeoutunionoptional
thenflowDirectiveoptional
metadataobjectoptional
setunionrequired
do:
- value:
set: { greeting: hello }
export: { as: '${ $context + { name: . } }' }

for

for

顺序遍历数组或对象的值。each 默认 item,at 默认 index(从 0 开始);用 $item、$index 访问。while 在每轮前求值,只有 true 继续。输出是最后一轮的最终输出,空集合保留输入,不自动收集为数组。

FieldSchema typePresence
ifstringoptional
inputinputoptional
outputoutputoptional
exportexportoptional
timeoutunionoptional
thenflowDirectiveoptional
metadataobjectoptional
forobjectrequired
for.eachstringoptional
for.instringrequired
for.atstringoptional
whilestringoptional
dotaskListrequired
do:
- items:
for: { each: item, at: index, in: '${ [1, 2] }' }
do:
- value:
set: { value: '${ $item }', index: '${ $index }' }

fork

fork

并行执行 branches。compete 默认 false,输出按分支顺序组成数组;true 取首先成功的分支输出。分支内不能 listen 或发起审批。最多 10 个分支,嵌套扇出最多 25。

FieldSchema typePresence
ifstringoptional
inputinputoptional
outputoutputoptional
exportexportoptional
timeoutunionoptional
thenflowDirectiveoptional
metadataobjectoptional
forkobjectrequired
fork.branchestaskListrequired
fork.competebooleanoptional
do:
- parallel:
fork:
branches:
- first: { set: { value: 1 } }
- second: { set: { value: 2 } }

try

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 时错误继续传播。

FieldSchema typePresence
ifstringoptional
inputinputoptional
outputoutputoptional
exportexportoptional
timeoutunionoptional
thenflowDirectiveoptional
metadataobjectoptional
trytaskListrequired
catchobjectrequired
catch.errorsobjectoptional
catch.errors.witherrorFilteroptional
catch.asstringoptional
catch.whenstringoptional
catch.exceptWhenstringoptional
catch.retryunionoptional
catch.dotaskListoptional
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

switch

按顺序选择第一个 when 为 true 的分支,无 when 的分支作默认。then 为 continue、end、exit 或同一列表的步骤名。输出保持输入;分支不是任务列表。

FieldSchema typePresence
ifstringoptional
inputinputoptional
outputoutputoptional
exportexportoptional
timeoutunionoptional
thenflowDirectiveoptional
metadataobjectoptional
switcharrayrequired
do:
- choose:
switch:
- yes: { when: '${ .enabled == true }', then: end }
- otherwise: { then: continue }
- finish: { set: { done: true } }

raise

raise

抛出内联 error 或 use.errors 中的名字,要求 type 与 status;title、detail 保留。没有正常输出,可由 try/catch 捕获。

FieldSchema typePresence
ifstringoptional
inputinputoptional
outputoutputoptional
exportexportoptional
timeoutunionoptional
thenflowDirectiveoptional
metadataobjectoptional
raiseobjectrequired
raise.errorunionrequired
do:
- fail:
raise:
error: { type: "https://example.com/errors/rejected", status: 400, detail: "Review required" }

listen

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。

FieldSchema typePresence
ifstringoptional
inputinputoptional
outputoutputoptional
exportexportoptional
timeoutunionoptional
thenflowDirectiveoptional
metadataobjectoptional
listenobjectrequired
listen.toeventConsumptionStrategyrequired
listen.readdata / envelope / rawoptional
foreachsubscriptionIteratoroptional
do:
- received:
listen:
to:
one:
with: { type: "order.ready" }
read: data

do

do

顺序执行命名任务列表,输出为最后一步的输出。同一列表的名字必须唯一;每个任务恰有一个任务种类(for 同时带 do)。

FieldSchema typePresence
ifstringoptional
inputinputoptional
outputoutputoptional
exportexportoptional
timeoutunionoptional
thenflowDirectiveoptional
metadataobjectoptional
dotaskListrequired
do:
- group:
do:
- value: { set: { ready: true } }

praxis/approval

Call

call: praxis/approval 是内置异步函数,不是 Action。with 在创建人工任务前校验,工作流等待结算,以 outcome 作为步骤输出。不能放在 fork 分支中。完整输入与结果契约见审批指南。

emit

Emit

不能执行:schema 校验可接受 emit,但创建运行时返回 DEFINITION_INVALID,没有输出。

错误

Error · Retry

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(修复建议)。先读第一条,修复后重新校验。

FieldSchema typePresence
typeunionrequired
statusintegerrequired
instanceunionoptional
titleunionoptional
detailunionoptional
FieldSchema typePresence
whenstringoptional
exceptWhenstringoptional
delaydurationoptional
backoffobjectoptional
backoff.constantobjectrequired
backoff.exponentialobjectrequired
backoff.linearobjectrequired
limitobjectoptional
limit.attemptobjectoptional
limit.attempt.countintegeroptional
limit.attempt.durationdurationoptional
limit.durationdurationoptional
jitterobjectoptional
jitter.fromdurationrequired
jitter.todurationrequired

Serverless Workflow 1.0.3 支持矩阵

Workflow · Task

supported 表示可执行;planned 表示目前被拒绝;not supported by design 表示按设计拒绝。accepted-inert:目前会被接受,但没有运行时效果(计划支持)。具体而言,use.secrets / use.authentications 不解析密钥或认证;call: a2a / call: mcp 分别按 praxis 中名为 a2a / mcp 的 Action 解析,而这些 Action 不存在,不会调用协议运行时。表中也逐项列出其他目前会被接受的声明与形似协议的 Action 名称。

ConstructStatusMain fieldsRuntime boundary
documentsupporteddsl, namespace, name, version, title, summary, tags, metadataExecuted by the workflow input/task/output pipeline.
inputsupportedschema, fromExecuted by the workflow input/task/output pipeline.
outputsupportedschema, asExecuted by the workflow input/task/output pipeline.
dosupportedExecuted by the workflow input/task/output pipeline.
timeoutsupportedafterExecuted by the workflow input/task/output pipeline.
usesupportedauthentications, errors, extensions, functions, retries, secrets, timeouts, catalogsNamed errors, retries and timeouts are resolved by the interpreter.
schedulesupportedtimezone, every, cron, after, oncron/every with optional timezone; after/on are refused.
evaluateaccepted-inertExpression-engine selection is not wired; jq is used. Declaration is accepted without runtime resolution.
use.secretsaccepted-inertDeclaration is accepted but Vault/authentication resolution has no runtime effect.
use.authenticationsaccepted-inertDeclaration is accepted but Vault/authentication resolution has no runtime effect.
use.functionsaccepted-inertNo runtime resolver/handler; declaration syntax is accepted.
use.catalogsaccepted-inertNo runtime resolver/handler; declaration syntax is accepted.
use.extensionsaccepted-inertNo runtime resolver/handler; declaration syntax is accepted.
callsupportedif, input, output, export, timeout, then, metadata, call, withSee the task section for output and runtime restrictions.
runsupportedif, 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.inputSee the task section for output and runtime restrictions.
waitsupportedif, input, output, export, timeout, then, metadata, waitSee the task section for output and runtime restrictions.
setsupportedif, input, output, export, timeout, then, metadata, setSee the task section for output and runtime restrictions.
forsupportedif, input, output, export, timeout, then, metadata, for, for.each, for.in, for.at, while, doSee the task section for output and runtime restrictions.
forksupportedif, input, output, export, timeout, then, metadata, fork, fork.branches, fork.competeSee the task section for output and runtime restrictions.
trysupportedif, input, output, export, timeout, then, metadata, try, catch, catch.errors, catch.errors.with, catch.as, catch.when, catch.exceptWhen, catch.retry, catch.doSee the task section for output and runtime restrictions.
switchsupportedif, input, output, export, timeout, then, metadata, switchSee the task section for output and runtime restrictions.
raisesupportedif, input, output, export, timeout, then, metadata, raise, raise.errorSee the task section for output and runtime restrictions.
listensupportedif, input, output, export, timeout, then, metadata, listen, listen.to, listen.read, foreachSee the task section for output and runtime restrictions.
dosupportedif, input, output, export, timeout, then, metadata, doSee the task section for output and runtime restrictions.
emitplannedif, input, output, export, timeout, then, metadata, emit, emit.event, emit.event.withEvent publishing runtime is not wired; run creation refuses emit.
call: httpaccepted-inertResolved as the Action ID http in praxis, not an upstream protocol transport. This does not activate the upstream protocol-call configuration.
call: openapiaccepted-inertResolved as the Action ID openapi in praxis, not an upstream protocol transport. This does not activate the upstream protocol-call configuration.
call: grpcaccepted-inertResolved as the Action ID grpc in praxis, not an upstream protocol transport. This does not activate the upstream protocol-call configuration.
call: asyncapiaccepted-inertResolved as the Action ID asyncapi in praxis, not an upstream protocol transport. This does not activate the upstream protocol-call configuration.
call: a2aaccepted-inertResolved as the Action ID a2a in praxis, not an upstream protocol transport. No built-in Action with that name exists.
call: mcpaccepted-inertResolved as the Action ID mcp in praxis, not an upstream protocol transport. No built-in Action with that name exists.
run.shellnot supported by designOnly saved scripts and workflows execute.
run.containernot supported by designOnly saved scripts and workflows execute.
run.script.codenot supported by designScripts are saved and versioned before reference.
listen.to.allplannedNot executable in the event-wait subset; run creation refuses this form.
listen.read.rawplannedNot executable in the event-wait subset; run creation refuses this form.
listen.foreachplannedNot executable in the event-wait subset; run creation refuses this form.
listen in forkplannedNot executable in the event-wait subset; run creation refuses this form.
approval in forkplannedNot executable in the event-wait subset; run creation refuses this form.
listen dynamic typeplannedNot executable in the event-wait subset; run creation refuses this form.
listen.untilplannedNot executable in the event-wait subset; run creation refuses this form.
schedule.afterplannedSchedule trigger supports cron/every only.
schedule.onplannedSchedule trigger supports cron/every only.

编写工作流