Introduction to CrewAI

What is CrewAI?

CrewAI is an open-source framework for orchestrating autonomous AI agents and building complex workflows. It combines two layers:

  • Flows — the backbone of your app: structured, event-driven workflows that own state and control execution.
  • Crews — the units of work inside that backbone: teams of role-playing agents that collaborate on tasks the Flow delegates.

Official guidance: for any production-ready application, start with a Flow. Use a Flow for structure, state, and logic. Use a Crew inside a Flow step when you need a team of agents to work autonomously.

Coding agents (Cursor, Claude Code, Codex, …) can install the official skills:

npx skills add crewaiinc/skills

Source of truth: docs.crewai.com/llms.txt and skills.crewai.com.


Architecture: Flows control, Crews think

┌─────────────────────────────────────────────────────────┐
│  Flow (backbone: state, events, branching, persistence) │
│    @start → @listen / @router → next step               │
│         │                                               │
│         ▼                                               │
│    Crew.kickoff() (role-playing team)                   │
│         Agent(role, goal, backstory, tools)             │
│         Task(description, expected_output)              │
│         Process.sequential | hierarchical               │
└─────────────────────────────────────────────────────────┘
LayerRoleWhat it gives you
FlowThe “manager” / process definitionState, event triggers, conditionals / loops / branches
CrewThe team that does the workRole-playing agents, autonomous collaboration, delegation

Together: the Flow starts and holds state → delegates a hard task to a Crew → agents collaborate → the Crew returns a result → the Flow continues.


When to use Crews vs Flows

Short answer: use both.

Use caseArchitecture
Simple automationFlow only, with ordinary Python in steps
Complex research / writingFlow owns state → Crew researches and drafts
App backendFlow handles the API → Crew generates → Flow writes to the DB

Do not start by spawning many agents. Draw the predictable steps as a Flow; hand the “needs judgment and a tool loop” segment to a Crew.


vs LangChain / LangGraph and LlamaIndex

CrewAILangChain + LangGraphLlamaIndex
StrengthRole teams + production Flow backboneAgent harness, graph nodes / edges / checkpointsIndexing, query engines, document RAG
OrchestrationFlow events + Crew process (sequential / hierarchical)StateGraph, conditional edges, interruptsQuery / retrieval pipelines
Multi-agentFirst-class Agent + CrewSubgraphs / multi-agent nodes you assembleAgents are secondary
RAGTools (RagTool, LlamaIndexTool, …)Retrievers + agentic RAGHome for the data layer

Choose CrewAI for researcher / writer / reviewer role-play. Choose LangChain (especially LangGraph) for fine-grained graphs, checkpoints, and middleware. Choose LlamaIndex when indexing/query is the product; wrap it with LlamaIndexTool if a Crew needs it. For chunking, vector stores, and eval, see the RAG tutorial.

These stacks compose; they are not mutually exclusive.


Core objects

ObjectEssentials
Agentrole, goal, backstory; optional tools, llm
Taskdescription, expected_output; assign agent
Crewagents + tasks + process
Processsequential (task list order) or hierarchical (manager_llm / manager_agent required)
Flow@start() entries, @listen(...) listeners, @router() branches

New CLI projects are JSON-first (agents/*.jsonc + crew.jsonc). This tutorial teaches the Python API; scaffolding commands are in Installation.


Good fit / caveats

Good fit: multi-role collaboration, research-and-write with tools, backends that need a state machine plus an autonomous team.

Watch out: one-shot prompts with no tools or state (call the Chat API); ultra-low latency (multi-agent token cost); hierarchical crews without a manager LLM.


Next steps

评论