1. Orchestration
  2. Approvals

ava.decision pauses a run until a person answers. You define the possible answers as a model, so the next step receives a typed decision, not free text.

from datetime import timedelta
from typing import Literal

import avalanche as ava


class Approval(ava.Event):
    kind: Literal["approve", "reject"]


@ava.workflow
def review_flow():
    doc = draft()
    review = ava.decision(
        Approval,
        prompt="Publish this document?",
        show=doc,
        timeout=timedelta(days=2),
        on_timeout=Approval(kind="reject"),
    )
    return publish(doc, review)
Rendering diagram…

​
The decision

ArgumentMeaning
The outcome model (Approval)The fields the reviewer fills in. A subclass of ava.Event.
promptThe question shown to the reviewer.
showWhat the reviewer sees: a step’s output, a model or plain text.
timeoutHow long to wait for an answer.
on_timeoutThe answer to use when nobody replies in time. Without it, the run fails at the timeout.
approversWho may decide. Anyone else is refused.

The next step receives the filled-in Approval.

​
One decision per item

reviews = ava.decision.map(Approval, drafts, prompt="Publish this draft?", timeout=timedelta(days=2))

One decision is opened per draft. The next step receives the list of answers.

​
Decide

In the UI, a run that waits for a decision shows Waiting for decision. Open it, fill in the form, give a reason and choose Submit decision.

From the command line:

ava run decide RUN_ID review '{"kind": "approve"}' --reason "Checked the figures" --idempotency-key d-1

A reason is always required and is kept with the run.

​
Test it

t = review_flow().test()
t.decide("review", Approval(kind="approve"), reason="ok")
assert t.handle.result() == "doc:approve"