Skip to content

[Bug] SelectorGroupChat livelock: fallback returns excluded previous speaker when allow_repeated_speaker=False #7471

@1Ckpwee

Description

@1Ckpwee

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions