ap.Abhishek Patel

Search

Search notes, essays, projects, the library and the AI course. Use arrow keys to choose and Enter to open.

Lesson 8 of 10 30 min

AutoGen and CrewAI

Build the same content team in AutoGen's group chat and CrewAI's role-and-task crew, map both to patterns you know, and choose a framework with its costs in view.

Words in this lessonAutoGen · CrewAI · Agent framework · Group chat (multi-agent) · Termination condition · Multi-agent system
AutoGen
An open-source multi-agent framework from Microsoft built around agents that talk to each other in conversations. Like a meeting room where specialists take turns speaking until someone says the plan is agreed.
CrewAI
An open-source Python framework where agents with roles work through a list of tasks as a crew. Like a film crew with job titles and a call sheet listing who does what, in what order.
Agent framework
A library that packages common agent patterns, such as loops, tools and teams, so you write less code. Like an event company: faster than organising everything yourself, but you eat from their menu.
Group chat (multi-agent)
A multi-agent setup where agents take turns adding messages to one shared conversation. Like a committee meeting that only ends when someone calls the vote, or the clock runs out.
Termination condition
A rule that tells a multi-agent conversation or loop when to stop. Like a referee’s whistle plus the clock: the game ends on whichever comes first.
Multi-agent system
A system where several agents, each with its own instructions, tools and context, work together on a task. Like a newsroom where an editor assigns reporters to different beats and writes the story from their memos.
On this page
  1. Two event companies
  2. Following one product through both frameworks
  3. Through CrewAI: a crew of three, in sequence
  4. Through AutoGen: a writer and an editor taking turns
  5. Opening the hood: AutoGen
  6. Opening the hood: CrewAI
  7. The code
  8. AutoGen: writer and editor, round-robin
  9. CrewAI: researcher, writer, editor
  10. Choosing: hand-built, AutoGen, CrewAI or a graph
  11. Where it breaks
  12. Try it yourself
  13. Common mistakes
  14. Recap
  15. Go deeper

The spring menu had nine new products, from a mango cheesecake to a jaggery-and-sesame cookie, and each needed a website description by Friday. Crumb’s content process had three steps, borrowed from how Meera’s niece ran a magazine: someone gathered the facts from the recipe archive, someone wrote, and someone edited. Arjun wanted to automate all three. He had built a team by hand the week before. This time, he decided, he would use a real framework, like grown-up engineers.

He found a popular tutorial for AutoGen, Microsoft’s multi-agent framework, ran uv add autogen-agentchat, and pasted in the tutorial code. The first line failed:

ModuleNotFoundError: No module named 'autogen'

The tutorial was from 2023. AutoGen had since been rewritten from the ground up, and the package names, the classes and the way agents talked had all changed. Twenty minutes later, he had it half-working and discovered something worse in the project’s README: AutoGen was now in maintenance mode, with Microsoft pointing new users to a successor, the Microsoft Agent Framework.

Meera, passing by, saw the error on his screen. “Is this the AI we’re paying for?”

“It’s free. It’s open source.”

“Nothing is free,” she said. “What does it cost us when it changes again?”

Important

The idea in one sentence: AutoGen and CrewAI are frameworks that package the multi-agent patterns you have already built by hand, AutoGen around agents conversing in a group chat and CrewAI around roles and tasks in a crew, and choosing one is a trade between less code today and less control, more hidden prompts and more churn tomorrow.

Two event companies

Priya pulled a chair over. “Imagine Crumb is organising its tenth-anniversary party, and two event companies pitch for it.”

“The first one says: we’ll put your planners in a meeting room. The caterer, the decorator and the DJ will talk it through, taking turns, until they agree on a plan. You set the rules for who speaks and when the meeting ends. That’s AutoGen. It is built around conversation: agents are participants in a chat, and the chat is the program.”

“The second one says: we’ll give you a crew with job titles. A caterer with a clear goal, a decorator with a clear goal. And a call sheet: task one, task two, task three, each with an owner and a definition of done. That’s CrewAI. It is built around roles and tasks.”

“And what I built last week?”

