Skip to content

工作流程 DSL 參考 ​

Triggerfish 工作流程引擎中 CNCF Serverless Workflow DSL 1.0 的完整參考。有關 使用指南和範例,請參見工作流程。

文件結構 ​

每個工作流程 YAML 必須有一個頂層 document 欄位和一個 do 區塊。

yaml
document:
  dsl: "1.0"
  namespace: my-namespace
  name: my-workflow
  version: "1.0.0"            # optional
  description: "What it does"  # optional
classification_ceiling: INTERNAL  # optional
input:                            # optional
  from: "${ . }"
output:                           # optional
  from:
    result: "${ .final_step }"
timeout:                          # optional
  after: PT5M
do:
  - task_name:
      # task definition

文件中繼資料 ​

FieldTypeRequiredDescription
dslstringyesDSL 版本。必須為 "1.0"
namespacestringyes邏輯分組(例如 ops、reports)
namestringyes命名空間內的唯一工作流程名稱
versionstringno語意版本字串
descriptionstringno人類可讀的描述

頂層欄位 ​

FieldTypeRequiredDescription
documentobjectyes文件中繼資料(見上文)
doarrayyes任務條目的有序清單
classification_ceilingstringno執行期間允許的最大工作階段 taint
inputtransformno應用於工作流程輸入的轉換
outputtransformno應用於工作流程輸出的轉換
timeoutobjectno工作流程級逾時(after: <ISO 8601>)
metadataobjectno任意鍵值中繼資料

任務條目格式 ​

do 區塊中的每個條目是一個單鍵物件。鍵是任務名稱,值是任務定義。

yaml
do:
  - my_task_name:
      call: http
      with:
        endpoint: "https://example.com"

任務名稱在同一個 do 區塊中必須唯一。任務結果以任務名稱儲存在資料上下文中。


通用任務欄位 ​

所有任務類型共享以下可選欄位:

FieldTypeDescription
ifstring運算式條件。條件為假時跳過任務。
inputtransform任務執行前應用的轉換
outputtransform任務執行後應用的轉換
timeoutobject任務逾時:after: <ISO 8601 duration>
thenstring流程指令:continue、end 或任務名稱
metadataobject任意鍵值中繼資料。啟用自修復時,需要 description、expects、produces。

自修復設定 ​

metadata.triggerfish.self_healing 區塊為工作流程啟用自主修復代理。完整指南請 參見自修復。

yaml
metadata:
  triggerfish:
    self_healing:
      enabled: true
      retry_budget: 3
      approval_required: true
      pause_on_intervention: blocking_only
      pause_timeout_seconds: 300
      pause_timeout_policy: escalate_and_halt
      notify_on: [intervention, escalation, approval_required]
FieldTypeRequiredDefaultDescription
enabledbooleanyes—啟用修復代理
retry_budgetnumberno3最大介入嘗試次數
approval_requiredbooleannotrue修復是否需要人工審批
pause_on_interventionstringno"blocking_only"always | never | blocking_only
pause_timeout_secondsnumberno300逾時策略觸發前的等待秒數
pause_timeout_policystringno"escalate_and_halt"escalate_and_halt | escalate_and_skip | escalate_and_fail
notify_onarrayno[]intervention | escalation | approval_required

步驟中繼資料(自修復啟用時必需) ​

當 self_healing.enabled 為 true 時,每個任務必須包含以下中繼資料欄位。 解析器會拒絕缺少任何欄位的工作流程。

FieldTypeDescription
descriptionstring該步驟的功能及其原因
expectsstring需要的輸入形式或前置條件
producesstring產生的輸出形式
yaml
- fetch-invoices:
    call: http
    with:
      endpoint: "https://api.example.com/invoices"
    metadata:
      description: "Fetch open invoices from billing API"
      expects: "API available, returns JSON array"
      produces: "Array of {id, amount, status} objects"

任務類型 ​

call ​

分發到 HTTP 端點或 Triggerfish 服務。

FieldTypeRequiredDescription
callstringyes呼叫類型(見下方分發表)
withobjectno傳遞給目標工具的參數
yaml
- fetch:
    call: http
    with:
      endpoint: "https://api.example.com/data"
      method: GET

run ​

執行 shell 命令、內聯指令碼或子工作流程。run 欄位必須恰好包含以下之一: shell、script 或 workflow。

