Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Examples

Each example is a standalone binary in the examples/ directory. Run them with cargo run -p <example-name>.

Running Examples

# List all examples
ls examples/

# Run a specific example
cargo run -p step-retry

# Run with output visible
cargo run -p step-retry -- --nocapture

Example Index

ExampleDescription
step-retryTask-check-repair loop with a planning task that validates and retries
materialiserMaterialising task output into a different type before validation
join-reconcileParallel fan-out with .join() and fan-in with .reconcile_task()
composed-workflowSequential retry + parallel composition
dynamic-workflowRuntime graph construction with Workflow, StepNode, and GraphPatch
process-taskShell-command integration via naaf-process
build-testGenerate → materialise → validate → repair loop at the heart of naaf
knowledge-toolKnowledge base integration
tui-demoTerminal UI demonstration

Example Descriptions

step-retry

The core example: a task that generates output, validates it with a check, and retries with a repair planner on failure.

materialiser

Shows how to transform output between task and check. A task produces raw text, a materialiser writes it to a file, and the check validates the file.

join-reconcile

Parallel execution: use .join() to run two steps with the same input concurrently, then .reconcile_task() to merge their results.

composed-workflow

Combines sequential and parallel composition: step A → (step B + step C) → step D.

dynamic-workflow

Runtime-determined topology: nodes can spawn new nodes based on their output using spawn_with() and GraphPatch.

process-task

Shell command integration: wraps cargo check, cargo test, and other CLI tools as tasks and checks.

build-test

The quintessential workflow: generate code → write to file → compile → test → fix if needed.

knowledge-tool

Qdrant integration: ingest documentation and query it with semantic search.

tui-demo

Interactive terminal UI for observing workflow execution and providing human feedback.

Adding New Examples

  1. Create a new directory in examples/
  2. Add a Cargo.toml with the crate name
  3. Implement your example
  4. Add it to Cargo.toml workspace members
# examples/my-example/Cargo.toml
[package]
name = "my-example"
version = "0.1.0"
edition = "2024"

[dependencies]
naaf-core = { path = "../crates/core" }
tokio = { version = "1", features = ["full"] }