An AG2 ConversableAgent will keep replying to the other agent until something stops it, and two agents that misunderstand each other can loop for a long time. The maximum consecutive auto-reply setting caps how many replies an agent sends in a row before it stops and waits. Set it low for a first run: a small number is enough for a working conversation, and a loop that hits the cap is a signal to fix the instructions, not to raise the cap.
What you need
- Python with the autogen package installed
- An AG2 ConversableAgent already created
- A rough idea of how many turns the task should take
Step 1: Set the auto-reply count on the agent
Set the maximum consecutive auto-reply count when you create the agent, choosing a small number that fits the task. The setting applies per agent, so set it on each agent in the conversation.
Step 2: Run the conversation and watch the turn count
Run the agents on a real task and count the turns. A healthy run finishes well under the cap; a run that hits the cap has a looping problem.
Step 3: Fix the loop instead of raising the cap
If the run hits the cap, read the last few messages to find where the agents started repeating each other, and fix the instructions or the termination rule. Raise the cap only when the task genuinely needs more turns.
Worked example: synthetic conversation run
The table below is a synthetic example. It shows the expected result of the auto-reply limit; no chat was run.
| Check | Expected | Result |
|---|---|---|
| Task finishes under the cap | Yes | Pass |
| Turns used | 6 | Under cap |
| Looping run hits the cap | Yes | Stopped |
Expected result (UNTESTED). a healthy run finishes in a few turns, and a looping run stops at the cap instead of running on. This check was not run live; the table shows the expected result for the synthetic example.
Limits
- The cap is per agent, so set it on every agent in the conversation, not just one.
- A run that hits the cap is a symptom, not a limit problem; fix the instructions first.
- Pair the cap with a termination condition, so a run that finishes early still stops cleanly.
