07 โ Step-wise Execution
Engine.run_steps runs a pipeline one step at a time, yielding a StepResult
per executed node. It supports resume (skip already-done steps) and
progress hooks (report started / completed / skipped).
๐ฏ Goal
Run a three-node pipeline, observe progress, and resume a partial run.
๐งฑ Setup
๐ Step by step
Output:
Each StepResult exposes:
| Field | Meaning |
|---|---|
index |
0-based step ordinal (resume_from is relative to this) |
node_id |
The node that ran in this step |
states |
States produced by this step |
completed |
True if any state was produced |
๐ Resume after interruption
If you already processed #0 and #1, skip ahead:
๐ Progress hooks
Pass on_step (or set it at engine construction) to be notified per step:
Output:
A ProgressMessage can be passed as the third argument for richer progress
(lines, blocks, count, unit, error, ...). Use as_dict() to surface
it in your logging.
The async variant run_steps_async mirrors this API with on_step:
AsyncStepHook โ see use case 06.
๐ Step ordering in graph mode
In graph mode, run_steps derives a deterministic topological order (DFS
post-order, roots first), one StepResult per node. A node that yields no
states marks that step completed=False and the branch stops there.
๐ก Tips
- Use
resume_fromfor idempotent retries: record the last consumedindex(e.g. in a DB), then resume the next run fromindex + 1. completed=Falsemeans "no states produced" (pruned/static node) โ treat it as "no work available", not "error".- Hooks are a good place to emit telemetry (counters, traces) without coupling the engine to your logging stack.