fix(agentchat): SelectorGroupChat fallback must not return excluded previous speaker when allow_repeated_speaker=False#7936
Conversation
ErenAta16
left a comment
There was a problem hiding this comment.
Checked out the branch and ran the existing group-chat suite before anything else, and it surfaces something worth flagging before this merges: test_selector_group_chat_fall_back_to_previous_after_3_attempts now fails.
Looking at that test, it does not pass allow_repeated_speaker explicitly, so it runs against the default (False). The model client always returns "agent2" (the already-excluded previous speaker) for all 4 attempts, and the test asserts the fallback still returns "agent2" a second time — which is exactly the pre-existing bug this PR is fixing, just encoded as the expected outcome in an older test. So the fix logic itself is correct and matches the allow_repeated_speaker=False contract described in the docstring, but this specific pre-existing test needs its assertions (and probably its name) updated to match the corrected behavior, otherwise this fails CI as soon as the full suite runs. Not showing up yet since only license/cla and the security check have completed on this SHA.
Once that test is updated to reflect "fallback must not repeat when allow_repeated_speaker=False" rather than asserting the old repeat, happy to re-review.
…revious speaker when allow_repeated_speaker=False When allow_repeated_speaker=False, _select_speaker excludes the previous speaker from the participants list. If the model fails after max_attempts, the fallback returned self._previous_speaker anyway — which is excluded from the list and causes a livelock where one agent speaks forever. Fix: check allow_repeated_speaker in the fallback. If disallowed, pick the first participant that isn't the previous speaker instead. Fixes microsoft#7471 Signed-off-by: Diwak4r <diwakar.pandey2004@gmail.com> Signed-off-by: Diwak4r <diwak4r.comp@gmail.com>
f944e46 to
2568b4d
Compare
|
Thanks for the detailed review, @ErenAta16. You were right: the existing test was asserting the old buggy behavior. I updated est_selector_group_chat_fall_back_to_previous_after_3_attempts to est_selector_group_chat_fall_back_to_non_previous_after_3_attempts and changed the final assertion to expect �gent1 (the first non-previous candidate) instead of �gent2. All 32 selector group chat tests now pass locally. Please re-review when you have a moment. |
|
Re-reviewed. The renamed test now asserts The new Fix logic and both tests look correct to me. |
Problem
In
SelectorGroupChat, whenallow_repeated_speaker=False,_select_speakerexcludes the previous speaker from theparticipantslist passed to the model. If the model fails to make a valid selection aftermax_selector_attemptsretries, the fallback logic returnedself._previous_speakeranyway:Since the previous speaker was deliberately excluded from
participants, returning it violates theallow_repeated_speaker=Falsecontract — and, worse, in a two-agent team it causes a livelock: the same agent is picked again and again, never making progress (see #7471).Fix
Gate the "use previous speaker" fallback behind
allow_repeated_speaker. When repeated speakers are disallowed, the fallback now picks the first participant that is not the previous speaker:participants[0]remains the final safe fallback (it already excludes the previous speaker when disallowed).Verification
Added
test_selector_group_chat_fallback_respects_allow_repeated_speaker, which makes the selector model always "select" the previous speaker and asserts the fallback moves to the other participant (no agent speaks twice in a row). Run on both runtime variants:Fixes #7471