fix: validation error messages for invalid participants in BaseGroupChat#7715
Open
AmSach wants to merge 1 commit into
Open
fix: validation error messages for invalid participants in BaseGroupChat#7715AmSach wants to merge 1 commit into
AmSach wants to merge 1 commit into
Conversation
…upChat Before this fix, passing invalid participants (None, wrong types, bad list items) to RoundRobinGroupChat caused raw AttributeError/TypeError from internal code. After this fix, BaseGroupChat.__init__ validates participants upfront: - None -> TypeError with descriptive message - Wrong type (not list/tuple) -> TypeError - Empty list -> ValueError - Non-agent items -> TypeError with index and actual type shown Fixes microsoft#7580
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.
Fixed the bug described in issue #7580. Here's what was wrong and how I fixed it:
What was broken:
When invalid participants (None, wrong types, or lists containing non-agent objects) were passed to
RoundRobinGroupChat(or anyBaseGroupChatsubclass), the constructor raised raw low-level Python errors likeTypeError: object of type 'NoneType' has no len(),AttributeError: 'str' object has no attribute 'name', instead of a clear validation message.How I fixed it:
Added explicit input validation at the top of
BaseGroupChat.__init__that checks:participantsis notNone→ raisesTypeErrorparticipantsis a list or tuple → raisesTypeErrorif notparticipantsis non-empty → raisesValueErrorif emptyChatAgentorTeaminstances → raisesTypeErrorwith index and actual type name if notThis replaces opaque internal errors with clear, actionable messages that point users directly to the problem.
Testing:
Verified all 5 error cases from the issue now produce descriptive errors:
RoundRobinGroupChat(participants=None)→TypeError: participants must be a non-empty sequence of ChatAgent or Team instances.RoundRobinGroupChat(participants="not a list")→TypeError: participants must be a list or tuple of ChatAgent or Team instances.RoundRobinGroupChat(participants=42)→TypeError: participants must be a list or tuple of ChatAgent or Team instances.RoundRobinGroupChat(participants=[])→ValueError: At least one participant is required.RoundRobinGroupChat(participants=[UserProxyAgent(name="valid"), "bad"])→TypeError: participants[1] must be a ChatAgent or Team instance, got str.Files changed:
python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat.py— added 9 lines of validationLink to issue: #7580