fix(agentchat): respect allow_repeated_speaker=False in selector fallback#7568
Open
extrasmall0 wants to merge 1 commit intomicrosoft:mainfrom
Open
fix(agentchat): respect allow_repeated_speaker=False in selector fallback#7568extrasmall0 wants to merge 1 commit intomicrosoft:mainfrom
extrasmall0 wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…back When the model fails to select a valid speaker within max_selector_attempts and allow_repeated_speaker=False, the fallback unconditionally returned self._previous_speaker — the exact speaker that should be excluded — causing a livelock where the same agent kept being selected indefinitely. The _select_speaker method already receives a participants list that has the previous speaker filtered out (done by the caller at line 196-197), so the fix is to use random.choice(participants) for the fallback when repeated speakers are not allowed, instead of falling through to the self._previous_speaker branch.
Author
|
Gentle ping — the fix is small and all CI checks are passing. Happy to add tests or make any adjustments if needed. Thanks for maintaining this! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7471
Problem
When
allow_repeated_speaker=Falseand the model exhaustsmax_selector_attemptswithout picking a valid (non-previous) speaker, the fallback in_select_speakerreturnsself._previous_speaker:This creates a livelock: agent A speaks → selector tries to pick someone else → exhausts attempts → falls back to A → A speaks again → repeat.
Root Cause
The
_select_speakermethod receives aparticipantslist that already has the previous speaker filtered out (done by the caller whenallow_repeated_speaker=False). The fallback logic ignores this filtered list and reads directly fromself._previous_speaker.Fix
Add an early-exit branch before the existing fallback: when
allow_repeated_speaker=Falseand there is a previous speaker, userandom.choice(participants)(the already-filtered list) instead of returning the excluded speaker.The existing fallback for
allow_repeated_speaker=True(return previous speaker) is unchanged.