Node class is the foundation of all workflow nodes in CrystalFlow.
Class: Node
Properties
string
Unique identifier for the node instance. Auto-generated on creation.
string
Node type identifier (e.g.,
'math.add'). Set via @defineNode decorator.NodeMetadata
Node metadata including label, category, description, and port definitions.
NodeState
Current execution state:
'idle', 'executing', 'success', or 'error'.Methods
execute()
Execute the node’s business logic. Must be implemented by all nodes.validate()
Validate node configuration and inputs.ValidationResult with isValid boolean and optional errors array.
Example:
run()
Execute the node with validation and state management. Called by the execution engine.ExecutionContext
Optional execution context providing variables and timing info.
- Set state to
'executing' - Call
validate() - Call
execute() - Set state to
'success'or'error'
reset()
Reset node state to idle and clear outputs.toJSON()
Serialize node to JSON format.id, type, position, and data (inputs, outputs, properties).
Example:
fromJSON()
Deserialize node from JSON format.NodeJSON
JSON representation of the node.
checkCancellation()
Check if execution has been cancelled. ThrowsCancellationError if cancelled.
Types
NodeMetadata
NodeState
ValidationResult
NodeJSON
Interface: IConditionalNode
Nodes implement this interface to enable conditional branching in workflows.evaluateCondition()
Determines which branch should execute based on the node’s state.- Must return a string matching an existing output port name
- Called after
execute()completes - Must be deterministic based on node state
- Should not modify node state or perform side effects
The execution engine uses
evaluateCondition() to build and execute conditional
branches. Only nodes connected to the returned output port will execute.- Conditional Flow Guide - Complete guide to conditional workflows
- Built-in Conditional Nodes - IfNode and SwitchNode API
- Conditional Logic Examples - Working examples
Examples
Basic Node
Async Node with Validation
Long-Running Node with Cancellation
Related
Creating Custom Nodes
Learn to build custom nodes
Decorators
Decorator API reference
Workflow
Workflow class reference
Executor
Executor class reference