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
__hash__
Return stable hash based on node ID.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Hash of the node ID, allowing nodes to be used as dict keys. |
__new__
Create or reuse an async node instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args |
Any
|
Positional constructor arguments forwarded to |
()
|
**kwargs |
Any
|
Keyword constructor arguments forwarded to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
AsyncNode |
AsyncNode
|
A fresh instance for subclasses declaring a parameterized
|
__repr__
Return computation identity based on node ID.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
String of the form |
__str__
Return user-facing display name.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
String of the form |
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 |
Any
|
Dot-path payload updates. |
None
|
confidence_delta |
float
|
Confidence adjustment. |
0.0
|
metadata_update |
Any
|
Metadata updates. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
State |
State
|
New child execution state. |
Notes
Responsibilities:
1 2 | |
is_async
Return whether this node executes asynchronously.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the node is an |
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
Execute no-op resolution in sync contexts.
Sync-only engines (and the base Node.run) treat an AsyncNode as a
no-op consumer: this returns no states, signalling that an async engine
is required.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state |
State
|
Input execution state. |
required |
Returns:
| Type | Description |
|---|---|
Iterable[State]
|
Iterable[State]:
Empty tuple, since async execution is handled by
|
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
Guarantees:
1 2 3 | |
run
run_async
async
Execute this node asynchronously on a state, validating outputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state |
State
|
Input execution state. |
required |
Returns:
| Type | Description |
|---|---|
tuple[State, ...]
|
tuple[State, ...]: Derived execution states. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
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
__hash__
Return stable hash based on node ID.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Hash of the node ID, allowing nodes to be used as dict keys. |
__new__
Create or reuse a node instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args |
Any
|
Positional constructor arguments forwarded to |
()
|
**kwargs |
Any
|
Keyword constructor arguments forwarded to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Node |
Node
|
A fresh instance for subclasses declaring a parameterized
|
Notes
Guarantees:
1 2 3 4 5 6 | |
__repr__
Return computation identity based on node ID.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
String of the form |
__str__
Return user-facing display name.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
String of the form |
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 |
Any
|
Dot-path payload updates. |
None
|
confidence_delta |
float
|
Confidence adjustment. |
0.0
|
metadata_update |
Any
|
Metadata updates. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
State |
State
|
New child execution state. |
Notes
Responsibilities:
1 2 | |
is_async
Return whether this node executes asynchronously.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the node is an |
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 |
Returns:
| Type | Description |
|---|---|
Iterable[State]
|
Iterable[State]: Derived execution state(s). |
Notes
Responsibilities:
1 2 3 4 | |