Select every condition that should be in the termination policy for a production AutoGen team
A production AutoGen policy OR-combines a message cap, a token budget, a sentinel from a designated agent, and a wall-clock timeout so cost, hang, and natural completion all stop the loop cleanly.
Imagine a meeting where people keep talking forever. To end the meeting safely you set several alarms: stop after 30 turns of conversation, stop after the room has spent its budget, stop the moment the chairperson says the word DONE, and stop after one hour on the clock no matter what. Whichever alarm rings first ends the meeting. You do not pick one alarm and trust it, because each kind of meeting fails in a different way. A long argument hits the turn cap. A waste of time meeting hits the budget cap. A productive meeting reaches DONE early. A stuck on one question meeting hits the wall clock. The agent team uses the same idea: layer four alarms so no failure mode runs the bill up overnight.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
A multi-agent team has more ways to fail than a single-agent chain. Two agents can ping-pong forever, a worker can hang on a slow tool call, the team can converge but never announce completion, and any of these can quietly burn budget while a human is asleep. The termination policy is the contract that says "under no circumstances does this run continue past these bounds." It is one of the highest-leverage configuration choices in a production agent deployment.
This deep dive walks through the four production-grade conditions, why each maps to a distinct failure mode, why the two distractor options in the question are nonsense, how AutoGen 0.4 composes them in code, and how to layer a no-progress detector underneath as the senior move.
The four conditions that earn their slot
Max-message count is the crudest and the most universal. The team has N turns and then it stops. Set N from the longest legitimate trace you have observed plus a small margin. The cap exists for the case where every other condition has failed to fire and the loop is grinding away with no end in sight. It is a safety net, not a primary signal.
Token-usage budget is the cost ceiling. The loop's input plus output tokens are summed across turns and the run stops when the total exceeds the budget. This is the line item that converts a bug from "the agent looped overnight" into "the agent looped for ten minutes and stopped at the cap." Set the budget per task, not per session, and alert on runs that hit the cap because hitting it should be rare; if it fires every run, your budget is wrong or your agents are broken.
Text-mention sentinel is the natural-completion path. A designated agent emits a token like TERMINATE or DONE and the framework matches the token and ends the loop. The sentinel matters because without it the team has no way to say "we are done"; the only termination is then the safety nets, which is wasteful.
External timeout is the wall-clock backstop. It catches the failure mode where a tool call hangs, an LLM provider stalls, or a human in the loop step never resolves. Token spend is zero during a hang because the model is not running, so the token cap does not save you; only the wall-clock does.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- AutoGen 0.4 ships MaxMessageTermination, TokenUsageTermination, TextMentionTermination, and TimeoutTermination as composable primitives joined with the | operator.
- Microsoft AutoGen Studio surfaces these termination conditions as toggles in the team editor so non-engineers can configure the safety envelope.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy is the sentinel typically restricted to a single designated agent rather than any agent in the team?
If any agent can end the run by emitting the sentinel, a worker can accidentally terminate by quoting the keyword in its reasoning. Restricting the sentinel to a supervisor or critic makes the stop signal authoritative and prevents quoting as stop accidents.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Picking one condition (just max-messages, or just a sentinel) and assuming it covers every failure mode. A single condition leaves at least one runaway path open.
60 second bullets to scan on the way to the call.
List the four termination conditions a production AutoGen team should combine
Explain why the conditions are OR-combined rather than AND-combined
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.