Shell:

FieldTypeRequiredDescription
run.shell.commandstringyes要執行的 shell 命令
run.shell.argumentsobjectno命名參數
run.shell.environmentobjectno環境變數

Script:

FieldTypeRequiredDescription
run.script.languagestringyes指令碼語言
run.script.codestringyes內聯指令碼程式碼
run.script.argumentsobjectno命名參數

子工作流程:

FieldTypeRequiredDescription
run.workflow.namestringyes已儲存工作流程的名稱
run.workflow.versionstringno版本約束
run.workflow.inputobjectno子工作流程的輸入資料

set ​

為資料上下文賦值。

FieldTypeRequiredDescription
setobjectyes要賦值的鍵值對。值可以是運算式。
yaml
- prepare:
    set:
      full_name: "${ .first_name } ${ .last_name }"
      count: 0

switch ​

條件分支。switch 欄位是分支條目的陣列。每個分支是一個單鍵物件,鍵為分支名稱。

Case fieldTypeRequiredDescription
whenstringno運算式條件。省略則為預設分支。
thenstringyes流程指令:continue、end 或任務名稱

分支按順序評估。第一個 when 為真(或沒有 when)的分支被執行。

yaml
- route:
    switch:
      - high:
          when: "${ .priority > 7 }"
          then: alert_team
      - low:
          then: log_only

for ​

遍歷集合。

FieldTypeRequiredDescription
for.eachstringyes當前元素的變數名稱
for.instringyes參考集合的運算式
for.atstringno當前索引的變數名稱
doarrayyes每次迭代執行的巢狀任務清單
yaml
- process_all:
    for:
      each: item
      in: "${ .items }"
      at: idx
    do:
      - handle:
          call: triggerfish:llm
          with:
            task: "Process item ${ .idx }: ${ .item.name }"

raise ​

以結構化錯誤停止工作流程。

FieldTypeRequiredDescription
raise.error.statusnumberyesHTTP 風格狀態碼
raise.error.typestringyes錯誤類型 URI/字串
raise.error.titlestringyes人類可讀標題
raise.error.detailstringno詳細錯誤訊息
yaml
- abort:
    raise:
      error:
        status: 422
        type: "validation-error"
        title: "Invalid input"
        detail: "Field 'email' is required"

emit ​

記錄工作流程事件。事件儲存在執行結果中。

FieldTypeRequiredDescription
emit.event.typestringyes事件類型識別碼
emit.event.sourcestringno事件來源 URI
emit.event.dataobjectno事件承載資料
yaml
- record:
    emit:
      event:
        type: "step.completed"
        source: "workflow/pipeline"
        data:
          step: "transform"
          duration_ms: 1200

wait ​

暫停執行指定時長。

FieldTypeRequiredDescription
waitstringyesISO 8601 時長(例如 PT5S)

常用時長:PT1S(1 秒)、PT30S(30 秒)、PT1M(1 分鐘)、PT5M(5 分鐘)。


呼叫分發表 ​

將 call 欄位值對應到實際呼叫的 Triggerfish 工具。

call 值呼叫的工具必需的 with: 欄位
httpweb_fetchendpoint 或 url;可選 method、headers、body
triggerfish:llmllm_taskprompt 或 task;可選 tools、max_iterations
triggerfish:agentsubagentprompt 或 task;可選 tools、agent
triggerfish:memorymemory_*operation(save/search/get/list/delete)+ 操作欄位
triggerfish:web_searchweb_searchquery;可選 max_results
triggerfish:web_fetchweb_fetchurl;可選 method、headers、body
triggerfish:mcpmcp__<server>__<tool>server、tool;可選 arguments
triggerfish:messagesend_messagechannel、text;可選 recipient

不支援的 CNCF 呼叫類型(grpc、openapi、asyncapi)傳回錯誤。


運算式語法 ​

運算式由 ${ } 分隔,針對工作流程資料上下文進行解析。

點路徑解析 ​

語法描述範例結果
${ . }整個資料上下文{...}
${ .key }頂層鍵"value"
${ .a.b.c }巢狀鍵"deep value"
${ .items[0] }陣列索引{...第一個元素...}
${ .items[0].name }陣列索引後取鍵"first"

前導點(或 $.)將路徑錨定在上下文根。解析為 undefined 的路徑在內插時產生 空字串,作為獨立值使用時為 undefined。

運算子 ​

類型運算子範例
比較==、!=、>、<、>=、<=${ .count > 0 }
算術+、-、*、/、%${ .price * .quantity }

比較運算式傳回 true 或 false。算術運算式傳回數字(如果任一運算元非數字或 除以零則為 undefined)。

字面量 ​

類型範例
String"hello"、'hello'
Number42、3.14、-1
Booleantrue、false
Nullnull

內插模式 ​

單一運算式(原始值): 當整個字串是一個 ${ } 運算式時,傳回原始類型值 (數字、布林值、物件、陣列)。

yaml
count: "${ .items.length }"  # returns a number, not a string

混合/多運算式(字串): 當 ${ } 運算式與文字混合或有多個運算式時,結果 始終為字串。

yaml
message: "Found ${ .count } items in ${ .category }"  # returns a string

真值性 ​

對於 if: 條件和 switch 的 when: 運算式,值按 JavaScript 風格的真值性評估:

值為真?
true是
非零數字是
非空字串是
非空陣列是
物件是
false、0、""、null、undefined、空陣列否

輸入/輸出轉換 ​

轉換重塑流入和流出任務的資料。

input ​

在任務執行前應用。替換任務的資料上下文檢視。

yaml
- step:
    call: http
    input:
      from: "${ .config }"       # task sees only the config object
    with:
      endpoint: "${ .api_url }"  # resolved against the config object

from 為字串: 替換整個輸入上下文的運算式。

from 為物件: 將新鍵對應到運算式:

yaml
input:
  from:
    url: "${ .config.api_url }"
    token: "${ .secrets.api_token }"

output ​

在任務執行後應用。在以任務名稱儲存到上下文前重塑結果。

yaml
- fetch:
    call: http
    output:
      from:
        items: "${ .fetch.data.results }"
        count: "${ .fetch.data.total }"

流程指令 ​

任務上的 then 欄位控制任務完成後的執行流程。

值行為
continue繼續序列中的下一個任務(預設)
end停止工作流程。狀態:completed。
<任務名稱>跳轉到指定任務。該任務必須存在於同一 do 區塊中。

switch 分支也在其 then 欄位中使用流程指令。


分類上限 ​

限制執行期間最大工作階段 taint 的可選欄位。

yaml
classification_ceiling: INTERNAL
值含義
PUBLIC存取任何分類資料時工作流程停止
INTERNAL允許 PUBLIC 和 INTERNAL 資料
CONFIDENTIAL允許最高 CONFIDENTIAL 資料
RESTRICTED允許所有分類級別
(省略)不強制上限

上限在每個任務前檢查。如果工作階段 taint 已升級超過上限(例如,因為先前的任務 存取了分類資料),工作流程以狀態 failed 和錯誤 Workflow classification ceiling breached 停止。


儲存 ​

工作流程定義 ​

以鍵前綴 workflows:{name} 儲存。每筆儲存記錄包含:

FieldTypeDescription
namestring工作流程名稱
yamlstring原始 YAML 定義
classificationstring儲存時的分類級別
savedAtstringISO 8601 時間戳記
descriptionstring可選描述

執行歷史 ​

以鍵前綴 workflow-runs:{runId} 儲存。每筆執行記錄包含:

FieldTypeDescription
runIdstring此次執行的 UUID
workflowNamestring執行的工作流程名稱
statusstringcompleted、failed 或 cancelled
outputobject最終資料上下文(內部鍵已篩選)
eventsarray執行期間發出的事件
errorstring錯誤訊息(如果狀態為 failed)
startedAtstringISO 8601 時間戳記
completedAtstringISO 8601 時間戳記
taskCountnumber工作流程中的任務數量
classificationstring完成時的工作階段 taint

限制 ​

限制值描述
子工作流程最大深度5run.workflow 呼叫的最大巢狀層數
執行歷史預設限制10workflow_history 的預設 limit

執行狀態 ​

狀態描述
pending工作流程已建立但尚未啟動
running工作流程正在執行中
completed所有任務成功完成(或 then: end)
failed任務失敗、觸發了 raise 或上限被突破
cancelled執行被外部取消