Bug Description
When allow_repeated_speaker=False in SelectorGroupChat, if the LLM-based selector fails to pick a valid (non-previous) speaker within max_selector_attempts, the fallback logic in _selector_group_chat.py returns self._previous_speaker — the exact speaker that was supposed to be excluded.
This creates a livelock: Agent A speaks → selector tries to pick someone else → exhausts attempts → falls back to A → A speaks again → repeat forever.
Reproduction
from autogen_agentchat.teams import SelectorGroupChat
team = SelectorGroupChat(
participants=[agent_a, agent_b, agent_c],
model_client=client,
allow_repeated_speaker=False,
max_selector_attempts=3,
)
# If the LLM consistently selects the previous speaker in all 3 attempts,
# the fallback returns the previous speaker, violating allow_repeated_speaker=False
Root Cause
In _selector_group_chat.py, the fallback after exhausting max_selector_attempts:
if self._previous_speaker is not None:
return self._previous_speaker # BUG: returns the excluded speaker
Suggested Fix
When allow_repeated_speaker=False, the fallback should select a random participant that is NOT the previous speaker:
if not self._allow_repeated_speaker and self._previous_speaker is not None:
candidates = [p for p in participants if p != self._previous_speaker]
if candidates:
return random.choice(candidates)
return self._previous_speaker # only if repeated speaker IS allowed or no alternatives
Bug Description
When
allow_repeated_speaker=FalseinSelectorGroupChat, if the LLM-based selector fails to pick a valid (non-previous) speaker withinmax_selector_attempts, the fallback logic in_selector_group_chat.pyreturnsself._previous_speaker— the exact speaker that was supposed to be excluded.This creates a livelock: Agent A speaks → selector tries to pick someone else → exhausts attempts → falls back to A → A speaks again → repeat forever.
Reproduction
Root Cause
In
_selector_group_chat.py, the fallback after exhaustingmax_selector_attempts:Suggested Fix
When
allow_repeated_speaker=False, the fallback should select a random participant that is NOT the previous speaker: