Skip to content
/

What makes an agent work

ConceptsChapter 4 of 143 min read

An agent is not just a language model with instructions. It is a system built from six core elements: role, focus, tools, cooperation, guardrails, and memory. This chapter breaks down each element using the contract review crew you build in this course.


Give it a role#

A role scopes the model's perspective, priorities, and domain expertise. Without one, the model acts as a generic assistant.

Python
risk_analyst = Agent(
    role="Commercial risk analyst",
    goal="Spot the deadlines, costs, and one-sided terms that could hurt {customer}",
    backstory=(
        "You have reviewed hundreds of software agreements from the buyer's "
        "side. You know which clauses cost customers money: automatic "
        "renewals, price increases, short claim windows, and terms the "
        "vendor can change on its own."
    ),
    verbose=True,
)

The role, goal, and backstory parameters prime the model to act as buyer's counsel rather than a neutral party.

Give it one job#

Constrain each task to a single, measurable deliverable. Broad tasks produce unfocused, rambling output.

Python
assess_risks = Task(
    description=(
        "Using the key terms, write a risk memo for {customer}. Pick the five "
        "terms most likely to cost them money or catch them out, and say what "
        "they should do about each one."
    ),
    expected_output=(
        "A Markdown memo of no more than 350 words: a two-sentence summary, then "
        "a numbered list of five risks. Each risk has a section number, why it "
        "matters, and a recommended action."
    ),
    agent=risk_analyst,
)

Separating drafting from verification prevents self-confirmation bias. An agent that checks its own work rarely catches its own mistakes.

Give it tools#

Large language models cannot access local files or network services directly. Tools provide executable functions that an agent can invoke during execution.

Python
read_file = FileReadTool()

reader = Agent(
    role="Contract analyst",
    goal="Pull every commercially important term out of a contract, with its section number",
    backstory=(
        "You read contracts line by line for a procurement team. You quote "
        "the contract rather than paraphrase it, and you always note the "
        "section a term comes from."
    ),
    tools=[read_file],
    verbose=True,
)

Scope tools strictly to the agents that require them. The risk analyst operates purely on extracted text and requires no direct file access.

Let agents work together#

A crew coordinates agents and tasks into an executable pipeline:

Python
crew = Crew(
    agents=[reader, risk_analyst, fact_checker],
    tasks=[extract_terms, assess_risks, fact_check],
    process=Process.sequential,
    verbose=True,
)

Process.sequential executes tasks in order, passing each output to the next task. This provides predictable execution and transparent debugging logs.

Keep it in bounds#

Guardrails enforce output accuracy through step limits, schema constraints, and secondary reviewer agents.

Python
fact_check = Task(
    description=(
        "Check every claim in the risk memo against the contract at {contract_path}. "
        "Fix any number, date, or section reference that does not match the "
        "contract, and remove anything the contract does not say."
    ),
    expected_output="The corrected memo in Markdown, followed by a 'Corrections' section that lists each change you made, or says 'None'.",
    agent=fact_checker,
)

Independent review agents catch discrepancies but can share common blind spots. Pair reviewer agents with deterministic unit tests for reliable verification.

Let it remember#

Enable memory with memory=True when agents need state across runs, such as conversational support workflows. Leave memory disabled for stateless batch pipelines where each document requires a clean evaluation.

How they map to CrewAI#

Building blockCore questionCrewAI implementation
RoleWho performs the work?Agent(role, goal, backstory)
FocusWhat is the exact deliverable?Task(description, expected_output)
ToolsWhat capabilities can it use?Agent(tools=[...])
CooperationHow do agents hand off work?Crew(agents, tasks, process)
GuardrailsWhat keeps execution in bounds?max_iter, task validation, reviewer agents
MemoryWhat state persists across runs?Crew(memory=True)