AutoGen Essentials

Course Content

AutoGen Essentials

7 sections · 28 lessons

How do you implement agent patterns in AutoGen like planner–executor or researcher–writer–critic?


Planner–executor loop for a Kerala tripplanner:numbered planplanner:names one stepexecutor:runs toolsexecutor:reports JSONplanner: APPROVEDonly agentwith toolsnohouseboat on 17 DecA failed step goes back to the planner, which swaps days 3 and 4 instead of guessing.
Splitting planning from doing gives you a plan to inspect and one clear place to re-plan when a tool says no.

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+

Python
from autogen_agentchat.agents import AssistantAgentfrom autogen_agentchat.conditions import MaxMessageTermination, TextMentionTerminationfrom autogen_agentchat.teams import RoundRobinGroupChatplanner = AssistantAgent("planner", model_client=client,    system_message="Write a numbered plan, then name ONE step for the executor. "                   "Never call tools. When every step is done, reply APPROVED.")executor = AssistantAgent("executor", model_client=client,    tools=[search_trains, search_hotels, check_budget], max_tool_iterations=3,    system_message="Do only the step the planner named. Report results as JSON. "                   "Do not re-plan.")team = RoundRobinGroupChat(    [planner, executor],    termination_condition=TextMentionTermination("APPROVED", sources=["planner"])                          | MaxMessageTermination(24),)

Researcher–writer–critic

AgentJobOutput contract
researcherGather facts with sources using search toolsBullet facts, each with a URL
writerDraft from the facts onlyDraft text
criticCheck draft against the task and factsAPPROVED, or at most 3 numbered issues

The researcher may need several turns in a row, which round robin cannot express. Options:

  • SelectorGroupChat with allow_repeated_speaker=True (the default is False) and good descriptions.
  • GraphFlow: edges researcher to writer, writer to critic, and critic back to writer only when the message does not contain APPROVED.
  • 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:

  1. 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."
  2. Executor runs each step with real tools and returns JSON.
  3. When the houseboat search returns nothing for 17 Dec, the planner re-plans: swap days 3 and 4.
  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_iterations set 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.