Server-side workflow state storage implementations
WorkflowStateStore Protocol
The WorkflowStateStore protocol defines the interface for persisting workflow state. This allows patterns like StepFlow to work with different storage backends (in-memory, file-based, database) without being coupled to any specific implementation.
Implementations receive the sess (session) object to extract a session identifier for scoping state to individual users.
The state store needs a way to identify individual users/sessions. We store a small UUID in the session object itself (the only thing we store there) and use it as a key for server-side storage.
In-memory workflow state storage for development and testing.
Usage Example
# Create a store instancestore = InMemoryWorkflowStateStore()# Mock session object (in real usage, this comes from FastHTML)mock_sess = {}# Store and retrieve statestore.set_current_step("my_workflow", mock_sess, "step_1")print(f"Current step: {store.get_current_step('my_workflow', mock_sess)}")store.update_state("my_workflow", mock_sess, {"name": "Alice", "email": "alice@example.com"})print(f"State: {store.get_state('my_workflow', mock_sess)}")# Session only contains the session IDprint(f"Session contents: {mock_sess}")
# Verify it satisfies the protocolassertisinstance(store, WorkflowStateStore), "InMemoryWorkflowStateStore must implement WorkflowStateStore protocol"print("Protocol check passed!")