Shared State
Shared state enables data sharing and communication between workflow nodes through theSharedState class and workflow_state() function.
Core Concept
Every workflow has an associated shared state that tracks execution history, stores data, and provides access to node outputs:SharedState Parameter
Automatic Injection
Add aSharedState parameter to any node to access state:
SharedState parameter allowed per node.
State Access Methods
workflow_state() Function
Access state from decision functions and nested code:Access Patterns
By node name:Accessing Node Outputs
get_node_output()
Get output from previously executed nodes:get_node_attribute()
Access nested attributes with dot notation:State Properties
initial_input
Access the workflow’s original input:final_output
Get the most recent node output:previous_output
Access the immediately previous node’s output:execution_count
Track how many nodes have executed:Parallel Node Outputs
get_parallel_outputs()
Access results from parallel branches:Dictionary-based Access
Parallel results automatically stored in state dict:Execution History
get_execution_history()
Get full execution history:get_node_execution_count()
Count how many times a node has executed:get_execution_sequence()
Get sequence of executed node names:Loop Detection
detect_execution_loop()
Detect repetitive execution patterns:check_node_execution_limit()
Enforce execution limits per node:Generic State Store
store Property
Store arbitrary workflow data:- Accumulating metrics across nodes
- Storing configuration data
- Caching computed values
- Temporary workflow-level storage
State Serialization
Save State
Persist state to disk:Load State
Restore previously saved state:to_dict() / from_dict()
Manual serialization:Advanced Patterns
State-Based Routing
Accumulator Pattern
Conditional Processing
Metrics Collection
Best Practices
Use store for temporary data
Use store for temporary data
Check if node has executed before accessing
Check if node has executed before accessing
Use workflow_state() in decision functions
Use workflow_state() in decision functions
Initialize store data at workflow start
Initialize store data at workflow start
Save state at checkpoints
Save state at checkpoints
Performance Considerations
State Access Overhead
- Dictionary access: Less than 1ms
- get_node_output(): Less than 1ms (cached)
- workflow_state(): Less than 1ms
- Serialization: ~10ms per MB
Memory Impact
- Per node output: ~100-500 bytes metadata
- Execution history: ~50 bytes per entry
- Store data: Depends on stored values

