# Loops & Workflows | EasyNet Docs Source: https://easynet.run/docs/aal/workflows # 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 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](data:text/plain;charset=utf-8,agent%20Tutorial%20is%20Agent%0A%20%20public%0A%20%20%20%20ability%20run(scores%3A%20List%3CInt%3E)%20-%3E%20Int%20effects(workflow)%0A%20%20%20%20%20%20workflow%20%22total-scores%22%20persist%20%22scores.json%22%0A%20%20%20%20%20%20%20%20state%20sum%0A%20%20%20%20%20%20%20%20%20%20total%20%3D%200%0A%20%20%20%20%20%20%20%20%20%20for%20score%20in%20scores%0A%20%20%20%20%20%20%20%20%20%20%20%20total%20%3D%20total%20%2B%20score%0A%20%20%20%20%20%20%20%20%20%20-%3E%20done%0A%20%20%20%20%20%20%20%20state%20done%0A%20%20%20%20%20%20%20%20%20%20return%20total%0A) ## Syntax explained 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. wait until condition is valid only inside a state. A false condition suspends the invocation; resumption replays from that state’s entry. 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](https://github.com/Brain-Cell-Coding/Agent-Assembly-Language/blob/main/examples/workflow.aal)