Overview
Contexts in Flow Core manage state at two levels:- NodeContext: Individual node execution state
- WorkflowContext: Shared state across the entire workflow
NodeContext
Each node has its own isolated context for execution:NodeContext Properties
| Property | Type | Description |
|---|---|---|
node_id | str | Unique identifier for the node |
status | NodeStatus | Current execution status |
input_data | Dict | Input passed to the node |
output_data | Dict | Output produced by the node |
error | Optional[str] | Error message if failed |
start_time | datetime | Execution start timestamp |
end_time | datetime | Execution end timestamp |
metadata | Dict | Additional node metadata |
variables | Dict | Node-specific variables |
NodeStatus Enum
WorkflowContext
Shared context accessible by all nodes in the workflow:WorkflowContext Properties
| Property | Type | Description |
|---|---|---|
workflow_id | str | Unique workflow identifier |
global_variables | Dict | Variables accessible by all nodes |
shared_state | Dict | Mutable shared state |
execution_metadata | Dict | Workflow execution metadata |
node_results | Dict | Results from all executed nodes |
config | Dict | Workflow configuration |
Using Contexts in Nodes
Accessing Input Data
Setting Output Data
Using Node Variables
Workflow Context Patterns
Sharing Data Between Nodes
Global Variables
Accessing Previous Node Results
Context Lifecycle
1
Initialization
Contexts are created when workflow starts
2
Pre-execution
Node context is prepared with input data
3
Execution
Node processes using both contexts
4
Post-execution
Contexts are updated with results
5
Cleanup
Contexts can be persisted or cleaned up
Advanced Context Features
Context Persistence
Context Isolation
Context Validation
Context Helpers
Context Utilities
Context Decorators
Memory Management
Context Size Limits
Context Cleanup
Debugging with Contexts
Context Logging
Context Inspection
Best Practices
Minimize Shared State
Minimize Shared State
Use Immutable Data
Use Immutable Data
When possible, use immutable data structures to avoid unexpected mutations.
Clear Sensitive Data
Clear Sensitive Data
Always clear sensitive data from contexts after use.
Document Context Dependencies
Document Context Dependencies
Clearly document what context data each node expects and produces.