Prev Next

AI / CrewAI Interview Questions II

Explain the lifecycle of state persistence in a Flow using the @persist decorator?

flowchart LR A[Flow Starts] --> B[Unique UUID Assigned] B --> C[State Updated as Methods Execute] C --> D[@persist Writes State to Backing Store] D --> E{Interrupted?} E -->|Yes| F[State Reloaded from Store] F --> C E -->|No| G[Flow Completes]
  1. Initialization: a Flow instance is created and automatically assigned a unique identifier, a UUID, as part of its state
  2. Execution: as @start, @listen, and @router methods run, they read from and write to the Flow's state, whether unstructured as a dictionary or structured as a Pydantic model
  3. Persistence: with @persist applied to the Flow class, this state is written out to a backing store, SQLite by default, or PostgreSQL for multi-instance deployments, as execution proceeds
  4. Interruption: if the Flow is interrupted, whether by a crash, a deliberate pause such as @human_feedback, or a restart, its state isn't lost
  5. Recovery: on resumption, the Flow reloads its persisted state and continues rather than starting over from the beginning

This lifecycle is specifically what makes long-running or human-in-the-loop Flows viable in production, without it, any interruption would force the entire workflow to restart from scratch, discarding whatever progress had already been made.

What is assigned to a Flow instance automatically at initialization?
What happens on recovery after an interruption, with @persist applied?

More Related questions...

Show more question and Answers...


Comments & Discussions