“You cooked the party food yourself. You know exactly what’s in it, and it took you a day. The event companies are faster to start, but you eat what’s on their menu, and when they change their menu, you change too.” She tapped the error on the screen. “Which, as you’ve noticed, they do.”

Where the analogy breaks: a real event company has a contract and a phone number. An open-source framework has neither. If it is abandoned or rewritten, nobody owes you anything. That’s not a reason to avoid frameworks; it’s a reason to choose with your eyes open, and to keep your own logic (tools, prompts, data access) in plain code that doesn’t depend on the framework.

Note

Pause and think. Map each framework onto a pattern you already know from Workflow patterns and Multi-agent systems. A writer and an editor taking turns until the editor says “approve”: which pattern? A crew where task 2 uses task 1’s output and task 3 uses task 2’s: which pattern?

Show the answer

The writer-editor turn-taking is the evaluator-optimizer pattern, expressed as a two-agent group chat. The crew with tasks feeding each other in order is prompt chaining, where each step happens to be done by an agent with a role. CrewAI’s hierarchical mode, where a manager agent assigns tasks, is orchestrator-workers. Frameworks don’t invent new patterns; they give the old ones new names and a convenient API. Recognising the pattern underneath is how you stay in control.

Following one product through both frameworks

Priya suggested they run the same job through both frameworks and compare the traces: the description for the Spring Mango Cheesecake. The input notes from the recipe archive:

Alphonso mango from Ratnagiri, baked cheesecake, digestive biscuit base, contains egg,
dairy and gluten. 6-inch serves 6. ₹1,150. Available 1 March to 31 May.

Through CrewAI: a crew of three, in sequence

The crew has three agents (researcher, writer, editor) and three tasks, run in order.

Task 1, researcher. Expected output: “a bullet list of 5–8 verified facts”. Output:

- Made with Alphonso mangoes from Ratnagiri
- Baked cheesecake on a digestive biscuit base
- Contains egg, dairy and gluten
- 6-inch cake serves 6; ₹1,150
- Seasonal: 1 March to 31 May

Task 2, writer. Receives task 1’s output as context. Output (74 words): “Spring tastes like Ratnagiri. Our new Mango Cheesecake layers silky baked cheesecake over a crisp digestive base, crowned with real Alphonso mango… the best mangoes in the world…”

Task 3, editor. Receives both previous outputs. It strikes “the best mangoes in the world” as an unverifiable claim, adds the allergen line, and returns the final 71-word text.

Three agents, three tasks, four model calls (the editor used one extra to double-check the facts), about 9,500 input tokens and 1,400 output tokens. On Claude Opus 5.5 at 20 per million, that’s about $0.07, or ₹6. Notice the input tokens: nearly 2,400 per call for what is a short job. CrewAI wraps each task in its own instructions (role, goal, backstory, expected output, formatting rules), and you pay for that wrapping on every call.

Through AutoGen: a writer and an editor taking turns

The AutoGen version is a two-agent group chat (a shared conversation where agents take turns), run round-robin, ending when the editor writes “APPROVE” or after eight messages.

user:   Write the website description for the Spring Mango Cheesecake. Notes: ...
writer: Spring tastes like Ratnagiri... the best mangoes in the world...      (82 words)
editor: Two fixes: cut to under 80 words; remove 'best in the world' (unverifiable);
        add allergens (egg, dairy, gluten).
writer: Spring tastes like Ratnagiri. Our new Mango Cheesecake... Contains egg,
        dairy and gluten.                                                      (71 words)
editor: APPROVE

Five messages, four model calls. Each agent reads the entire chat history on its turn, so input tokens grow with every message, the same ticket-rail effect from Your first agent. For this short chat that’s fine. For a twelve-agent group chat running forty turns, it is how bills explode.

Both traces produced nearly identical text. The difference is in what you wrote and what you can see. The crew needed role and task definitions; the chat needed a termination rule. The crew’s prompts were partly written by the framework; the chat’s were mostly yours.

Opening the hood: AutoGen

What it is. AutoGen is an open-source framework from Microsoft Research, released in 2023, that made “agents talking to each other” a popular idea. The current version is organised in layers: a low-level core for message passing between agents, and a high-level AgentChat layer that most people use.

The key pieces of AgentChat:

  • AssistantAgent: an agent backed by a model, with a name, a system message and optional tools.
  • A model client: the object that talks to a model provider, such as OpenAIChatCompletionClient.
  • Teams: ways to run several agents together. RoundRobinGroupChat gives each agent a turn in order. SelectorGroupChat uses a model to choose who speaks next.
  • Termination conditions: rules for ending the conversation, like TextMentionTermination("APPROVE") or MaxMessageTermination(8). Combine them with | (“stop when either happens”).

The honest status. At the time of writing, AutoGen’s own README says it is in maintenance mode (bug and security fixes only) and directs new users to the Microsoft Agent Framework, which provides migration guides from both AutoGen and Semantic Kernel. A community fork called AG2 also continues the older AutoGen style. So learn AutoGen for its ideas, which you’ll meet in many frameworks, and check the project’s status before starting anything new on it.

Opening the hood: CrewAI

What it is. CrewAI is an open-source Python framework built around the metaphor of a crew: agents with roles working through a list of tasks. It is independent of LangChain and has grown a large following because its vocabulary is easy for non-engineers to read.

The key pieces:

  • Agent: a role (“Menu researcher”), a goal, a backstory (a short persona that shapes behaviour), optional tools, and an llm.
  • Task: a description, an expected_output (the definition of done), the agent who owns it, and optionally context (other tasks whose output it should read).
  • Crew: the agents, the tasks and a process. Process.sequential runs tasks in order; Process.hierarchical adds a manager agent that delegates.
  • kickoff(inputs={...}): runs the crew, filling {placeholders} in descriptions with your inputs.
  • Flows: a separate feature for event-driven, deterministic orchestration around crews, for when you want code, not agents, to decide what happens next.

Note

Pause and think. CrewAI adds a “backstory” to every agent. That backstory is sent to the model on every call. What are the costs and benefits of a 150-word backstory?

Show the answer

Benefit: it can steer tone and focus (“You’ve edited food writing for fifteen years and hate exaggeration”). Costs: about 200 tokens on every call that agent makes, which adds up across many tasks and runs; and it is one more piece of hidden prompt that can conflict with your task description. A backstory should earn its place like any prompt text: test with and without it, and keep the version that measurably helps.

The code

AutoGen: writer and editor, round-robin

uv add autogen-agentchat "autogen-ext[openai]" python-dotenv
# autogen_copy.py
import asyncio
import os
from dotenv import load_dotenv
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_agentchat.conditions import TextMentionTermination, MaxMessageTermination
from autogen_ext.models.openai import OpenAIChatCompletionClient

load_dotenv()                                    # OPENAI_API_KEY
MODEL = os.getenv("OPENAI_MODEL", "gpt-5-mini")  # model names change; see the provider's models page

NOTES = ("Alphonso mango from Ratnagiri, baked cheesecake, digestive biscuit base, contains egg, "
         "dairy and gluten. 6-inch serves 6. ₹1,150. Available 1 March to 31 May.")

async def main() -> None:
    model_client = OpenAIChatCompletionClient(model=MODEL)
    writer = AssistantAgent(
        "writer", model_client=model_client,
        system_message="You write warm website copy for Crumb & Co., a Pune bakery. Under 80 words. "
                       "Use only facts from the notes. When the editor gives fixes, apply all of them.")
    editor = AssistantAgent(
        "editor", model_client=model_client,
        system_message="You edit bakery copy. Check: under 80 words, only facts from the notes, "
                       "allergens listed, no unverifiable claims. List specific fixes, or reply APPROVE.")
    stop = TextMentionTermination("APPROVE") | MaxMessageTermination(8)   # always add a hard cap
    team = RoundRobinGroupChat([writer, editor], termination_condition=stop)

    result = await team.run(task=f"Write the description for the Spring Mango Cheesecake. Notes: {NOTES}")
    for message in result.messages:
        print(f"{message.source}: {str(message.content)[:150]}\n")
    await model_client.close()

asyncio.run(main())

You should see the user task, a draft, the editor’s fixes, a revision and APPROVE, much like the trace above. This example uses OpenAI’s client because it’s the one AutoGen documents most fully; extension packages exist for other providers. If AutoGen complains that it doesn’t recognise a model name, pass a model_info dictionary as its docs describe.

Two lines to notice. MaxMessageTermination(8) is your brake: without it, a writer and editor who never agree will chat forever. And asyncio.run(main()): AgentChat is built on Python’s async features (a way of running many waiting tasks without blocking), so everything happens inside an async function.

CrewAI: researcher, writer, editor

uv add crewai python-dotenv
# crew_copy.py
from dotenv import load_dotenv
from crewai import Agent, Task, Crew, Process, LLM

load_dotenv()                                          # ANTHROPIC_API_KEY
llm = LLM(model="anthropic/claude-opus-5-5")

researcher = Agent(
    role="Menu researcher",
    goal="Extract accurate, checkable facts about {product}",
    backstory="You work from Crumb's recipe archive and never add facts that aren't in the notes.",
    llm=llm,
)
writer = Agent(
    role="Copywriter",
    goal="Write warm, honest website copy for {product}",
    backstory="You write for a family bakery in Pune. Short sentences, no hype.",
    llm=llm,
)
editor = Agent(
    role="Editor",
    goal="Make sure the copy is accurate, under 80 words and lists allergens",
    backstory="You remove any claim that can't be checked.",
    llm=llm,
)

research = Task(
    description="From these notes, list the facts a customer needs about {product}: {notes}",
    expected_output="A bullet list of 5-8 facts, each traceable to the notes.",
    agent=researcher,
)
write = Task(
    description="Write a website description for {product} using only the researcher's facts.",
    expected_output="One paragraph under 80 words, ending with the allergens.",
    agent=writer,
    context=[research],
)
edit = Task(
    description="Edit the description. Remove unverifiable claims; check allergens and length.",
    expected_output="The final description only.",
    agent=editor,
    context=[research, write],
)

crew = Crew(agents=[researcher, writer, editor], tasks=[research, write, edit],
            process=Process.sequential, verbose=True)
result = crew.kickoff(inputs={
    "product": "Spring Mango Cheesecake",
    "notes": "Alphonso mango from Ratnagiri, baked cheesecake, digestive biscuit base, contains egg, "
             "dairy and gluten. 6-inch serves 6. ₹1,150. Available 1 March to 31 May.",
})
print(result.raw)

With verbose=True, CrewAI prints each agent’s work as it goes. You should see the fact list, the draft and the final description. {product} and {notes} are filled from kickoff(inputs=...), so the same crew can run for all nine spring products in a loop.

Library APIs change quickly. If a name has moved, check the docs linked below.

Choosing: hand-built, AutoGen, CrewAI or a graph

Hand-built (last lesson) AutoGen (AgentChat) CrewAI LangGraph (Module 14)
Core idea Your own loop and tools Agents converse in teams Roles and tasks in a crew Explicit graph of steps and state
Lines for this job ~80 ~30 ~50 ~60
Prompt visibility All yours Mostly yours Partly framework-written Mostly yours
Control over flow Total Turn-taking rules Process type, Flows Total, as a graph
Status (at the time of writing) Yours to maintain Maintenance mode; see Microsoft Agent Framework Active Active
Best for Learning, unusual flows Debate and review chats Readable role-based pipelines Production agents you must debug

Priya’s rule of thumb: frameworks are great for getting a prototype in front of people this week. For something that will run every day for years, prefer the option where you can see every prompt, every step and every piece of state, and where your tools and data access live in plain Python you could move to another framework in a day.

Where it breaks

Arjun ran the CrewAI version for all nine products. What he learned:

  • Hidden prompts are hard to debug. One description kept coming out in a strangely formal tone. The cause was the combination of the editor’s backstory and CrewAI’s own task wrapper, which he couldn’t see until he turned on verbose logging and read the full prompts. When an agent behaves oddly in a framework, your first job is to find out what was actually sent to the model.
  • Overhead adds up. About 2,400 input tokens per call, much of it framework text. For nine products, trivial. For ninety thousand support emails a month, significant.
  • Termination is fragile. In an AutoGen test, the editor wrote “I’d approve this if…” and the TextMentionTermination("APPROVE") check, which matches the text, ended the chat early on a draft that still needed work. A stricter phrase (“FINAL: APPROVED”) and the message cap fixed it.
  • Hierarchical mode wanders. CrewAI’s manager agent sometimes re-delegated the same task twice. For a fixed three-step job, sequential was cheaper and more predictable.
  • Version churn is real. The AutoGen tutorial broke because the framework was rewritten. Pin your versions in pyproject.toml, and keep your business logic outside the framework.

Caution

Some multi-agent frameworks include agents that can execute code the model writes. Never run those executors directly on your laptop or server with real credentials. Use the framework’s Docker-based executor or another sandbox, exactly as you learned with smolagents.

Try it yourself

  1. Run both scripts on the mango cheesecake. Compare the final texts and count model calls (verbose output for CrewAI, result.messages for AutoGen).
  2. In the AutoGen version, change the editor’s system message so it is very picky (“find at least two problems with every draft”). What happens?
  3. In the CrewAI version, change Process.sequential to Process.hierarchical and add manager_llm=llm to the Crew. Count the calls again.
Show the expected result
  1. Both should produce a similar 60–80 word description that lists allergens and avoids “best in the world”. Expect four or five model calls each.
  2. The picky editor never approves, so the chat runs until MaxMessageTermination(8) stops it. This is exactly why the hard cap exists, and a reminder that an evaluator with impossible criteria makes an evaluator-optimizer loop useless.
  3. Hierarchical mode adds the manager’s planning and delegation calls, often doubling the total. For a fixed, three-step pipeline, it buys you nothing. It earns its cost only when the tasks needed really vary from input to input.

Common mistakes

  • Copying old tutorials. Check the date and the framework’s current docs first. Agent frameworks change faster than almost any other software you’ll use.
  • Letting the framework own your tools. Write tools and data access as plain Python functions, then wrap them for the framework. Switching frameworks should be an afternoon, not a rewrite.
  • No message or turn caps. Group chats and manager agents need hard limits in code.
  • Never reading the real prompts. Turn on verbose logging or tracing and read what is actually sent at least once.
  • Picking a framework for its demo. Choose based on how you’ll debug it at 2 am when it misbehaves.

Recap

  • AutoGen treats a multi-agent system as a conversation: assistant agents in teams such as RoundRobinGroupChat, ended by termination conditions. It is now in maintenance mode, with Microsoft pointing new work to the Microsoft Agent Framework.
  • CrewAI treats it as a crew: agents with roles, goals and backstories working through tasks with expected outputs, run sequentially or under a manager.
  • Both package patterns you already know: group chat ≈ evaluator-optimizer, sequential crew ≈ prompt chaining, hierarchical crew ≈ orchestrator-workers.
  • Frameworks trade less code for hidden prompts, overhead and churn. Pin versions and keep tools in plain Python.
  • Always cap turns, read the real prompts at least once, and sandbox any code execution.

Arjun answered Meera’s question on Friday, with nine product descriptions approved. “The frameworks are free to use, but we pay in three ways: tokens for their extra instructions, time when they change, and time when something goes wrong inside them that we can’t see. For the spring menu, CrewAI was quick and fine. For the support agent that runs all day, we keep our own code.”

“So you built it twice to learn which one to build,” Meera said. “Fine. Now the delivery partner says they have an AI agent too, and they want ours to talk to theirs. Is that a framework thing as well?”

“No,” said Priya. “That’s a protocol. Two agents from two different companies, built on different frameworks, that have never met. They need a common language, and there’s one being built for exactly that.”

Go deeper

Check your understanding

3 quick questions
1. Which description matches CrewAI?
2. A writer and editor in an AutoGen RoundRobinGroupChat never agree. What stops the run?
3. What did Arjun discover about AutoGen's status that matters when choosing it for a new project?