Gallery

Contacts

405 W. Greenlawn Ave Lansing, Michigan 48910

contact@techjacksolutions.com

+1-616-320-4064

CREWAI

How to Build CrewAI Agents: Complete Tutorial

CrewAI gives you a Python framework for assembling multi-agent systems where each agent has a defined role, goal, and set of tools. This tutorial walks through every step: installing the CLI, configuring agents in YAML, defining tasks, wiring up a crew, adding built-in and custom tools, and orchestrating complex pipelines with Flows. By the end, you will have a working multi-agent application that you can extend for research, content generation, or data analysis workflows.

What you will build: A two-agent research crew that searches the web, analyzes results, and produces a structured report, all running from the CrewAI CLI.


3.10+
Python Version Required
2
Process Types
3
Flow Decorators

Prerequisites

Before installing CrewAI, confirm that your environment meets these requirements. CrewAI enforces strict Python version bounds and depends on compiled C extensions, so skipping any prerequisite will cause installation failures.

Setup Checklist
Python >=3.10 and <3.14 – Run python --version to verify. Python 3.9 and below are not supported.
OpenAI API key (or another supported LLM provider) – Set via OPENAI_API_KEY environment variable.
uv package manager (from Astral, creators of Ruff) – Required by the CrewAI CLI for dependency management.
Windows only: Visual Studio Build Tools with the "Desktop development with C++" workload – needed for compiled dependencies.

Install CrewAI

CrewAI uses uv as its default package manager. Install uv first, then install the CrewAI CLI as a global tool.

Step 1: Install uv

macOS / Linux curl -LsSf https://astral.sh/uv/install.sh | sh
Windows (PowerShell) powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

Step 2: Install CrewAI CLI

Terminal uv tool install crewai

Step 3: Scaffold a new crew project

Terminal crewai create crew my_research_crew

This generates the full project structure: src/my_research_crew/config/agents.yaml, tasks.yaml, crew.py, main.py, a .env file for API keys, and directories for custom tools and knowledge files.

Step 4: Install dependencies and run

Terminal cd my_research_crew crewai install crewai run

Alternative install: If you prefer pip over uv, run pip install 'crewai[a2a]' to get CrewAI with all optional dependencies.

Tutorial Progress
0 of 7 sections complete

Define Agents

An Agent in CrewAI represents a single autonomous worker with a specific role. Each agent gets three required personality parameters (essentially prompt engineering via YAML) that shape how the LLM responds: role, goal, and backstory.

The YAML-first approach keeps agent definitions separate from your Python logic. Edit src/my_research_crew/config/agents.yaml:

agents.yaml researcher: role: "Senior Research Analyst" goal: "Find accurate, up-to-date information on {topic}" backstory: > You are a meticulous researcher with 10 years of experience in data analysis. You cross-reference multiple sources before reporting findings. tools: - SerperDevTool - ScrapeWebsiteTool verbose: true writer: role: "Technical Content Writer" goal: "Turn raw research into a clear, structured report" backstory: > You write for a technical audience that values precision over filler. Every claim must cite its source. verbose: true allow_delegation: false
7
Key Agent parameters: role, goal, backstory, tools, llm, verbose, and allow_delegation. Additional options include max_iterations, max_rpm, allow_code_execution, and memory.

Delegation behavior: By default, allow_delegation is True when a crew has multiple agents. Set it to false on worker agents (like the writer above) to prevent infinite delegation loops where agents keep passing tasks back and forth.


FREE TEMPLATE

Agentic AI Compliance Assessment

Compliance checklist for autonomous agent deployments

Download Free →

Define Tasks

A Task tells an agent exactly what to do and what output format to produce. Each task needs a description, an expected_output, and an assigned agent. In sequential mode, every task must have an agent assigned.

Edit src/my_research_crew/config/tasks.yaml:

tasks.yaml research_task: description: > Search for the latest developments on {topic}. Focus on announcements from the past 30 days. Include source URLs for every claim. expected_output: > A structured list of 5-10 findings, each with a one-sentence summary and source URL. agent: researcher report_task: description: > Using the research findings, write a 500-word technical briefing on {topic}. Cite all sources inline. expected_output: > A markdown-formatted report with sections for key findings, analysis, and source list. agent: writer output_file: "output/report.md"
Parameter Required Purpose
descriptionYesWhat the agent should accomplish
expected_outputYesFormat and structure of the result
agentSequential: YesWhich agent handles this task
output_fileNoSave result to disk automatically
output_jsonNoParse output as JSON (Pydantic model)
contextNoReference outputs from other tasks
guardrailNoValidation function that can reject and retry

Assemble a Crew

The Crew object brings agents and tasks together, selects the execution process, and provides the kickoff() method that runs everything. Edit crew.py:

crew.py from crewai import Agent, Task, Crew, Process from crewai_tools import SerperDevTool, ScrapeWebsiteTool search_tool = SerperDevTool() scrape_tool = ScrapeWebsiteTool() researcher = Agent( role="Senior Research Analyst", goal="Find accurate, up-to-date information on {topic}", backstory="You are a meticulous researcher...", tools=[search_tool, scrape_tool], verbose=True ) writer = Agent( role="Technical Content Writer", goal="Turn raw research into a clear, structured report", backstory="You write for a technical audience...", verbose=True, allow_delegation=False ) research_task = Task( description="Search for the latest developments on {topic}...", expected_output="A structured list of 5-10 findings...", agent=researcher ) report_task = Task( description="Write a 500-word technical briefing on {topic}...", expected_output="A markdown-formatted report...", agent=writer, output_file="output/report.md" ) crew = Crew( agents=[researcher, writer], tasks=[research_task, report_task], process=Process.sequential, verbose=True ) result = crew.kickoff(inputs={"topic": "CrewAI multi-agent frameworks"}) print(result.raw)

Sequential vs. Hierarchical: Process.sequential (the default) runs tasks in the order listed, passing each output to the next. Process.hierarchical uses a manager agent (or manager_llm) to dynamically delegate tasks across agents.

The kickoff() method accepts an inputs dictionary. Any {placeholder} in agent goals or task descriptions gets replaced with the corresponding value from this dictionary. The return value is a CrewOutput object with properties for .raw, .json, .pydantic, and .token_usage.


Add Tools

Tools give agents the ability to interact with the outside world. CrewAI ships with built-in tools for web search, scraping, file operations, and code execution. You can also write custom tools by inheriting from BaseTool.

Built-in tools

Tool What It Does Requires
SerperDevToolGoogle Search via Serper.dev API, returns structured JSONSERPER_API_KEY
ScrapeWebsiteToolExtracts content from web pagesNone
FileReadToolReads and extracts data from local filesNone
CodeInterpreterToolRuns Python in a sandboxed environmentNone

Custom tools

Place custom tools in the tools/ directory. Each tool must inherit from BaseTool, define a name and description, and implement the _run method:

tools/sentiment_tool.py from crewai.tools import BaseTool class SentimentAnalysisTool(BaseTool): name: str = "Sentiment Analyzer" description: str = "Analyzes the sentiment of a given text passage." def _run(self, text: str) -> str: # Your sentiment analysis logic here positive_words = ["good", "great", "excellent"] score = sum(1 for w in text.lower().split() if w in positive_words) return f"Sentiment score: {score} positive signals found"

Then assign the tool to an agent: tools=[SentimentAnalysisTool()]. The agent reads the tool's description and _run method signature to decide when and how to call it, so detailed docstrings and type hints are important for accurate tool invocation.


Orchestrate with Flows

Flows provide a deterministic, event-driven orchestration layer for situations where a single crew is not enough. This is where CrewAI transitions from a framework into a full agentic AI platform. Use Flows when you need to chain multiple crews, add conditional routing, or maintain structured state across pipeline stages.

A Flow class uses three decorators to control execution:

  • @start() marks the entry point that runs first
  • @listen() triggers a method when a previous method completes
  • @router() sends execution down different paths based on conditions
flow_example.py from crewai.flow.flow import Flow, listen, start, router from pydantic import BaseModel class ResearchState(BaseModel): topic: str = "" research_data: str = "" quality_score: int = 0 class ResearchFlow(Flow[ResearchState]): @start() def gather_research(self): # Run a research crew here self.state.research_data = "findings from crew..." return self.state.research_data @listen(gather_research) def evaluate_quality(self, research_data): # Score the research output self.state.quality_score = 8 return self.state.quality_score @router(evaluate_quality) def decide_next_step(self, quality_score): if quality_score >= 7: return "publish" return "revise" @listen("publish") def publish_report(self): return f"Published: {self.state.research_data}" @listen("revise") def revise_research(self): # Re-run the research crew with refined inputs return "Revision requested"

State management uses Pydantic BaseModel classes, giving you typed attributes with validation. Each flow method can read and update self.state to pass data between stages without relying on LLM memory.


Limitations and Gotchas

CrewAI handles a lot of orchestration automatically, but there are tradeoffs worth knowing before you commit to a production deployment.

Memory is local-only by default
All four memory types store data in .crewai/memory on local disk. Container redeployments wipe this data, and there is no built-in multi-user isolation. For production, CrewAI recommends Mem0 for persistent, isolated memory storage.
Hierarchical delegation loops
When using Process.hierarchical with vaguely defined agent roles, agents can enter infinite delegation loops. Prevent this by setting allow_delegation: false on worker agents and writing specific, non-overlapping role descriptions.
Token cost multiplication
Multi-agent coordination passes context between agents at every step. Community benchmarks suggest this can increase token usage by 4x compared to a single-agent approach. Monitor result.token_usage to track actual consumption per run.

Troubleshooting

These are the most common issues encountered during CrewAI setup and their fixes.

This usually means your Python version is outside the supported range (>=3.10, <3.14). Run python --version to check. If you have multiple Python installations, make sure uv is using the correct one. You can specify the version with uv python pin 3.12 in your project directory.
Set allow_delegation: false on all worker agents. Delegation loops happen when multiple agents have overlapping roles and keep passing tasks to each other. Only the manager agent in a hierarchical crew should have delegation enabled. Also reduce max_iterations to a reasonable cap (e.g., 10) to force termination.
Install Visual Studio Build Tools and select the "Desktop development with C++" workload. CrewAI depends on packages with compiled C extensions that require these build tools. Restart your terminal after installation.
Verify that SERPER_API_KEY is set in your .env file and that the .env file is in your project root. The Serper.dev free tier has a limited number of searches per month. Check your remaining quota at serper.dev.
Verified against CrewAI official documentation, May 2026
CrewAI is a trademark of CrewAI, Inc. This article is an independent editorial resource by Tech Jacks Solutions. Not affiliated with or endorsed by CrewAI, Inc.
Before You Use AI
Your Privacy
CrewAI crews send prompts and data to LLM providers (OpenAI, Anthropic, etc.) based on your API configuration. Free-tier API keys may allow providers to use your data for model training. Enterprise API plans typically include data processing agreements that restrict training use. Review each provider's data use policy before processing sensitive information through multi-agent workflows.
Mental Health & AI Dependency
Automated AI agents can produce outputs that feel authoritative but may contain hallucinated facts, fabricated sources, or incorrect analysis. Over-reliance on AI-generated research without human verification introduces real risk in professional and personal decisions. If you are experiencing distress:
  • 988 Suicide & Crisis Lifeline: Call or text 988
  • SAMHSA Helpline: 1-800-662-4357
  • Crisis Text Line: Text HOME to 741741
AI systems can produce plausible-sounding but incorrect guidance. For mental health, medical, legal, or financial decisions, always consult a qualified professional.
Your Rights & Our Transparency
Under GDPR and CCPA, you have the right to access, correct, and delete your personal data held by AI service providers. Tech Jacks Solutions maintains editorial independence from all vendors reviewed on this site. Some links may be affiliate links, which help fund independent research at no extra cost to you. The EU AI Act classifies multi-agent orchestration systems according to their intended use and risk level.