Engine
dagpipe.engine
Summary
Execution engine responsible for running pipelines and graphs.
The Engine executes Node objects and propagates immutable State instances
through either a linear sequence or a directed acyclic graph (Graph).
It orchestrates execution order, branching, and state propagation.
Guarantees
- Deterministic execution and consistent state lineage.
- Orchestrates execution without modifying
Graph,Node, orStateobjects.
Classes
Engine
Execution engine responsible for running pipeline logic.
Notes
Responsibilities:
1 2 3 4 5 6 7 | |
Guarantees:
1 2 3 4 5 | |
Create an engine from a node sequence or a graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes_or_graph |
Sequence[Node] | Graph
|
Either an ordered sequence of |
required |
on_step |
StepHook | None
|
Default per-step callback |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If a sequence element is not a |
Attributes
nodes
property
Return nodes managed by this engine.
Returns:
| Type | Description |
|---|---|
tuple[Node, ...]
|
tuple[Node, ...]: Ordered sequence in linear mode or all nodes in graph mode. |
Functions
__repr__
Return the canonical string representation of the object.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Representation that uniquely identifies the object and its configuration. |
run
Execute the pipeline starting from a root State.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root |
State
|
Initial execution state. |
required |
Returns:
| Type | Description |
|---|---|
list[State]
|
list[State]: Terminal execution states produced by the pipeline. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
RuntimeError
|
If the engine execution mode is invalid. |
Notes
Responsibilities:
1 2 | |
run_async
async
Execute the pipeline starting from root, dispatching sync vs async nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root |
State
|
Initial execution state. |
required |
Returns:
| Type | Description |
|---|---|
list[State]
|
list[State]: Terminal execution states produced by the pipeline. |
Notes
Each node is executed with Node.run when synchronous and
AsyncNode.run_async when asynchronous. Linear and graph topologies
are both supported.
run_steps
Execute the pipeline step-by-step, yielding one StepResult per step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root |
State
|
Initial execution state. |
required |
resume_from |
int | None
|
Skip steps at index < |
None
|
on_step |
StepHook | None
|
Callback |
None
|
Yields:
| Name | Type | Description |
|---|---|---|
StepResult |
StepResult
|
One per executed node/step, carrying the produced states. |
Notes
This is a synchronous, generator-based checkpoint interface compatible
with the imperative resume-by-step behaviour of the legacy
orchestrator. Use run_steps_async for async nodes.
run_steps_async
async
Async variant of run_steps supporting AsyncNode execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root |
State
|
Initial execution state. |
required |
resume_from |
int | None
|
Skip steps at index < |
None
|
on_step |
AsyncStepHook | None
|
Async callback |
None
|
Yields:
| Name | Type | Description |
|---|---|---|
StepResult |
AsyncIterator[StepResult]
|
One per executed node/step. |
ProgressMessage
Lightweight progress payload emitted by engine step hooks.
Mirrors the imperative ProgressMessage used by the legacy orchestrator so
callers can surface counts/lines/errors without coupling the engine to pydantic.
Attributes:
| Name | Type | Description |
|---|---|---|
lines |
int | None
|
Optional count of processed lines. |
blocks |
int | None
|
Optional count of processed blocks. |
count |
int | None
|
Optional generic item count. |
unit |
str | None
|
Optional unit for the count (e.g., 'pages'). |
raw_ocr_line |
str | None
|
Optional raw OCR line payload. |
error |
str | None
|
Optional error description. |
step |
str
|
Identifier of the step that emitted the message. |
status |
str
|
Status label associated with the step. |
Notes
Guarantees:
1 2 | |
Create a progress message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lines |
int | None
|
Optional count of processed lines. |
None
|
blocks |
int | None
|
Optional count of processed blocks. |
None
|
count |
int | None
|
Optional generic item count. |
None
|
unit |
str | None
|
Optional unit for the count (e.g., 'pages'). |
None
|
raw_ocr_line |
str | None
|
Optional raw OCR line payload. |
None
|
error |
str | None
|
Optional error description. |
None
|
step |
str
|
Identifier of the step that emitted the message. |
''
|
status |
str
|
Status label associated with the step. |
''
|
Functions
as_dict
Return the message as a plain dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: All attribute values keyed by their attribute name. |
StepResult
A single checkpointed step within an async/resumable engine run.
Attributes:
| Name | Type | Description |
|---|---|---|
index |
int
|
Ordinal index of the step. |
node_id |
str
|
Identifier of the node associated with this step. |
states |
tuple[State, ...]
|
States produced by running this step. |
completed |
bool
|
Whether this step succeeded (vs. paused/interrupted). |
Initialise StepResult.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index |
int
|
Ordinal index of the step. |
required |
node_id |
str
|
Identifier of the node associated with this step. |
required |
states |
tuple[State, ...]
|
States produced by running this step. |
required |
completed |
bool
|
Whether this step succeeded (vs. paused/interrupted). |
required |