TAI BUI
Back to curriculum
BuildPython

Group Chat and Speaker Selection

AutoGen GroupChat and AG2 GroupChat share one conversation across N agents, and a selector function (LLM, round-robin, or custom) picks who speaks next. Agents do not know their role in a static graph. They react to the shared pool, which makes this the archetype of emergent multi-agent conversation. AutoGen v0.2's GroupChat semantics were preserved in the AG2 fork, and v0.4 rewrote it as an event-driven actor model. Microsoft put AutoGen into maintenance mode in February 2026 and merged it with Semantic Kernel into Microsoft Agent Framework (RC February 2026). The GroupChat primitive survives in both AG2 and Microsoft Agent Framework, so learn it once and use it in either.

TIME: ~60 minutesPREREQUISITES: Phase 16 · 04 (Primitive Model)

Learning Objectives

  • Name the three speaker-selector flavors (round-robin, LLM-selected, custom) and pick one for a given task
  • Explain what GroupChat and GroupChatManager each own, and how the manager loops over turns
  • Choose termination rules (max rounds, TERMINATE token, goal-reached check) for a chat
  • Spot the failure modes (hot speakers, sycophancy cascades, context bloat) and the Ship It fixes
  • Run the stdlib demo and read the selector trace under round-robin vs context-aware selection

Problem

Static graphs (LangGraph) work well when the workflow is known. Real conversations are not static. Sometimes the coder asks the reviewer, sometimes the researcher, sometimes the writer. Hardcoding every possible handoff gives you an edge explosion. What you want is agents reacting to a shared pool, with some function deciding who talks next.

That is what AutoGen GroupChat does.

Warm-up0/3
1. Which of the four primitives is the only one that is not stateless?Warm-up
Four boxes labelled Agent, Handoff, Shared State and Orchestrator, above a dashed box asking which one keeps data between turns.
Recall of the four primitives, not specific to this lesson.
2. Mechanically, what is a handoff in the primitive model?Warm-up
Agent A, an arrow to a dashed question-mark box, then an arrow to Agent B.
Recall of a handoff from the prior lesson.
3. A program calls a model in a loop and might never reach its goal. What is the simplest guard against it running forever?Warm-up
A call-model box leads to a check-goal box, which loops back to call-model, with a note reading repeat forever and a dashed guard box off to the side.
Typed schematic of an unbounded agent loop.
Check: Problem0/1
1. What problem does GroupChat solve relative to static graphs like LangGraph?Explain
Five agents connected by a hardcoded edge between every pair, beside a pool-plus-selector box and a dashed box asking which fits a changing topic.

Concept

The shape

              ┌─── shared pool ────┐
              │   m1  m2  m3  ...  │
              └─────────┬──────────┘
                        │ (everyone reads all)
      ┌───────┬─────────┼─────────┬───────┐
      ▼       ▼         ▼         ▼       ▼
    Agent A  Agent B  Agent C  Agent D  Selector
                                           │
                                           ▼
                                  "next speaker = C"

Every agent sees every message. A selector function is invoked at each turn to pick who speaks next.

The three selector flavors

Round-robin. Fixed cycle. Deterministic. Scales linearly in N but ignores context: a coder gets the turn even when the topic is legal review.

LLM-selected. A call to an LLM that reads the recent pool and returns the best next speaker. Context-aware but slow: every turn adds an LLM call. AutoGen's default.

Custom. A Python function with whatever logic you want. Typical: LLM-selected with fallback rules (e.g., "always give the verifier the turn after the coder").

The ConversableAgent API

agent = ConversableAgent(
    name="coder",
    system_message="You write Python.",
    llm_config={...},
)
chat = GroupChat(agents=[coder, reviewer, tester], messages=[])
manager = GroupChatManager(groupchat=chat, llm_config={...})

GroupChatManager holds the selector. When an agent completes a turn, the manager calls the selector, which returns the next agent. Loop continues until a termination condition.

