CrewAI Multi-Agents

Course Content

CrewAI Multi-Agents

9 sections · 53 lessons

What is an Agent in CrewAI, and what responsibilities does it have?


One agent, one task, one loopprompt:persona plus taskmodel: call atool or answerCrewAIruns the toolresult addedas observationfinal answerdecidesevery stepforced atmax_iterOrder, context and output checks live on the Task and Crew, not the agent.
When the step budget runs out the agent still answers, so a weak final answer looks exactly like a strong one until a guardrail checks it.

What you need to know

What an agent is made of

Python
from crewai import Agent, LLManalyst = Agent(    role="Credit Document Analyst",    goal="Extract income and obligations from loan documents accurately",    backstory="You worked 10 years in retail lending. "              "You never state a number without the page it came from.",    tools=[pdf_reader],      # your own PDF-reading tool    llm=LLM(model="openai/gpt-4o-mini", temperature=0.1),    max_iter=10,             # default is 25    allow_delegation=False,  # default is False    verbose=True,)
  • role, goal, backstory — the persona; CrewAI puts them into the system prompt.
  • tools — what it can actually do in the world.
  • llm — which model runs its loop; different agents can use different models.
  • max_iter, max_execution_time, max_rpm — limits on loop steps, wall-clock seconds and requests per minute.

What happens when an agent runs a task

  1. CrewAI builds a prompt from the agent's persona, the task's description and expected_output, any context from earlier tasks, and the tool descriptions.
  2. The model either calls a tool or gives a final answer.
  3. Tool results are added to the conversation and the loop continues.
  4. If it reaches max_iter, CrewAI makes one last call asking for its best final answer.

Responsibilities: agent vs the rest

Belongs to the agentBelongs elsewhere
Understanding the instructionThe order of work (Crew, Process, Flow)
Choosing and calling toolsWhich outputs it sees (Task.context)
Staying inside its roleChecking the output (output_pydantic, guardrails)
Producing the deliverableRetries after a failed check (the task)

An agent can also run without a crew: analyst.kickoff("Summarise this payslip: ...") runs one standalone loop, which is useful for chat-style features or inside a Flow step.

A real-life example

A loan-document review crew at an NBFC has three agents:

  • Document Analyst — tools: a PDF reader and an OCR tool. Job: pull out monthly salary, employer, existing EMIs and bank balance, with page numbers.
  • Policy Checker — no tools, the lending policy loaded as knowledge. Job: compare the numbers with policy (for example, total EMIs must stay under 50% of income).
  • Summary Writer — no tools. Job: a one-page note for the credit officer.

In an early version the analyst's backstory said "then check the policy and write a summary". The analyst kept doing all three jobs badly. Moving those steps out of the backstory and into separate tasks made the analyst's output clean: 12 fields with page references, every time. The lesson: an agent describes who, a task describes what to do now.

Follow-up questions to expect

  • "Can one agent run several tasks?" — Yes. An agent is reusable; for example, a researcher can own both the company research task and the competitor research task.
  • "What happens when max_iter runs out?" — The agent is asked once more for its best final answer, so you get an answer, possibly a weak one. Guardrails should catch it.
  • "Can agents use different models?" — Yes, and you should: a strong model for reasoning or managing, a cheaper one for extraction or formatting.