Course Content
AutoGen Essentials
7 sections · 28 lessons
What are AutoGen’s core components—agents, messages, group chat—and how do they interact?
What you need to know
The three packages
| Package | What it holds |
|---|---|
autogen-core | The runtime: agents addressed by AgentId, direct messages and topic publish/subscribe, model context classes, memory protocol |
autogen-agentchat | The high-level API most people use: AssistantAgent, UserProxyAgent, CodeExecutorAgent, teams, termination conditions |
autogen-ext | Plug-ins: model clients (OpenAI, Azure, Anthropic, Ollama), code executors (Docker, Azure), memory stores, MCP tools |
How one turn flows
- Task in —
team.run(task=...)turns the task into aTextMessagefrom the user. - Broadcast — the team sends every new message to all participants, so they share one conversation.
- Pick a speaker — the team's rule chooses who replies: fixed order, an LLM selector, a handoff, or a graph edge.
- Agent responds — the chosen agent calls its model, maybe calls tools (emitting
ToolCallRequestEventandToolCallExecutionEvent), and returns a chat message. - Check termination — the termination condition looks at the new messages; if it fires, the run returns a
TaskResultwith astop_reason.
Messages versus events. Chat messages (TextMessage, HandoffMessage, StructuredMessage) are shared with the other agents. Events (tool call requests and results, thoughts) are emitted for observing the run but are not passed to other agents as conversation.
A travel-planning team in 0.4+
1from autogen_agentchat.agents import AssistantAgent2from autogen_agentchat.base import TaskResult3from autogen_agentchat.conditions import MaxMessageTermination, TextMentionTermination4from autogen_agentchat.teams import RoundRobinGroupChat56planner = AssistantAgent("planner", model_client=client,7 system_message="Draft a day-by-day itinerary within the budget.")8checker = AssistantAgent("checker", model_client=client,9 system_message="Check budget and travel times. Reply APPROVED or list problems.")1011team = RoundRobinGroupChat([planner, checker],12 termination_condition=TextMentionTermination("APPROVED", sources=["checker"])13 | MaxMessageTermination(10))1415async for item in team.run_stream(task="3 days in Jaipur, 2 people, budget Rs 30,000"):16 if isinstance(item, TaskResult):17 print("stopped because:", item.stop_reason)18 else:19 print(item.source, type(item).__name__)The team object owns the turn order and the shared history; the agents only know how to reply. Calling run again continues the same conversation; await team.reset() clears it.
The legacy 0.2 shape
1import autogen # legacy 0.2 API2groupchat = autogen.GroupChat(agents=[planner, checker, user_proxy], messages=[], max_round=12)3manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config)4user_proxy.initiate_chat(manager, message="3 days in Jaipur, budget Rs 30,000")In 0.2 everything was a ConversableAgent, messages were plain dicts (role, content, name), and GroupChatManager was itself an agent that chose the next speaker. It was synchronous and harder to observe.
A real-life example
A travel startup's first prototype used 0.2 GroupChat with five agents: planner, flights, hotels, budget checker and user proxy. Debugging was painful: the transcript was a list of dicts, and they could not see which tool calls happened inside a turn.
After moving to 0.4, they iterated run_stream and logged every item by type. They learned that 40% of their tokens went to the hotels agent re-reading the whole shared history on each turn. Knowing that the team broadcasts everything to everyone, they moved hotel search into a nested team that returns one summary message, and cost per itinerary fell from about 38,000 tokens to about 22,000.
Follow-up questions to expect
- "What is
autogen-corefor, if AgentChat exists?" — Core is the lower-level, event-driven actor runtime; you use it directly when you need custom message types, topic-based pub/sub, or agents in separate processes. AgentChat is built on top of it. - "Does every agent see every message?" — In the built-in group chats, yes: each chat message is broadcast to all participants. That is why group chats grow expensive, and why nested teams help.
- "What does
runreturn?" — ATaskResultwith the list of messages and astop_reasonsaying which termination condition fired.