Termination

Three common patterns:

  • Max rounds. Hard cap on total turns.
  • "TERMINATE" token. Agents can emit a sentinel message; the manager stops when one appears.
  • Goal-reached check. A lightweight verifier runs each turn and stops the chat when done.

The AutoGen → AG2 split and the Microsoft Agent Framework merge

In early 2025, Microsoft began a major rewrite of AutoGen (v0.4) around an event-driven actor model. The community forked AutoGen v0.2's GroupChat semantics as AG2, preserving the API that early adopters had integrated.

In February 2026, Microsoft announced AutoGen would go to maintenance mode, with the event-driven actor model merging into Microsoft Agent Framework (RC February 2026, now merged with Semantic Kernel). The GroupChat concept survives in both tracks; the implementation details differ. AG2 is the preferred upstream for v0.2-compatible code.

When GroupChat fits

  • Emergent conversations. You do not want to pre-wire every possible next-speaker.
  • Role-mixing tasks. Coder asks researcher, researcher asks archivist, archivist asks coder back. Flow is not a DAG.
  • Exploratory problem-solving. Think "brainstorm meeting," not "assembly line."

When it fails

  • Strict determinism. The LLM selector can be inconsistent. Same prompt, different runs, different next speakers.
  • Sycophancy cascades. Agents defer to whoever spoke most confidently. Counter-prompt explicitly.
  • Context bloat. Every agent reads every message; after 10 turns the context is huge. Use projections (Lesson 15) to scope views.
  • Hot speakers. One agent dominates the conversation because the selector favors its specialties. Introduce speaker balance as a selector feature.

Group chat vs supervisor

Same primitives, different defaults:

  • Supervisor: one agent plans and others execute. Selector is "ask the planner what to do."
  • Group chat: all agents are peers; selector is a function over the shared pool.

Both use the four primitives from Lesson 04. Group chat defaults to LLM-selected orchestration and full-pool shared state.

