Skip to content
中文

Approvals

A workflow step written call: praxis/approval opens an approval task (a HumanTask) for the people you name and then waits. Once an assignee decides in the Console or through the API, the workflow continues from that step and the decision is the step’s output. Waiting uses no compute and costs nothing; a workflow run can wait up to 30 days.

praxis/approval is a built-in function, not an Action: a script cannot call("approval"). Write it only in workflow YAML, and not inside a fork branch.

Open an approval

document: { dsl: "1.0.3", namespace: shop, name: refund, version: "1.0.0" }
do:
- approveRefund:
call: praxis/approval
with:
title: "${ \"Refund $\" + (.amount | tostring) + \" for order \" + .order_id }"
body: |
The customer requested a refund. Check the order amount.
context: "${ { order_id: .order_id, amount: .amount } }"
assignees:
users: [usr_finance_lead, usr_ops_manager]
mode: any
due: P2D
on_timeout: { action: reject }
form:
type: object
properties:
refund_amount: { type: number, minimum: 0 }
required: [refund_amount]
- decide:
switch:
- approved:
when: "${ .decision == \"approve\" }"
then: refund
- otherwise:
then: end
- refund:
call: shop/refund
with:
order_id: "${ $workflow.input.order_id }"
amount: "${ .values.refund_amount }"

For a long wait, create the run with deadline_seconds longer than due (workflows allow up to 2592000 seconds, 30 days). due cannot exceed the run’s remaining time; when omitted it defaults to 3 days, cut to the run’s remaining time.

with arguments

ArgumentMeaning
titleRequired, at most 200 characters.
bodyMarkdown details, up to 16 KiB.
contextAttached JSON (for example the order), up to 32 KiB.
actions1–6 buttons {id, label, style?, require_comment?}; style is primary, danger or default. Defaults to approve (primary) and reject (danger).
formThe form assignees fill in: type: object with at most 30 string, number, integer, boolean or enum fields, plus optional required.
assigneesRequired, {users: [user ids…]}, 1–20 people. groups is not supported yet.
modeany (default), all, quorum, sequential; see below.
quorumApprovals needed in mode: quorum.
allow_self_approvalDefault false: the person who started the run cannot approve their own request.
allow_agent_decisionDefault false: agents cannot respond on someone’s behalf.
dueISO 8601 duration, default P3D, at most P30D.
on_timeout{action: reject | approve | fault}, default fault. escalate is not supported yet.
remindUp to 3 durations; stored, reminders are not sent yet.
proposalAn agent’s proposal (JSON) for the assignees to consider.
channelsconsole, email; stored, notification delivery is not wired yet.

Arguments written as ${…} expressions are checked when the step runs; the rest are checked when you save and publish the workflow.

Step output

{
"decision": "approve",
"values": { "refund_amount": 120 },
"comment": "Amount matches the order",
"decided_by": { "id": "usr_finance_lead", "kind": "human", "display_name": null },
"responses": [ … ]
}

decision is the deciding action id. values and comment come from the deciding response; responses lists every response submitted.

Decision rules

modeRule
anyThe first response decides.
allEveryone must respond; any rejection rejects at once.
quorumquorum approvals approve; it rejects as soon as that many approvals are no longer possible.
sequentialAssignees respond in users order; any rejection rejects at once and the last approval approves.

all, quorum and sequential need exactly two buttons: one style: danger rejection and one approval. When two assignees respond at the same moment, exactly one decides and the other receives TASK_CLOSED.

Timeouts

If nobody decides by due, on_timeout applies and the task becomes expired:

  • reject / approve: the step output has decision timeout:reject or timeout:approve and decided_by null.
  • fault (default): the step raises a timeout error, which try can catch:
- guard:
try:
- approve:
call: praxis/approval
with: { title: Release to production, assignees: { users: [usr_release_owner] }, due: PT4H }
catch:
errors:
with: { type: https://serverlessworkflow.io/spec/1.0.0/errors/timeout }
do:
- giveUp:
set: { released: false }

When an approval is cancelled, the step raises a runtime error with code HUMAN_TASK_CANCELLED. When a run ends (completed, faulted or cancelled), its open approvals are cancelled automatically.

Respond

An assignee’s inbox is List human tasks: by default the open tasks assigned to the caller.

终端窗口
curl --fail-with-body -sS "$PRAXIS_API_URL/automation/v1/human-tasks" \
-H "Authorization: Bearer $PRAXIS_API_KEY"

Respond with the task id:

终端窗口
curl --fail-with-body -sS "$PRAXIS_API_URL/automation/v1/human-tasks/$TASK/respond" \
-H "Authorization: Bearer $PRAXIS_API_KEY" \
-H 'Content-Type: application/json' \
-H "Idempotency-Key: $(uuidgen)" \
--data '{"action_id":"approve","values":{"refund_amount":120},"comment":"Amount matches the order"}'

It returns the updated task; once decided, status is completed and outcome is what the workflow receives. An assignee can also delegate to another user, and the initiator can cancel. An approval wait ends only this way: completing it through the run’s wait completion endpoint is refused.

ErrorWhen
NOT_ASSIGNEDYou are not an assignee, or it is not your turn in sequential mode.
SELF_APPROVALThe initiator responds to their own request without allow_self_approval.
AGENT_NOT_ALLOWEDAn agent session or run token responds without allow_agent_decision.
ALREADY_RESPONDEDYou already responded.
COMMENT_REQUIREDThe chosen action requires a comment.
INVALID_ACTION / INVALID_VALUESNo such action / values do not match form.
TASK_CLOSEDThe approval was already decided, expired or cancelled.

Next steps