AutoGen Essentials

Course Content

AutoGen Essentials

7 sections · 28 lessons

How do you define agent roles and prompts so multiple agents avoid overlap and endless conflict?


What you need to know

Two different texts per agent

Every AutoGen agent has two pieces of text, and they have different readers:

FieldWho reads itWhat it should say
system_messageThe agent's own modelHow to do the job, what not to do, the output format
descriptionThe speaker selector (SelectorGroupChat, or 0.2 GroupChat in "auto" mode) and other agentsWhen this agent should speak next

Most people copy the system message into description, or leave the default. Then the selector has to guess, and it picks the wrong agent.

Five rules for non-overlapping roles

  1. One responsibility, stated first. "You write Python. You do not run it and you do not review style."
  2. Name the exclusions. In a group chat, the "do not" half of the prompt prevents more trouble than the "do" half.
  3. An output contract. Each agent produces something the next one can parse: a numbered plan, a JSON object, APPROVED.
  4. A bounded critic. "At most three issues, and only ones that change correctness." An unbounded critic always finds something.
  5. A decider. When two agents disagree, one of them (or a human) has the final word, and the loop has a cap anyway.

What it looks like in code (0.4+)

Python
flights = AssistantAgent(    "flights", model_client=client, tools=[search_flights],    description="Pick me when the plan needs flight options or prices.",    system_message=(        "You find flights only. Return at most 3 options as JSON with "        "airline, depart, arrive, price_inr. Do not suggest hotels, "        "trains or itineraries."    ),)hotels = AssistantAgent(    "hotels", model_client=client, tools=[search_hotels],    description="Pick me when the plan needs a place to stay.",    system_message="You find hotels only. Return at most 3 options as JSON. "                   "Do not change dates or suggest transport.",)

Notice the description is written as "pick me when…", and the system message ends with the exclusions. Each agent's tools match its job, so even a confused agent cannot book the other's work.

Where conflict really comes from

  • Shared goals with no owner. Two agents both "improve the plan" and undo each other's edits.
  • Critic without an exit. The writer keeps changing wording to satisfy vague feedback.
  • No tiebreak. The last agent to speak wins, which is random.

A real-life example

A travel-planning team had four agents: planner, flights, hotels, budget. Users kept getting itineraries with two different arrival times. The trace showed why: planner and flights both wrote travel legs, and hotels also suggested "take the 6 am Shatabdi" because its prompt said "help plan the stay". Round after round, they overwrote each other.

The fix took one afternoon:

  • planner became the only agent allowed to write the day-by-day plan.
  • flights and hotels returned options as JSON only, with "do not suggest transport or itineraries".
  • budget got a contract: APPROVED, or the rupee amount over budget and which line to cut.
  • planner was named the decider; after two budget rounds it ships the cheapest valid plan.

Conflicting arrival times went from 1 in 6 runs to none in 50 test runs, and the average run fell from 14 messages to 8.

Follow-up questions to expect

  • "How do you check that roles do not overlap?" — Read each system prompt alone and ask whether it could do another agent's job. Then check traces: if two agents produce the same kind of output, merge or narrow them.
  • "Should agents know about each other?" — A planner or coordinator should list the team and what each member does. Workers usually should not; they only need their own job.
  • "What if agents still disagree?" — Let the named decider pick using evidence (test results, budget numbers), and cap the rounds so disagreement ends in a decision or an escalation, never in a loop.