Node
dagpipe.node
Summary
Defines the Node abstraction used by dagpipe.
A node represents a single unit of pipeline execution logic. It consumes one
State and produces zero, one, or many new State objects.
Nodes are connected using a Graph and executed by an Engine.
Design principles
- Pure: Must not mutate input state.
- Deterministic: Same input produces same output.
- Stateless: Recommended to be stateless for reuse.
- Composable: Nodes enable branching execution graphs.
Classes
AsyncNode
Bases: Node
Base class for nodes whose execution is asynchronous.
Subclasses implement resolve_async (an async generator yielding derived
State objects). The engine dispatches to resolve_async when running an
async traversal (see Engine.run_async).
Sync-only engines (and the base Node.run) treat an AsyncNode as a no-op
consumer: calling run on an AsyncNode returns no states, signalling that
an async engine is required.
Functions
clean_id_and_name
classmethod
Normalize and validate node ID and display name.
Raises:
| Type | Description |
|---|---|
TypeError
|
If ID is not a string. |
ValueError
|
If ID format is invalid. |
Notes
Guarantees:
1 2 3 | |
fork
Create a child State attributed to this node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state |
State
|
Parent execution state. |
required |
payload_update |
Mapping[str, Any]
|
Dot-path payload updates. |
None
|
confidence_delta |
float
|
Confidence adjustment. |
0.0
|
metadata_update |
Mapping[str, Any]
|
Metadata updates. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
State |
State
|
New child execution state. |
Notes
Responsibilities:
1 2 | |
node_id_to_name
staticmethod
Convert a dotted snake_case node ID into a human-readable name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id |
str
|
Unique node identifier (e.g., 'entity.resolve.numeric_merchant'). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Human-readable display name (e.g., 'Entity › Resolve › Numeric Merchant'). |
resolve_async
async
Execute node logic asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state |
State
|
Input execution state. |
required |
Returns:
| Type | Description |
|---|---|
Iterable[State]
|
Iterable[State]: Derived execution state(s). |
Notes
Subclasses implement this. Must not mutate the input state.
Should use fork() to create child states.
run
run_async
async
Execute this node asynchronously on a state, validating outputs.
Node
Bases: ABC
Base class for all dagpipe execution nodes.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier of the node (snake_case dotted format). |
name |
str
|
Human-readable display name. |
Notes
Responsibilities:
1 2 3 | |
Guarantees:
1 2 | |
Functions
__new__
Create or reuse a Node instance.
Stateless subclasses (no parameterized __init__) share one singleton
instance per class — matching the original dagpipe behaviour underpinning
set_registry-style configuration. Subclasses that declare an __init__
requiring instance-state arguments get a fresh instance per construction
so pipeline builders can inject per-run dependencies.
clean_id_and_name
classmethod
Normalize and validate node ID and display name.
Raises:
| Type | Description |
|---|---|
TypeError
|
If ID is not a string. |
ValueError
|
If ID format is invalid. |
Notes
Guarantees:
1 2 3 | |
fork
Create a child State attributed to this node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state |
State
|
Parent execution state. |
required |
payload_update |
Mapping[str, Any]
|
Dot-path payload updates. |
None
|
confidence_delta |
float
|
Confidence adjustment. |
0.0
|
metadata_update |
Mapping[str, Any]
|
Metadata updates. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
State |
State
|
New child execution state. |
Notes
Responsibilities:
1 2 | |
node_id_to_name
staticmethod
Convert a dotted snake_case node ID into a human-readable name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id |
str
|
Unique node identifier (e.g., 'entity.resolve.numeric_merchant'). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Human-readable display name (e.g., 'Entity › Resolve › Numeric Merchant'). |
resolve
abstractmethod
Execute node logic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state |
State
|
Input execution state. |
required |
Yields:
| Name | Type | Description |
|---|---|---|
State |
Iterable[State]
|
Derived execution state(s). |
Notes
Responsibilities:
1 2 3 4 | |