CrewAI Basics

Master CrewAI framework for orchestrating role-playing autonomous AI agents

Defining Agents & Roles

In CrewAI, agents are defined by three core attributes: their role (job title), goal (what they aim to achieve), and backstory (expertise and context). This role-based design makes agents feel like real team members with distinct personalities and expertise.

Interactive: Explore Agent Roles

🔍

Senior Researcher

Curious, thorough, skeptical of hype

Role:
Senior Researcher
Goal:
Uncover cutting-edge developments in AI and data science
Backstory:
You work at a leading tech think tank. Your expertise lies in identifying emerging trends and analyzing their implications for the industry.
Tools:
SerperDevTool (web search)ScrapeWebsiteToolFileReadTool

🔧 Creating an Agent in Code

from crewai import Agent
from crewai_tools import SerperDevTool

researcher = Agent(
    role='Senior Researcher',
    goal='Uncover cutting-edge developments in AI and data science',
    backstory="""You work at a leading tech think tank.
    Your expertise lies in identifying emerging trends and
    analyzing their implications for the industry.""",
    verbose=True,
    allow_delegation=False,  # Can this agent delegate work?
    tools=[SerperDevTool()]  # Give agent access to tools
)

✨ Agent Attributes Explained

role (string)

The job title or functional role. This shapes how the agent approaches tasks. Examples: "Data Scientist", "Marketing Strategist", "Code Reviewer".

💡 Tip: Use descriptive titles that imply expertise (e.g., "Senior" vs "Junior")

goal (string)

The overarching objective the agent is trying to achieve. Should be specific and measurable. Guides decision-making and prioritization.

💡 Tip: Frame as an outcome (e.g., "Create engaging content" vs "Write stuff")

backstory (string)

Context about the agent's expertise, experience, and personality. Helps the LLM roleplay more authentically. Can be creative and detailed.

💡 Tip: Add personality traits and constraints (e.g., "You value brevity and clarity")

tools (list)

Tools the agent can use to accomplish tasks. Examples: web search, file operations, APIs, calculators. Agents autonomously decide when to use tools.

💡 Tip: Give agents only the tools they need for their role (avoid tool overload)

allow_delegation (boolean)

Whether the agent can ask other agents for help. Set to True for managers, False for specialists who should focus on their own work.

💡 Tip: Enable for complex tasks where collaboration helps, disable for focused execution

🎭 Role Design Best Practices

  • Be specific: "Senior Data Analyst" is better than "Data Person"
  • Add personality: Include traits like "detail-oriented", "creative", "skeptical"
  • Set boundaries: Mention what the agent should/shouldn't do in backstory
  • Match tools to role: Researcher gets search tools, Writer gets file tools
Prev