A CrewAI Flow is the structured counterpart to a crew: you define the steps, their order, the conditions and the state, and the Flow owns the sequence while crews do the reasoning inside individual steps. That is the shape the CrewAI docs recommend for anything headed to production: start with a Flow and run a crew inside one of its steps. Use it when you control which steps run, in what order and under what conditions.
What you need
- Python with the crewai package installed
- A task with steps that must run in a known order
- A crew that already works for one of those steps
Step 1: Define the Flow state and the first step
Create a Flow with a state object holding the data each step needs, and a start method for the first step. Keep the state small: only what later steps must read.
Step 2: Add the steps and their listeners
Add a method for each later step and listen for the step it follows, so the Flow runs them in order. Add a router method where the Flow must choose between two paths from a result.
Step 3: Run the Flow and check the order held
Run the Flow with a real input and confirm each step ran once, in order, with the state carried between them. If a step ran out of order or twice, the listener is wired to the wrong event.
Worked example: synthetic three-step Flow
The table below is a synthetic example. It shows the expected result of a Flow run; no Flow was run.
| Step | Ran in order? | State carried? |
|---|---|---|
| Fetch records | Yes, first | Yes |
| Analyse with crew | Yes, second | Yes |
| Write report | Yes, third | Yes |
Expected result (UNTESTED). all three steps run once in order, with the state carried between them. This check was not run live; the table shows the expected result for the synthetic example.
Limits
- A Flow owns the order, so do not also ask the agents to decide the sequence; the two will fight.
- State is saved after each method, so keep it small and serializable.
- A single agent is enough for one intelligent task with tools; reach for a Flow when you control the steps.
