Installation & Setup
Install CrewAI, configure your LLM provider, and build your first crew with two agents that collaborate on a task.
Installation
# 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:
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
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") )
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.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.
Ready to Go Deeper?
Live instructor-led courses from our partners. Affiliate disclosure.
AI & ML Courses - 30% Off
Live instructor-led AI, machine learning, data science, and cloud courses for working professionals. Use code Limited30 at checkout.
EdurekaDataCamp - AI & Data Science
Hands-on Python, machine learning, and AI courses with interactive exercises and real projects.
DataCampedX - Top AI Courses
University-level AI courses from MIT, Harvard, Stanford. Earn certificates that employers recognize.
edX