Documentation Index
Fetch the complete documentation index at: https://crewai-lorenze-imp-docs-improvements.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Overview
CrewAI Flows is a powerful feature designed to streamline the creation and management of AI workflows. Flows allow developers to combine and coordinate coding tasks and Crews efficiently, providing a robust framework for building sophisticated AI automations. Flows allow you to create structured, event-driven workflows. They provide a seamless way to connect multiple tasks, manage state, and control the flow of execution in your AI applications. With Flows, you can easily design and implement multi-step processes that leverage the full potential of CrewAI’s capabilities.- Simplified Workflow Creation: Easily chain together multiple Crews and tasks to create complex AI workflows.
- State Management: Flows make it super easy to manage and share state between different tasks in your workflow.
- Event-Driven Architecture: Built on an event-driven model, allowing for dynamic and responsive workflows.
- Flexible Control Flow: Implement conditional logic, loops, and branching within your workflows.
When to Use Flows
- You need deterministic orchestration and branching logic.
- You need explicit state transitions across multiple steps.
- You need resumable workflows with persistence.
- You need to combine crews, direct model calls, and Python logic in one runtime.
When Not to Use Flows
- A single prompt/response call is sufficient.
- A single crew kickoff with no orchestration logic is sufficient.
- You do not need stateful multi-step execution.
Getting Started
The example below shows a realistic Flow for support-ticket triage. It demonstrates features teams use in production: typed state, routing, memory access, and persistence.Code

@start()initializes and normalizes state for downstream steps.@router()performs deterministic branching into labeled routes.- Route listeners implement lane-specific behavior (
security,priority,standard). @persist()keeps the flow state recoverable between runs.- Built-in memory methods (
remember,recall) add durable context beyond a single method call.
@start()
The@start() decorator marks entry points for a Flow. You can:
- Declare multiple unconditional starts:
@start() - Gate a start on a prior method or router label:
@start("method_or_label") - Provide a callable condition to control when a start should fire
@start() methods will execute (often in parallel) when the Flow begins or resumes.
@listen()
The@listen() decorator is used to mark a method as a listener for the output of another task in the Flow. The method decorated with @listen() will be executed when the specified task emits an output. The method can access the output of the task it is listening to as an argument.
Usage
The@listen() decorator can be used in several ways:
-
Listening to a Method by Name: You can pass the name of the method you want to listen to as a string. When that method completes, the listener method will be triggered.
Code
-
Listening to a Method Directly: You can pass the method itself. When that method completes, the listener method will be triggered.
Code
Flow Output
Accessing and handling the output of a Flow is essential for integrating your AI workflows into larger applications or systems. CrewAI Flows provide straightforward mechanisms to retrieve the final output, access intermediate results, and manage the overall state of your Flow.Retrieving the Final Output
When you run a Flow, the final output is determined by the last method that completes. Thekickoff() method returns the output of this final method.
Here’s how you can access the final output:

second_method is the last method to complete, so its output will be the final output of the Flow.
The kickoff() method will return the final output, which is then printed to the console. The plot() method will generate the HTML file, which will help you understand the flow.
Accessing and Updating State
In addition to retrieving the final output, you can also access and update the state within your Flow. The state can be used to store and share data between different methods in the Flow. After the Flow has run, you can access the state to retrieve any information that was added or updated during the execution. Here’s an example of how to update and access the state:
first_method and second_method.
After the Flow has run, you can access the final state to see the updates made by these methods.
By ensuring that the final method’s output is returned and providing access to the state, CrewAI Flows make it easy to integrate the results of your AI workflows into larger applications or systems,
while also maintaining and accessing the state throughout the Flow’s execution.
Flow State Management
Managing state effectively is crucial for building reliable and maintainable AI workflows. CrewAI Flows provides robust mechanisms for both unstructured and structured state management, allowing developers to choose the approach that best fits their application’s needs.Unstructured State Management
In unstructured state management, all state is stored in thestate attribute of the Flow class.
This approach offers flexibility, enabling developers to add or modify state attributes on the fly without defining a strict schema.
Even with unstructured states, CrewAI Flows automatically generates and maintains a unique identifier (UUID) for each state instance.
Code

