For AI agents: the complete documentation index is available at https://a3s-lab.github.io/Flow/v1.0.0/en/llms.txt, the full documentation bundle is available at https://a3s-lab.github.io/Flow/v1.0.0/en/llms-full.txt, and this page is available as Markdown at https://a3s-lab.github.io/Flow/v1.0.0/en/reference/examples.md.

Example index

The examples/ directory contains 31 runnable programs. Start with sequential_steps, then choose the group matching your production concern. Examples use temporary resources or explicit environment variables and never connect to a production service automatically.

Prepare

git clone https://github.com/A3S-Lab/Flow.git
cd Flow
cargo run --example sequential_steps

Flow 1.0 requires Rust 1.88. SQL examples compile their selected driver on first use and take longer than memory examples.

Steps and business orchestration

ExampleWhat it demonstratesCommand
sequential_stepsTwo dependent durable steps under replaycargo run --example sequential_steps
batch_stepsOne declaration of independent step memberscargo run --example batch_steps
retry_backoffFixed and exponential backoff with deterministic jittercargo run --example retry_backoff
recoverable_step_failureReturn retry exhaustion to workflow codecargo run --example recoverable_step_failure
compensationExplicit compensation after an earlier successful stepcargo run --example compensation
polling_loopCompose a step and timer into pollingcargo run --example polling_loop

A useful order is sequential_steps, retry_backoff, recoverable_step_failure, then compensation. It exposes success, redelivery, exhaustion, and compensation boundaries one at a time.

Waits, signals, and callbacks

ExampleWhat it demonstratesCommand
scheduler_workerScan due waits and dispatch run taskscargo run --example scheduler_worker
workflow_signalsSignal declaration, early delivery, and stable delivery IDcargo run --example workflow_signals
hook_approvalResume a human-approval hook by public tokencargo run --example hook_approval
hook_disposalWithdraw an active hook and reject a late callbackcargo run --example hook_disposal
cancellationCancellation request, durable cleanup, and invalidated timerscargo run --example cancellation

For an HTTP callback, run hook_approval to see token resolution, then read reliable redelivery in Signals and hooks. The example demonstrates Flow calls only and does not provide HTTP serving or authentication.

Long runs, rollout, and parent-child execution

ExampleWhat it demonstratesCommand
continue_as_newBound one event stream through successor runscargo run --example continue_as_new
replay_safe_patchSelect a patch for new runs while preserving old pathscargo run --example replay_safe_patch
child_workflowOne first-class child and terminal resultcargo run --example child_workflow
child_workflow_batchBounded concurrent children with request-order resultscargo run --example child_workflow_batch
run_inspectionState summary, suspension listing, and run inspectioncargo run --example run_inspection

Rollout examples use memory storage to isolate their contract. Production also needs exact runtime-build routes from Workers and rollout.

Local persistence

ExampleWhat it demonstratesCommand
local_file_durabilityRecover JSONL history after engine recreationcargo run --example local_file_durability
sqlite_durabilityRead a run after reconnecting SQLitecargo run --example sqlite_durability --features sqlite
local_retentionDelete expired local terminal historycargo run --example local_retention
sqlite_retentionSQL audit holds, linked deletion, and tombstonescargo run --example sqlite_retention --features sqlite

These examples work in temporary directories or files and clean their resources. Read owner and backup requirements in Stores and migrations before using a real path.

PostgreSQL

PostgreSQL examples connect only after A3S_FLOW_POSTGRES_URL is set.

export A3S_FLOW_POSTGRES_URL=postgres://user:pass@127.0.0.1:5432/flow_test
cargo run --example postgres_durability --features postgres
ExampleWhat it demonstratesCommand
postgres_durabilityRecover shared SQL history across instancescargo run --example postgres_durability --features postgres
postgres_task_queue_durabilityPostgreSQL task leases with workflow historycargo run --example postgres_task_queue_durability --features postgres

Use a dedicated test database. Examples may create or migrate Flow tables and must never target production.

Tasks and workers

ExampleWhat it demonstratesCommand
task_queue_durabilityRecover a local durable task queue after restartcargo run --example task_queue_durability
sqlite_workerCombine SQLite history and worker drivingcargo run --example sqlite_worker --features sqlite
boot_task_policyBoot task retry, timeout, stall, and deduplication policycargo run --example boot_task_policy --features boot

Task retry and step retry belong to different layers. Read lease recovery in task_queue_durability before host policy in boot_task_policy.

Observation and audit

ExampleWhat it demonstratesCommand
observer_fanoutFan one committed event into several observerscargo run --example observer_fanout
observer_bridgeMap event envelopes into low-cardinality recordscargo run --example observer_bridge
local_audit_logRepair-aware local JSONL audit outputcargo run --example local_audit_log

Observers run after event commit. The examples deliberately keep observation output out of workflow decisions.

Native TypeScript

Install the compiler and make Bun available first.

cargo install a3s-flow --version 1.0.0 --locked \
  --bin a3s-flow-native-compiler
export A3S_FLOW_NATIVE_TS_COMPILER="$(command -v a3s-flow-native-compiler)"
ExampleWhat it demonstratesCommand
native_ts_preflightResolve entrypoint, build artifact, and inspect cache hitcargo run --example native_ts_preflight
native_ts_greetingRun a complete TypeScript workflow and stepcargo run --example native_ts_greeting

Without the compiler environment variable, both examples print instructions and skip safely. See Native TypeScript for production configuration.

Workflow graph import

workflow_dsl_import accepts a YAML path and prints application data, version classification, node count, scopes, and execution digest.

cargo run --example workflow_dsl_import -- \
  tests/fixtures/workflow_dsl_echo.yml

Graph import validates structure and derives a plan without executing nodes. See host binding in Workflow graph.

Suggested production qualification path

When integrating a real service, replace one layer at a time.

  1. Confirm runtime and step boundaries with sequential_steps.
  2. Confirm restart recovery with the target SQL example.
  3. Verify duplicate timer delivery with scheduler_worker.
  4. Choose the signal or hook example matching ingress.
  5. Verify cleanup idempotency with cancellation.
  6. Replace in-process dispatch with task management.
  7. Inject process loss with the same store and queue as production.

Retain event history and external idempotency records at each stage. When behavior diverges, that evidence identifies which boundary owns the fault.