How Crews Work
A crew is a team of AI agents that collaborate to complete a goal. Think of it like hiring a small team of specialists: each person has a clear role, knows what tools they can use, and hands their work off to the next person when done.
The four building blocks
Agent
An agent is a specialist. You define:
- Role — what their job title is ("Senior Software Engineer", "Legal Analyst")
- Goal — what they're optimizing for ("write clean, tested code", "identify contract risks")
- Backstory — context that shapes their personality and approach
- Tools — what they can do (search the web, run code, read/write files)
- LLM — which model powers them (use a stronger model for harder jobs)
from crewai import Agent, LLM
engineer = Agent(
role="Senior Software Engineer",
goal="Write clean, working Python code that solves the stated problem",
backstory="You are a pragmatic engineer. You prefer simple solutions, write tests, and always check that your code runs before declaring it done.",
tools=[PythonSandboxTool(), ObsidianWriteTool()],
llm=LLM(model="openai/qwen3-coder", base_url="http://localhost:4000/v1", api_key=...),
)Task
A task is a specific piece of work assigned to one agent. You define:
- Description — exactly what needs to be done (be specific — this is the agent's brief)
- Expected output — what a successful result looks like
- Agent — who does the work
- Context — optionally, the output of a previous task (for passing work between agents)
from crewai import Task
build_task = Task(
description="Implement a REST API endpoint that accepts a video URL and returns a frame count. Write the code to /tmp/solution.py and run it to verify it works.",
expected_output="Working Python file at /tmp/solution.py with a passing test run shown.",
agent=engineer,
)Crew
A crew is the team + the order of work. You define:
- Agents — who's on the team
- Tasks — what needs to be done, in order
- Process —
sequential(A then B then C) orhierarchical(a manager delegates)
from crewai import Crew, Process
crew = Crew(
agents=[researcher, engineer, reviewer],
tasks=[research_task, build_task, review_task],
process=Process.sequential,
)
result = crew.kickoff()Tool
A tool is a capability an agent can invoke — like calling a function. Tools are how agents interact with the world outside the LLM: searching the web, reading files, running code, scraping sites, writing to Obsidian.
This server ships with these tools in every crew template:
| Tool | What it does |
|---|---|
DuckDuckGoSearchTool | Search the web |
WebScrapeTool | Fetch and extract text from a URL |
PythonSandboxTool | Run Python in an isolated container |
ObsidianReadTool | Read a note from your vault |
ObsidianWriteTool | Write a note to your vault |
ObsidianListTool | List notes in your vault |
You can write custom tools for anything else — a GovWin login, a GitHub commit, a Slack message, a database query.
Sequential vs hierarchical process
Sequential — tasks run in order, each agent's output becomes context for the next. Best for pipelines where step B needs step A's result.
Researcher → Writer → ReviewerHierarchical — a manager agent reads the goal, breaks it into subtasks, and delegates to the right specialist. Best for open-ended goals where you don't know the steps upfront.
Manager
├── delegates "research competitors" → Researcher
├── delegates "write summary" → Writer
└── delegates "check facts" → ReviewerUse hierarchical when you want to say "build me a video surveillance app" and let the crew figure out the steps. Use sequential when you have a defined pipeline (research → propose → build → review).
How agents pass work to each other
In a sequential crew, tasks automatically receive the output of all previous tasks as context. You don't wire this manually — CrewAI handles it.
You can also explicitly pass a task's output as context to a specific task:
write_task = Task(
description="Write the proposal based on the research findings.",
agent=writer,
context=[research_task], # explicitly inject research_task output
)Choosing the right model per agent
Not every agent needs the most powerful model. Assign models by task complexity:
| Agent job | Recommended model |
|---|---|
| Web search + summarise | qwen3-general (local, fast) |
| Write code | qwen3-coder (local, optimised for code) |
| Legal / contract analysis | claude-sonnet (cloud, nuanced reasoning) |
| Manager / planner in hierarchical crews | claude-sonnet or claude-opus |
| Simple formatting / assembly | qwen3-general |