id field is automatically generated and preserved throughout the flow’s execution. You don’t need to manage or set it manually, and it will be maintained even when updating the state with new data.
Key Points:
- Flexibility: You can dynamically add attributes to
self.statewithout predefined constraints. - Simplicity: Ideal for straightforward workflows where state structure is minimal or varies significantly.
Structured State Management
Structured state management leverages predefined schemas to ensure consistency and type safety across the workflow. By using models like Pydantic’sBaseModel, developers can define the exact shape of the state, enabling better validation and auto-completion in development environments.
Each state in CrewAI Flows automatically receives a unique identifier (UUID) to help track and manage state instances. This ID is automatically generated and managed by the Flow system.
Code

- Defined Schema:
ExampleStateclearly outlines the state structure, enhancing code readability and maintainability. - Type Safety: Leveraging Pydantic ensures that state attributes adhere to the specified types, reducing runtime errors.
- Auto-Completion: IDEs can provide better auto-completion and error checking based on the defined state model.
Choosing Between Unstructured and Structured State Management
-
Use Unstructured State Management when:
- The workflow’s state is simple or highly dynamic.
- Flexibility is prioritized over strict state definitions.
- Rapid prototyping is required without the overhead of defining schemas.
-
Use Structured State Management when:
- The workflow requires a well-defined and consistent state structure.
- Type safety and validation are important for your application’s reliability.
- You want to leverage IDE features like auto-completion and type checking for better developer experience.
Flow Persistence
The @persist decorator enables automatic state persistence in CrewAI Flows, allowing you to maintain flow state across restarts or different workflow executions. This decorator can be applied at either the class level or method level, providing flexibility in how you manage state persistence.Class-Level Persistence
When applied at the class level, the @persist decorator automatically persists all flow method states:Method-Level Persistence
For more granular control, you can apply @persist to specific methods:How It Works
-
Unique State Identification
- Each flow state automatically receives a unique UUID
- The ID is preserved across state updates and method calls
- Supports both structured (Pydantic BaseModel) and unstructured (dictionary) states
-
Default SQLite Backend
- SQLiteFlowPersistence is the default storage backend
- States are automatically saved to a local SQLite database
- Robust error handling ensures clear messages if database operations fail
-
Error Handling
- Comprehensive error messages for database operations
- Automatic state validation during save and load
- Clear feedback when persistence operations encounter issues
Important Considerations
- State Types: Both structured (Pydantic BaseModel) and unstructured (dictionary) states are supported
- Automatic ID: The
idfield is automatically added if not present - State Recovery: Failed or restarted flows can automatically reload their previous state
- Custom Implementation: You can provide your own FlowPersistence implementation for specialized storage needs
Technical Advantages
-
Precise Control Through Low-Level Access
- Direct access to persistence operations for advanced use cases
- Fine-grained control via method-level persistence decorators
- Built-in state inspection and debugging capabilities
- Full visibility into state changes and persistence operations
-
Enhanced Reliability
- Automatic state recovery after system failures or restarts
- Transaction-based state updates for data integrity
- Comprehensive error handling with clear error messages
- Robust validation during state save and load operations
-
Extensible Architecture
- Customizable persistence backend through FlowPersistence interface
- Support for specialized storage solutions beyond SQLite
- Compatible with both structured (Pydantic) and unstructured (dict) states
- Seamless integration with existing CrewAI flow patterns
Flow Control
Conditional Logic: or
The or_ function in Flows allows you to listen to multiple methods and trigger the listener method when any of the specified methods emit an output.

logger method will be triggered by the output of either the start_method or the second_method.
The or_ function is used to listen to multiple methods and trigger the listener method when any of the specified methods emit an output.
Conditional Logic: and
The and_ function in Flows allows you to listen to multiple methods and trigger the listener method only when all the specified methods emit an output.

logger method will be triggered only when both the start_method and the second_method emit an output.
The and_ function is used to listen to multiple methods and trigger the listener method only when all the specified methods emit an output.
Router
The@router() decorator in Flows allows you to define conditional routing logic based on the output of a method.
You can specify different routes based on the output of the method, allowing you to control the flow of execution dynamically.

