Skip to main content

Module 2 — Agents, roles and goals

Module 1 chose a crew. This module defines its members. In CrewAI, an agent is a small object with four fields that matter — role, goal, backstory and model — plus a handful of switches that control how loud it is and whether it may talk to its colleagues. Each field pulls a specific lever on the model's behaviour, and getting the four right is the difference between a team and a chat room.

The four fields that matter

The Agent class is intentionally short. Everything else is optional or defaulted.

from crewai import Agent
from langchain_openai import ChatOpenAI

analyst = Agent(
role="Specification Analyst",
goal="Extract every explicit feature, constraint and audience note from the source brief",
backstory=(
"Ten years turning ambiguous product briefs into unambiguous feature lists "
"for engineering teams. You care about what the brief actually says, "
"not about what it should have said."
),
llm=ChatOpenAI(model="gpt-4o-mini", temperature=0),
allow_delegation=False,
verbose=True,
)

Each field has a job. Role names the seat at the table — the model will refer to itself by this string in traces, and other agents will address it by it during delegation. Goal is the success criterion the agent optimises inside every task it receives; keep it single-sentence and testable, or it will drift. Backstory is a short paragraph that shapes tone and priorities without prescribing behaviour — the Analyst above is deliberately grounded ("what the brief actually says") so it does not invent features. llm is the model this agent will use, and it can be different for each agent — a fast small model for the Writer, a stronger one for the Reviewer.

The remaining fields — allow_delegation, verbose, max_iter, memory — are switches we tune module by module. Two are worth naming today: allow_delegation=False prevents the Analyst from asking the Writer for help (module 6 explains why the default is dangerous), and verbose=True prints the agent's internal thoughts to the console, which is the single most useful debugging aid you will have in this course.

Instantiating the four members of the crew

The running project needs four agents. Their fields are chosen so their goals cannot silently collapse into one another.

writer = Agent(
role="Technical Writer",
goal="Turn the feature list into readable prose that follows the house style guide",
backstory=(
"Former documentation lead at a mid-size SaaS. You write for a reader "
"who has ten minutes and one question, never for a reader who wants "
"to admire the prose."
),
llm=ChatOpenAI(model="gpt-4o-mini", temperature=0.3),
allow_delegation=False,
verbose=True,
)

reviewer = Agent(
role="Documentation Reviewer",
goal="Flag every claim not supported by the source brief and every violation of the house style guide",
backstory=(
"You have killed three feature announcements that turned out to be "
"wishful thinking. You would rather block a good draft than approve "
"a wrong one."
),
llm=ChatOpenAI(model="gpt-4o", temperature=0),
allow_delegation=False,
verbose=True,
)

manager = Agent(
role="Editorial Manager",
goal="Arbitrate between the writer and the reviewer, and deliver a single reconciled draft",
backstory="You cut the debate short when a decision is cheap to make.",
llm=ChatOpenAI(model="gpt-4o", temperature=0),
allow_delegation=True,
verbose=True,
)

Three things to notice. First, the four goals are non-overlapping — the Analyst extracts, the Writer drafts, the Reviewer flags, the Manager arbitrates. If two goals overlap, the crew will loop on the shared ground. Second, the Reviewer runs on a stronger model than the Writer; a small model that writes tolerably is a poor judge of what it just wrote. Third, only the Manager has allow_delegation=True — everyone else answers the task they are given.

The model choice is per agent, not per crew

CrewAI accepts any LangChain chat model as llm. That is not a footnote; it is the reason a crew is affordable. A run of the four-agent pipeline on one brief costs roughly $0.04 with the mix above — Writer on gpt-4o-mini, Reviewer and Manager on gpt-4o. Putting gpt-4o on every agent multiplies the bill by three for a barely measurable quality gain, because the Writer's job (rewrite a bulleted list into a paragraph) is not what the large model is worth paying for.

The same code works with a local Ollama server:

from langchain_community.chat_models import ChatOllama
writer = Agent(..., llm=ChatOllama(model="llama3.1:8b", temperature=0.3))

Course 29 covered the trade-off (privacy, latency, throughput) end to end.

The verbose switch is not optional in this course

verbose=True prints, for each step of each agent, the thought, the action, the observation and the final answer. It is noisy in production, and indispensable in development. Every debugging story in module 9 will start with a verbose=True trace — turn it on before the first run, turn it off only when you ship.

A short backstory beats a long one

It is tempting to write a three-paragraph backstory that describes every past project of a fictional persona. That paragraph eats the same context every turn and the model will start echoing it back to you. Two or three sentences that anchor tone and priorities are enough; the goal field carries the actual optimisation target.

Summary

  • An Agent is defined by four fields that matter: role, goal (single sentence, testable), backstory (two-to-three sentences of tone), and llm (chosen per agent, not per crew).
  • The four running-project agents have non-overlapping goals — extract, draft, flag, arbitrate — and only the Manager may delegate.
  • Model per agent is what makes the crew affordable: small on the Writer, stronger on the Reviewer and Manager; the same code swaps to a local Ollama model in one line.
  • Keep verbose=True in development; the printed thoughts, actions and observations are the raw material of every debugging session in module 9.

Next module: writing the tasks these four agents will perform, with expected outputs precise enough that a Reviewer can measure success.