Skip to content

Loops & Workflows

Describe recoverable execution with explicit states.

for iterates a collection. workflow divides a longer task into recoverable states. This example totals scores, then transitions to done to return the result.

Complete example

Save the example as workflows.aal

workflows.aal
agent Tutorial is Agent
  public
    ability run(scores: List<Int>) -> Int effects(workflow)
      workflow "total-scores" persist "scores.json"
        state sum
          total = 0
          for score in scores
            total = total + score
          -> done
        state done
          return total
Download .aal

Syntax explained

  1. The first state is the entry; -> done transitions to another state. Every reachable path must return or transition, and every declared state must be reachable.

  2. wait until condition is valid only inside a state. A false condition suspends the invocation; resumption replays from that state’s entry.

  3. Transitions commit execution state and pending memory. The kernel cannot roll back external effects; this is not a distributed exactly-once guarantee.

Build and run

Terminal
cargo run --locked --bin aalc -- check workflows.aal

cargo run --locked --bin aalc -- build workflows.aal -o workflows.aalc

cargo run --locked --bin aalc -- run workflows.aalc \
  --agent Tutorial --ability run \
  --args '{"scores":[4,6,8]}' \
  --state-dir .aal-tutorial/workflows --invocation workflows-1

Run with a fresh state directory. The returned value is shown below; the CLI also prints execution information.

Expected result
18

Try it yourself

Run scores [10,20] with a new invocation ID to get 30. Try an empty list to get 0.

Language source and specification