Skip to content

fix: return consistent List[str] from SwarmGroupChatManager.select_speaker#7582

Open
Ricardo-M-L wants to merge 1 commit intomicrosoft:mainfrom
Ricardo-M-L:fix/swarm-select-speaker-return-type
Open

fix: return consistent List[str] from SwarmGroupChatManager.select_speaker#7582
Ricardo-M-L wants to merge 1 commit intomicrosoft:mainfrom
Ricardo-M-L:fix/swarm-select-speaker-return-type

Conversation

@Ricardo-M-L
Copy link
Copy Markdown

Why Are These Changes Needed?

SwarmGroupChatManager.select_speaker() has inconsistent return types:

  • Lines 91, 97: return [self._current_speaker] (List[str])
  • Line 98: return self._current_speaker (str)

The return type annotation is List[str] | str, but the docstring says "This method always returns a single speaker." Callers that process the result uniformly as a list will get a TypeError when the fallback path returns a bare string.

Related issue number

N/A

Checks

  • I've included any doc changes needed
  • I've added tests (if applicable) corresponding to the changes introduced in this PR
  • I've made sure all auto checks have passed

…eaker

The method returns List[str] when thread is empty (line 91) or when a
HandoffMessage is found (line 97), but returns a bare str when no
handoff message exists (line 98). This inconsistency can cause TypeError
in callers expecting a uniform return type.

Wrap the fallback return in a list to match the other return paths.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
# The latest handoff message should always target a valid participant.
assert self._current_speaker in self._participant_names
return [self._current_speaker]
return self._current_speaker
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type annotation is List[str] | str, but the docstring says "This method always returns a single speaker" — suggesting List[str] was the intended signature all along. The bare string return path appears to be a latent bug rather than intentional behavior. Was there a historical reason for the str fallback, or is this simply a consistency fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants