AutoGen Essentials

Course Content

AutoGen Essentials

7 sections · 28 lessons

What are AutoGen’s core components—agents, messages, group chat—and how do they interact?


One turn inside an AutoGen 0.4+ teamteam.run(task)creates aTextMessageTeam broadcastsit to every agentTeam rule picksthe next speakerAgent callsmodel andtools, repliesTerminationconditionchecks the messageIf nothing fires, the loop returns to the broadcast step.
The team owns turn order and shared history; the agents only know how to reply, which is why every broadcast message costs tokens for everyone.

What you need to know

The three packages

PackageWhat it holds
autogen-coreThe runtime: agents addressed by AgentId, direct messages and topic publish/subscribe, model context classes, memory protocol
autogen-agentchatThe high-level API most people use: AssistantAgent, UserProxyAgent, CodeExecutorAgent, teams, termination conditions
autogen-extPlug-ins: model clients (OpenAI, Azure, Anthropic, Ollama), code executors (Docker, Azure), memory stores, MCP tools

How one turn flows

  1. Task in — team.run(task=...) turns the task into a TextMessage from the user.
  2. Broadcast — the team sends every new message to all participants, so they share one conversation.
  3. Pick a speaker — the team's rule chooses who replies: fixed order, an LLM selector, a handoff, or a graph edge.
  4. Agent responds — the chosen agent calls its model, maybe calls tools (emitting ToolCallRequestEvent and ToolCallExecutionEvent), and returns a chat message.
  5. Check termination — the termination condition looks at the new messages; if it fires, the run returns a TaskResult with a stop_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+

Python
from autogen_agentchat.agents import AssistantAgentfrom autogen_agentchat.base import TaskResultfrom autogen_agentchat.conditions import MaxMessageTermination, TextMentionTerminationfrom autogen_agentchat.teams import RoundRobinGroupChatplanner = AssistantAgent("planner", model_client=client,    system_message="Draft a day-by-day itinerary within the budget.")checker = AssistantAgent("checker", model_client=client,    system_message="Check budget and travel times. Reply APPROVED or list problems.")team = RoundRobinGroupChat([planner, checker],    termination_condition=TextMentionTermination("APPROVED", sources=["checker"])                          | MaxMessageTermination(10))async for item in team.run_stream(task="3 days in Jaipur, 2 people, budget Rs 30,000"):    if isinstance(item, TaskResult):        print("stopped because:", item.stop_reason)    else:        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

Python
import autogen  # legacy 0.2 APIgroupchat = autogen.GroupChat(agents=[planner, checker, user_proxy], messages=[], max_round=12)manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config)user_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-core for, 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 run return?" — A TaskResult with the list of messages and a stop_reason saying which termination condition fired.