Check: Concept0/24
1. Which selector flavor is AutoGen's default?Define
Three boxes named round-robin, LLM-selected and custom, with an arrow down to a dashed box asking which is AutoGen's default.
2. Which component holds the selector and loops over turns until a termination condition?Define
A GroupChat box holding agents and messages leads to a dashed box asking what owns the selector and loops turns, then to a stop box.
3. What is the custom speaker-selector flavor?Define
A recent-pool box leads to a highlighted custom-selector box, then to a dashed box asking what logic runs inside.
4. Which set lists the three common termination patterns for a GroupChat?Define
Three dashed boxes labelled stop idea 1, 2 and 3, under a note that a running chat needs something to end it.
5. Which failure mode is one agent dominating because the selector favors its specialties?Define
A bar chart of turn counts across four agents, one bar much taller than the rest, above a dashed box asking to name the failure.
Illustrative turn counts.
6. What is a GroupChat in AutoGen and AG2?Define
Three agent boxes, coder, reviewer and manager, each with arrows both into and out of a dashed question-mark box in the middle.
7. What does speaker selection do in a group chat?Define
A pool box noting the coder just spoke, leading to a highlighted speaker-selection box, then to a dashed question mark.
8. What is a ConversableAgent?Define
A coder box exchanging send and receive arrows with a messages box, beside a dashed box asking what class of component the coder is.
9. What is a termination token?Define
A short transcript ending in a highlighted message that reads manager colon TERMINATE, beside a dashed box asking what this message is.
10. What is context bloat in a group chat?Define
A bar chart of pool size at turn 2, 5 and 10 growing taller each time, with arrows down to a dashed box asking what effect this has.
Illustrative message counts.
11. What is a projection in a group chat?Define
A full pool of 12 messages, with a question mark over what an agent's view is, and two design boxes below: design A, agent reads everything, and design B, agent reads a scoped slice.
12. What did the community do when Microsoft began the v0.4 actor-model rewrite in early 2025?Define
An early-2025 card about Microsoft starting an event-driven actor-model rewrite, next to a dashed box asking what the community's reaction was.
13. What did Microsoft announce for AutoGen in February 2026?Define
A box reading AutoGen, February 2026, with an arrow to a dashed box asking what Microsoft announced.
14. What is the key weakness of round-robin speaker selection?Explain
A fixed cycle of coder, reviewer, manager, above a band reading topic right now legal review, and a dashed box asking whether this is a problem.
15. What determinism problem affects LLM-selected GroupChat?Explain
Two boxes, run 1 and run 2, both reading prompt P and the same pool, each with a dashed box underneath asking what the next speaker is.
16. What separates GroupChat from the supervisor pattern when both use the same four primitives?Explain
Pattern 1: a planner box with arrows down to two worker boxes. Pattern 2: three agent boxes connected to each other as peers. A dashed box below asks which has a planner and which is a selector over peers.
17. Why do teams often write a custom selector that wraps an LLM with fallback rules, such as always giving the verifier the turn after the coder?Explain
A fixed rule box, verifier always gets the turn right after the coder, beside a box for every other situation, under a dashed box asking why combine them.
18. Why keep a max-rounds cap even when agents can emit a TERMINATE token?Explain
A TERMINATE-token box beside a max_rounds-cap box, above a dashed box asking why keep both.
19. Why can a sycophancy cascade happen in a group chat, and what does the lesson suggest to counter it?Explain
Agent A, speaks confidently, with an arrow to a dashed box asking how Agent B responds.
20. A six-agent review chat gets slower and worse after about 15 turns, and the coder speaks in most of them. Which pair of fixes fits best?Analyze
Six agents, coder through F, with a bar chart showing coder taking far more turns than the other five after about 15 turns.
Illustrative turn counts for a six-agent chat.
21. The same task is run twice with no code changes, and the chat gives turns to different agents each time. Which setup best explains this?Analyze
Run 1 and run 2 boxes with different outcomes, above a dashed box asking what kind of setup explains this.
22. Three agents all accept the first confident but wrong claim and build on it. Which failure is this and which fix fits?Analyze
Agent 1 asserts X is true confidently, Agent 2 agrees, Agent 3 agrees, beside a dashed box asking what failure and fix apply.
23. You are building a brainstorm where a coder, a researcher and an archivist may each ask any of the others for help. Which setup fits best?Design
Coder, researcher and archivist boxes, with a dashed box underneath asking which setup fits a flow where any may ask any other for help.
24. A compliance workflow must run the same steps in the same order on every run. Which approach should you choose?Design
A box describing a workflow with step 1 to step 3 identical on every run, above a dashed box asking which approach fits.

Build It

code/main.py implements a GroupChat from scratch in stdlib. Three agents (coder, reviewer, manager), round-robin and LLM-selected variants, and a termination on a TERMINATE token. The LLM-selected variant is simulated with hardcoded rules on the last message's speaker, so the demo runs offline.

The demo prints the conversation transcript plus the selector's decision trace for both variants.

Run:

python3 code/main.py
Check: Build It0/4
1. Why does the clean six-turn context-aware demo trace say little about how a real LLM selector behaves?Explain
A clean six-turn trace box beside a dashed box asking what the selector is, under a dashed box asking what this says about a real LLM selector.
2. Why does the round-robin demo run end after four turns with the bug still in?Apply
A roster of coder, reviewer and manager, above a band reading 4 turns used, bug still present at the end, and a note asking why it ends here.
3. In the context-aware demo the pool starts empty. Which agent does the selector return first, and how long is the run?Apply
A roster of coder, reviewer and manager, above a band reading max_rounds equals 8, for a context-aware selector run starting from an empty pool.
4. Which sequence of turns matches the round-robin demo run?Apply
Four turn rows, each with a dashed question mark where the content would go.

Use It

outputs/skill-groupchat-selector.md configures a GroupChat selector for a given task: round-robin vs LLM-selected vs custom, and what selector inputs (recent messages, agent specialties, turn counts) to use.