start_method generates a random boolean value and sets it in the state.
The second_method uses the @router() decorator to define conditional routing logic based on the value of the boolean.
If the boolean is True, the method returns "success", and if it is False, the method returns "failed".
The third_method and fourth_method listen to the output of the second_method and execute based on the returned value.
When you run this Flow, the output will change based on the random boolean value generated by the start_method.
Human in the Loop (human feedback)
The
@human_feedback decorator requires CrewAI version 1.8.0 or higher.@human_feedback decorator enables human-in-the-loop workflows by pausing flow execution to collect feedback from a human. This is useful for approval gates, quality review, and decision points that require human judgment.
Code
emit is specified, the human’s free-form feedback is interpreted by an LLM and collapsed into one of the specified outcomes, which then triggers the corresponding @listen decorator.
You can also use @human_feedback without routing to simply collect feedback:
Code
self.last_human_feedback (most recent) or self.human_feedback_history (all feedback as a list).
For a complete guide on human feedback in flows, including async/non-blocking feedback with custom providers (Slack, webhooks, etc.), see Human Feedback in Flows.
Adding Agents to Flows
Agents can be seamlessly integrated into your flows, providing a lightweight alternative to full Crews when you need simpler, focused task execution. Here’s an example of how to use an Agent within a flow to perform market research:
-
Structured Output: Using Pydantic models to define the expected output format (
MarketAnalysis) ensures type safety and structured data throughout the flow. -
State Management: The flow state (
MarketResearchState) maintains context between steps and stores both inputs and outputs. -
Tool Integration: Agents can use tools (like
WebsiteSearchTool) to enhance their capabilities.
Multi-Crew Flows and Plotting
Detailed build walkthroughs and project scaffolding are documented in guide pages to keep this concepts page focused.- Build your first flow: /en/guides/flows/first-flow
- Master state and persistence: /en/guides/flows/mastering-flow-state
- Real-world chat-state pattern: /en/learn/flowstate-chat-history
- Use
flow.plot("my_flow_plot")in code, or - Use
crewai flow plotin CLI projects.
Running Flows
There are two ways to run a flow:Using the Flow API
You can run a flow programmatically by creating an instance of your flow class and calling thekickoff() method:
Streaming Flow Execution
For real-time visibility into flow execution, you can enable streaming to receive output as it’s generated:Memory in Flows
Every Flow automatically has access to CrewAI’s unified Memory system. You can store, recall, and extract memories directly inside any flow method using three built-in convenience methods.Built-in Methods
| Method | Description |
|---|---|
self.remember(content, **kwargs) | Store content in memory. Accepts optional scope, categories, metadata, importance. |
self.recall(query, **kwargs) | Retrieve relevant memories. Accepts optional scope, categories, limit, depth. |
self.extract_memories(content) | Break raw text into discrete, self-contained memory statements. |
Memory() instance is created automatically when the Flow initializes. You can also pass a custom one:
Example: Research and Analyze Flow
analyze step will recall findings from previous executions too — enabling flows that learn and accumulate knowledge over time.
See the Memory documentation for details on scopes, slices, composite scoring, embedder configuration, and more.
Using the CLI
Starting from version 0.103.0, you can run flows using thecrewai run command:
type = "flow" setting in your pyproject.toml) and runs it accordingly. This is the recommended way to run flows from the command line.
For backward compatibility, you can also use:
crewai run command is now the preferred method as it works for both crews and flows.
Common Failure Modes
Router branch not firing
- Cause: returned label does not match a
@listen("label")value. - Fix: align router return strings with listener labels exactly.
State fields missing at runtime
- Cause: untyped dynamic fields or missing kickoff inputs.
- Fix: use typed state and validate required fields in
@start().
Prompt/token growth over time
- Cause: appending unbounded message history in state.
- Fix: apply sliding-window state and summary compaction patterns.
Non-idempotent retries
- Cause: side effects executed on retried steps.
- Fix: add idempotency keys/markers to state and guard external writes.
