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?

Invest now in Acorns!!! 🚀 Join Acorns and get your $5 bonus!
Acorns Logo

Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!

Earn passively and while sleeping

Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.

Robinhood Logo

Invest now!!! Get Free equity stock (US, UK only)!

Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.

The Robinhood app makes it easy to trade stocks, crypto and more.


Webull Logo

Webull! Receive free stock by signing up using the link: Webull signup.

More Related questions...

Show more question and Answers...

OpenClaw Interview Questions

Comments & Discussions