Ship It

Checklist:

  • Max rounds cap. Set one. 10-20 for typical tasks.
  • Speaker-balance metric. Track turns per agent; alert when imbalance exceeds a threshold.
  • Termination token. TERMINATE or a dedicated verifier agent.
  • Projection or scoped memory. After ~10 messages, consider giving each agent only a scoped view to prevent context bloat.
  • Selector logging. For LLM-selected variants, log both the selector's input and its choice. Without both, debugging is guesswork.
Check: Ship It0/4
1. What does Ship It say about max rounds and speaker balance?Define
Two dashed boxes, one labelled max rounds and one labelled speaker balance, each with a question mark.
2. For an LLM-selected chat in production, what does Ship It say to log about the selector?Explain
Two dashed boxes side by side, one labelled input and one labelled choice, each with a question mark.
3. A team's LLM selector keeps picking the wrong agent, but their logs record only which agent was chosen. What is the missing piece?Analyze
Three log rows, each a turn number and a chosen agent, beside a dashed box asking what is missing for debugging.
4. You are shipping a code-review GroupChat. Which termination setup is strongest?Design
A cap-only box and a token-only box, above a dashed box asking which setup is strongest.
Author's Note

I'd run code/main.py and read the two traces side by side before anything else. Under round-robin the coder posts the buggy a - b, the reviewer flags it, the manager says "continue working", and then the cycle hands the turn back to the coder. The coder's policy only looks at the last three messages, sees the manager's line instead of the reviewer's "please fix", and emits TERMINATE. The chat ends after four turns with the bug still in. Nothing in the demo is broken. A context-blind cycle gave a turn to an agent whose message buried the one that mattered.

The context-aware run takes six turns, ends when the manager emits TERMINATE after the reviewer's approval, and gives each agent two. I'd be careful about what it proves, though. Its selector is a few hardcoded branches on the last speaker standing in for an LLM call, so the clean trace says nothing about how a real LLM selector behaves across repeated runs. It also spends its first turn on the manager, because the selector returns the manager when the pool is empty.

Neither run reaches max_rounds=8, so the cap never gets exercised. run_groupchat does record the selector's trace, which covers the choice half of the selector-logging item in Ship It. It does not record what the selector saw when it chose. For a real LLM selector I'd add that before anything else.

Exercises

  1. Run code/main.py. Compare the conversation under round-robin vs LLM-selected. Which agent dominates under each?
  2. Add a "max-speaks-per-agent" rule in the selector. How does it affect the transcript?
  3. Implement a goal-reached termination: stop when the reviewer returns "approved." How often does it trigger before the round cap?
  4. Read the AutoGen stable docs on GroupChat (https://microsoft.github.io/autogen/stable/user-guide/core-user-guide/design-patterns/group-chat.html). Identify the default selector used by GroupChatManager.
  5. Read the AG2 repo (https://github.com/ag2ai/ag2) and compare its v0.2 GroupChat to the v0.4 event-driven version. What concrete property (throughput, fault-tolerance, composability) does v0.4 add?

Key Terms

TermWhat people sayWhat it actually means
GroupChat"Agents in one chat room"Shared message pool + selector function. AutoGen / AG2 primitive.
Speaker selection"Who talks next"The function that picks the next agent. Round-robin, LLM-selected, or custom.
GroupChatManager"The meeting host"AutoGen component that owns the selector and loops over turns.
ConversableAgent"The base agent"AutoGen base class; an agent that can send and receive messages.
Termination token"The 'stop' word"Sentinel string (usually TERMINATE) that ends the chat.
Hot speaker"One agent dominates"Failure mode where the selector keeps picking the same agent.
Context bloat"Pool grows unbounded"Each agent reads every prior message; context grows with turns.
Projection"Scoped view"Role-specific view into the shared pool to prevent context bloat.

Further Reading

Code

Ships With