Defining Agents
Agents are the building blocks of every CrewAI system. Each agent is an autonomous unit designed to perform a specific function — like hiring a specialist for your team. In this lesson, you'll learn how to define agents with the right roles, goals, backstories, and tools. For the full API reference, see the Agent docs.
Anatomy of an Agent
Every CrewAI agent is defined with these core attributes:
| Attribute | Purpose | Example |
|---|---|---|
role | Job title — what the agent does | "Senior Data Analyst" |
goal | What the agent is trying to achieve | "Produce accurate data insights" |
backstory | Context that shapes the agent's behavior | "10 years of experience in fintech analytics" |
tools | External capabilities the agent can use | [SerperDevTool(), ScrapeWebsiteTool()] |
llm | The language model powering the agent | "gpt-4o" or "claude-sonnet-4-6" |
verbose | Whether to print the agent's reasoning | True or False |
Your First Agent
Here's a minimal agent definition:
from crewai import Agent
writer = Agent(
role="Content Writer",
goal="Write clear, engaging blog posts on technology topics",
backstory="You are a seasoned tech blogger who simplifies complex "
"topics for a general audience. You prioritize accuracy "
"and readability."
)
The role, goal, and backstory work together to shape how the LLM reasons. Think of them as a detailed system prompt, broken into structured pieces.
How Role, Goal, and Backstory Work Together
These three fields might seem redundant, but each serves a distinct purpose:
Role sets the agent's identity. It tells the LLM what it is. An agent with role="Data Scientist" will approach problems differently than one with role="Marketing Copywriter".
Goal defines success. It tells the LLM why it's working. An agent with goal="Maximize click-through rate" will make different choices than one with goal="Ensure factual accuracy".
Backstory provides context and constraints. It tells the LLM how it should work based on its experience and personality.
# These two agents will produce very different outputs for the same task:
conservative_analyst = Agent(
role="Financial Analyst",
goal="Identify safe, long-term investment opportunities",
backstory="You are a risk-averse analyst with 20 years at a pension fund. "
"You never recommend speculative assets and always prioritize "
"capital preservation."
)
aggressive_analyst = Agent(
role="Financial Analyst",
goal="Find high-growth investment opportunities",
backstory="You are a growth-focused analyst at a venture fund. "
"You look for disruptive technologies and are comfortable "
"with higher risk for higher potential returns."
)
Adding Tools to Agents
Tools give agents the ability to interact with the outside world — search the web, read files, scrape websites, and more.
from crewai import Agent
from crewai_tools import SerperDevTool, ScrapeWebsiteTool
researcher = Agent(
role="Research Analyst",
goal="Find comprehensive, up-to-date information on given topics",
backstory="You are meticulous about fact-checking and always "
"cross-reference multiple sources.",
tools=[SerperDevTool(), ScrapeWebsiteTool()],
verbose=True
)
Common Built-in Tools
CrewAI provides several ready-to-use tools via the crewai-tools package:
| Tool | What It Does |
|---|---|
SerperDevTool | Google search via Serper API |
ScrapeWebsiteTool | Extract content from web pages |
FileReadTool | Read local files |
DirectoryReadTool | List directory contents |
CodeInterpreterTool | Execute Python code |
PDFSearchTool | Search within PDF documents |
CSVSearchTool | Search within CSV files |
Tools are assigned per-agent, so a researcher can have web search while a writer has only file access — just like real team permissions.
Configuring the LLM
By default, CrewAI uses OpenAI's GPT-4. You can change the model per agent:
researcher = Agent(
role="Research Analyst",
goal="Find accurate information",
backstory="Experienced researcher.",
llm="gpt-4o"
)
writer = Agent(
role="Content Writer",
goal="Write engaging content",
backstory="Skilled technical writer.",
llm="claude-sonnet-4-6"
)
You can even use different models for different agents in the same crew — a powerful technique for balancing cost and quality.
Allowing Delegation
Agents can delegate work to other agents in the crew. This is controlled by the allow_delegation parameter:
manager = Agent(
role="Project Manager",
goal="Ensure all deliverables meet quality standards",
backstory="You oversee the team and delegate tasks to specialists.",
allow_delegation=True # Can ask other agents for help
)
specialist = Agent(
role="Data Analyst",
goal="Produce accurate statistical analysis",
backstory="You focus purely on data crunching.",
allow_delegation=False # Does its own work only
)
When delegation is enabled, the agent can autonomously decide to ask another agent in the crew to handle part of its work.
Agent Design Best Practices
Be specific with roles. "Senior SEO Content Strategist" produces better results than "Writer."
Make goals measurable. "Write a 500-word blog post with 3 actionable tips" is better than "Write something good."
Use backstory for constraints. If you need a specific writing style, tone, or approach, put it in the backstory rather than cramming it into the goal.
Match tools to roles. Don't give every agent every tool. A writer doesn't need web search if the researcher already provides the information.
Keep agents focused. Each agent should do one thing well. If an agent's description covers three different jobs, split it into three agents.
Key Takeaways
- Agents are defined with a role (identity), goal (success criteria), and backstory (context and constraints)
- These three fields work together to shape the LLM's reasoning, like a structured system prompt
- Tools give agents real-world capabilities like web search, file access, and code execution
- You can use different LLMs for different agents to balance cost and quality
- Delegation lets agents hand off work to other specialists in the crew
- Good agent design follows real-world team principles: clear roles, focused responsibilities, appropriate permissions

