CrewAI Flows Guide

Agent

by davila7 · Added 5mo ago

Claude

Install

npx claude-code-templates@latest --agent=cli-tool/components/skills/ai-research/agents-crewai/references --yes

Add to Claude

claude mcp add crewai-flows-guide

About

CrewAI Flows Guide

Overview

Flows provide event-driven orchestration with precise control over execution paths, state management, and conditional branching. Use Flows when you need more control than Crews provide.

When to Use Flows vs Crews

ScenarioUse CrewsUse Flows
Simple multi-agent collaboration
Sequential/hierarchical tasks
Conditional branching
Complex state management
Event-driven workflows
Hybrid (Crews inside Flow steps)

Flow Basics

Creating a Flow

from crewai.flow.flow import Flow, listen, start, router, or_, and_
from pydantic import BaseModel

# Define state model
class MyState(BaseModel):
    counter: int = 0
    data: str = ""
    results: list = []

# Create flow with typed state
class MyFlow(Flow[MyState]):

    @start()
    def initialize(self):
        """Entry point - runs first"""
        self.state.counter = 1
        return {"initialized": True}

    @listen(initialize)
    def process(self, data):
        """Runs after initialize completes"""
        self.state.counter += 1
        return f"Processed: {data}"

# Run flow
flow = MyFlow()
result = flow.kickoff()
print(flow.state.counter)  # Access final state

Flow Decorators

@start() - Entry Point

@start()
def begin(self):
    """First method(s) to execute"""
    return {"status": "started"}

# Multiple start points (run in parallel)
@start()
def start_a(self):
    return "A"

@start()
def start_b(self):
    return "B"

@listen() - Event Trigger

# Listen to single method
@listen(initialize)
def after_init(self, result):
    """Runs when initialize completes"""
    return process(result)

# Listen to string name
@listen("high_confidence")
def handle_high(self):
    """Runs when router returns 'high_confidence'"""
    pass

@router() - Conditional Branching

@router(analyze)
def decide_path(self):

Tags

FullStackaitmplclaude-code-templates

From Our Store

View all →
Claude Code

Claude Code Power User Kit

$39+

Advanced Claude Code skills and configurations

OpenClaw

OpenClaw Business Starter Kit

$59+

Set Up Your AI Assistant in 60 Minutes