Beginner
Installation & Setup
Install CrewAI, configure your LLM provider, and build your first crew with two agents that collaborate on a task.
Installation
Bash
# Install CrewAI pip install crewai # Install with tools support pip install "crewai[tools]" # Set your API key export OPENAI_API_KEY="sk-..." # Or use the CrewAI CLI to create a project crewai create crew my_crew cd my_crew
Your First Crew
Here is a complete example of a two-agent crew that researches a topic and writes an article:
Python - first_crew.py
from crewai import Agent, Task, Crew, Process # Define agents researcher = Agent( role="Senior Research Analyst", goal="Find comprehensive information about AI trends in 2026", backstory="""You are an experienced research analyst with a talent for finding and synthesizing information from multiple sources. You are thorough, accurate, and always cite your findings.""", verbose=True ) writer = Agent( role="Content Writer", goal="Write an engaging article based on research findings", backstory="""You are a skilled content writer who transforms complex research into clear, engaging articles. You write in a professional yet approachable tone.""", verbose=True ) # Define tasks research_task = Task( description="""Research the top 5 AI trends for 2026. Include specific examples, statistics, and expert opinions. Focus on practical applications, not hype.""", expected_output="A detailed research report with 5 AI trends", agent=researcher ) writing_task = Task( description="""Write a 500-word article about AI trends in 2026 based on the research findings. Make it engaging and informative. Include an introduction, body, and conclusion.""", expected_output="A polished 500-word article", agent=writer ) # Create and run the crew crew = Crew( agents=[researcher, writer], tasks=[research_task, writing_task], process=Process.sequential, # Tasks run in order verbose=True ) result = crew.kickoff() print(result)
Using Different LLMs
Python
from crewai import Agent, LLM # Use a specific OpenAI model agent = Agent( role="Analyst", goal="Analyze data", backstory="You are a data analyst.", llm="gpt-4o" ) # Use Anthropic Claude agent = Agent( role="Analyst", goal="Analyze data", backstory="You are a data analyst.", llm=LLM(model="anthropic/claude-sonnet-4-20250514") ) # Use local Ollama model agent = Agent( role="Analyst", goal="Analyze data", backstory="You are a data analyst.", llm=LLM(model="ollama/llama3", base_url="http://localhost:11434") )
Use verbose mode: Always set
verbose=True during development to see each agent's thought process, tool usage, and delegation decisions. This is invaluable for debugging and understanding agent behavior.Cost awareness: Each agent makes multiple LLM calls per task (reasoning, tool use, delegation). A crew with 3 agents and 3 tasks can make 10-30+ LLM calls. Start with GPT-4o-mini or local models during development.
What's Next?
In the next lesson, we will dive deep into agent design — crafting effective roles, goals, backstories, and assigning tools for maximum effectiveness.