🧑‍🤝‍🧑 Crews: Teams of Specialist Agents

Definition: A Crew is a group of autonomous agents working in parallel toward a shared goal. Each agent has a distinct role and can communicate or share context with its teammates.

When to Use Crews:

🛠️ Crew Example

from crewai import Crew, Agent

class Classifier(Agent):
    def run(self, text):
        # Detect intent
        return {"intent": "summarize"}

class Summarizer(Agent):
    def run(self, text):
        # Perform summarization
        return text[:100] + "…"

class Formatter(Agent):
    def run(self, summary):
        return f"**Summary:** {summary}"

# Build and run a Crew
crew = Crew([Classifier(), Summarizer(), Formatter()])
result = crew.run("Long article text here…")

print(result)
# [
#   {"intent": "summarize"},
#   "Long article text here… (first 100 chars)…",
#   "**Summary:** Long article text here…"
# ]

🔄 Flows: Event‑Driven Pipelines

Definition: A Flow is a linear or branching sequence of steps, each typically handled by one agent. Flows trigger agents in order, passing outputs from one step to the next.

When to Use Flows:

🛠️ Flow Example

from crewai import Flow, Step

# Define steps
flow = Flow()

flow.add_step("ingest", lambda data: data.splitlines())

flow.add_step("validate", lambda lines: [line for line in lines if len(line) > 10])

flow.add_step("analyze", lambda valid: {"count": len(valid)})

flow.add_step("report", lambda stats: f"Valid lines: {stats['count']}")

# Run the Flow
result = flow.run("Short\nThis is a valid line.\nAnother one.")
print(result)  # Output: "Valid lines: 2"

GitHub - awslabs/multi-agent-orchestrator: Flexible and powerful ...

⚖️ Choosing Between Crews and Flows

CrewAI’s flexible architecture means you’re never forced into one pattern—pick the abstraction that best matches your use case, or combine both to architect powerful, maintainable AI systems.