LearnAI ToolsCareerPractice BuildsPlayContact
Lesson 1125 min read

Multi-Agent Frameworks: CrewAI & AutoGen

Learn CrewAI for role-based agent crews and AutoGen for conversational multi-agent systems, with a working example of each.

Introduction

An "agent" in this context is an LLM given a role, a goal, and access to tools, then allowed to decide its own next step rather than following a fixed script. Multi-agent frameworks coordinate several such agents working together — one researching, one writing, one reviewing — toward a shared objective.

What You Will Learn
  • What distinguishes an "agent" from a single prompt-and-response call.
  • How to define a role-based agent crew with CrewAI.
  • How AutoGen's conversational approach differs from CrewAI's.

A Real-Life Analogy First

Think about writing a short magazine article by yourself versus how an actual newsroom does it: one person researches the facts, hands their notes to a writer, who drafts the piece, which then goes to an editor who checks it before it is published. Each person has a distinct role, a clear responsibility, and passes their work to the next person — nobody tries to do the whole job alone. A multi-agent framework recreates exactly this newsroom structure, except each "person" is an LLM playing one role.

What Is an "Agent" Here?

A single LLM call answers one question and stops. An agent, by contrast, runs in a loop: it can decide to call a tool (search the web, run code, query a database), observe the result, and decide what to do next — repeating until it judges the goal is met. Multi-agent frameworks add a further layer: multiple agents, each with a distinct role, collaborating on one overall task.

CrewAI: Role-Based Agent Crews

Use case: CrewAI organizes agents like a team — each agent gets a role, a goal, and a backstory that shapes its behavior, and a set of tasks are assigned across the crew, which CrewAI then executes in sequence or in parallel.

pip install crewai

CrewAI in Action

from crewai import Agent, Task, Crew
researcher = Agent(
role="Research Analyst",
goal="Find and summarize key facts about a topic",
backstory="An analyst who values accuracy over speed.",
)
writer = Agent(
role="Technical Writer",
goal="Turn research into a clear, short explanation",
backstory="A writer who explains technical topics simply.",
)
research_task = Task(
description="Research what a vector database is and why it's used.",
expected_output="3-4 bullet points of key facts.",
agent=researcher,
)
write_task = Task(
description="Write a 2-sentence beginner-friendly summary using the research.",
expected_output="A 2-sentence explanation.",
agent=writer,
context=[research_task],
)
crew = Crew(agents=[researcher, writer], tasks=[research_task, write_task])
result = crew.kickoff()
print(result)
Terminal Output

Click Run to see what this code prints.

context Chains Tasks Together

Passing context=[research_task] into write_task tells CrewAI to feed the research agent's output into the writer's task automatically — exactly like a researcher physically handing their notes to a writer's desk, rather than the writer having to go dig up the notes themselves.

AutoGen: Conversational Multi-Agent Systems

Use case: AutoGen (from Microsoft Research) frames multi-agent collaboration as a conversation between agents, rather than a fixed role-and-task structure — agents exchange messages, can include a human-in-the-loop participant, and a group chat manager decides which agent speaks next based on the conversation so far.

pip install autogen-agentchat
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_agentchat.conditions import MaxMessageTermination
researcher = AssistantAgent("researcher", model_client=model_client)
writer = AssistantAgent("writer", model_client=model_client)
team = RoundRobinGroupChat(
[researcher, writer],
termination_condition=MaxMessageTermination(4),
)
result = await team.run(task="Explain vector databases in 2 sentences.")
print(result.messages[-1].content)
Terminal Output

Click Run to see what this code prints.

CrewAI vs AutoGen

AspectCrewAIAutoGen
Mental modelA team with roles and assigned tasksA conversation between agents
Best forWell-defined workflows with clear rolesOpen-ended collaboration and human-in-the-loop review
BackingIndependent open-source projectMicrosoft Research
Learning curveGenerally gentler for structured tasksMore flexible, slightly more setup for simple cases

Common Mistakes

Avoid These Mistakes
  • Reaching for a multi-agent framework when a single well-crafted prompt or a simple chain (lesson 9) would solve the problem just as well.
  • Not setting a termination condition or max iteration count, which can let an agent loop indefinitely and rack up API costs.
  • Assuming agent frameworks are deterministic — the same task can take a different path or number of steps between runs.

Best Practices

  • Reach for a multi-agent framework only once a task genuinely needs multiple distinct roles or open-ended tool use — not by default.
  • Always set an explicit termination condition (max messages, max iterations, or a specific completion signal).
  • Log or trace every agent step during development (lesson 16 covers dedicated tooling for this) — multi-agent systems are much harder to debug blind.

Frequently Asked Questions

It depends heavily on the task — well-scoped, bounded workflows (like the research-then-write example above) are more production-ready than fully open-ended autonomous agents.

Most projects pick one to avoid unnecessary complexity, but the underlying concepts (roles, tasks, termination conditions) transfer between them if you need to switch.

Tool calling (covered implicitly in lesson 5) lets one model call a function mid-response. Multi-agent frameworks coordinate multiple separate LLM instances, each with their own role, across many turns.

Yes — when you read about "AI agents" browsing the web, writing and running code, or completing multi-step tasks autonomously, this category of framework (or something conceptually similar, often custom-built) is almost always the underlying mechanism.

Key Takeaways

  • An agent runs in a loop, deciding its own next step, unlike a single prompt-and-response call.
  • CrewAI models collaboration as a team with roles and assigned tasks, like a newsroom.
  • AutoGen models collaboration as a conversation between agents, with flexible turn-taking.
  • Always set a termination condition — agent loops can run indefinitely without one.

Summary

CrewAI and AutoGen both let multiple LLM "agents" collaborate on a task too complex for a single call, using two different mental models — a role-based team versus an open conversation — worth choosing based on how structured your task actually is.

Lesson 11 Completed
  • You understand what makes something an "agent" rather than a single call.
  • You can define a role-based agent crew with CrewAI.
  • You know how AutoGen's approach differs from CrewAI's.
Next Lesson →

Vector Databases: Pinecone & Weaviate