Course Content
AutoGen Essentials
7 sections · 28 lessons
How do you implement agent patterns in AutoGen like planner–executor or researcher–writer–critic?
What you need to know
Why split planning from doing
A model that plans and acts in the same turn tends to drift: it starts step 3 before step 2 is done, or rewrites the plan whenever a tool fails. Splitting gives:
- A plan you can inspect before any tool runs.
- An executor with a small job: do the current step, report the result.
- A clear place to re-plan when a step fails.
Planner–executor in 0.4+
1from autogen_agentchat.agents import AssistantAgent2from autogen_agentchat.conditions import MaxMessageTermination, TextMentionTermination3from autogen_agentchat.teams import RoundRobinGroupChat45planner = AssistantAgent("planner", model_client=client,6 system_message="Write a numbered plan, then name ONE step for the executor. "7 "Never call tools. When every step is done, reply APPROVED.")8executor = AssistantAgent("executor", model_client=client,9 tools=[search_trains, search_hotels, check_budget], max_tool_iterations=3,10 system_message="Do only the step the planner named. Report results as JSON. "11 "Do not re-plan.")1213team = RoundRobinGroupChat(14 [planner, executor],15 termination_condition=TextMentionTermination("APPROVED", sources=["planner"])16 | MaxMessageTermination(24),17)Researcher–writer–critic
| Agent | Job | Output contract |
|---|---|---|
| researcher | Gather facts with sources using search tools | Bullet facts, each with a URL |
| writer | Draft from the facts only | Draft text |
| critic | Check draft against the task and facts | APPROVED, or at most 3 numbered issues |
The researcher may need several turns in a row, which round robin cannot express. Options:
SelectorGroupChatwithallow_repeated_speaker=True(the default isFalse) and gooddescriptions.GraphFlow: edges researcher to writer, writer to critic, and critic back to writer only when the message does not containAPPROVED.MagenticOneGroupChat: an orchestrator that keeps a plan and a progress ledger, for open-ended tasks.
Legacy 0.2 used GroupChat with speaker_selection_method="auto" and allowed_or_disallowed_speaker_transitions, or register_nested_chats to hide a critique loop inside one agent.
Two things that make or break it
- Structured plan. Numbered steps with an owner and a "done when" line, not a paragraph.
- Verifiable exit. Tests pass, the budget check returns true, or the critic approves under a round cap.
A real-life example
A travel-planning team for a holiday company builds 5-day Kerala itineraries. The single-agent version wrote beautiful plans with a houseboat on a day when none were bookable and a total 20% over budget.
The planner–executor version:
- Planner: "1. Find trains Chennai to Kochi on 14 Dec. 2. Hotels in Munnar, 2 nights, under ₹5,000. 3. Houseboat in Alleppey on 17 Dec. 4. Check total against ₹60,000."
- Executor runs each step with real tools and returns JSON.
- When the houseboat search returns nothing for 17 Dec, the planner re-plans: swap days 3 and 4.
- After the budget check passes, the planner replies
APPROVED.
Runs average 11 messages. Plans with unbookable items dropped from 1 in 4 to about 1 in 30, and every plan now carries real prices.
Follow-up questions to expect
- "When is planner–executor overkill?" — For short tasks of one or two tool calls; a single agent with
max_tool_iterationsset is enough. - "Should the planner see tool results?" — Yes, as short summaries, so it can re-plan. It should not see raw bulk output.
- "How do you stop the critic loop?" — A bounded contract (approve or at most 3 issues), a cap of two revisions, and a termination condition that listens only to the critic.