fix(agentchat): validate participants type in BaseGroupChat with clear TypeError#7646
Open
xodn348 wants to merge 1 commit intomicrosoft:mainfrom
Open
fix(agentchat): validate participants type in BaseGroupChat with clear TypeError#7646xodn348 wants to merge 1 commit intomicrosoft:mainfrom
xodn348 wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…r TypeError Before this change, passing None, a string, or a list containing non-agent objects to RoundRobinGroupChat (and other group chat types) raised low-level internal errors such as: - TypeError: object of type 'NoneType' has no len() - AttributeError: 'str' object has no attribute 'name' Now BaseGroupChat.__init__ validates that participants is a list and that each element is a ChatAgent or Team instance, raising a descriptive TypeError before any internal code runs. Fixes microsoft#7580
Contributor
|
@xodn348 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
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.
Summary
Fixes #7580
When a user accidentally passes
None, a non-list value (e.g. a string or integer), or a list containing non-agent/non-team objects asparticipantstoRoundRobinGroupChat(or anyBaseGroupChatsubclass), the current code raises low-level internal errors that are hard to debug:TypeError: object of type 'NoneType' has no len()— forparticipants=NoneAttributeError: 'str' object has no attribute 'name'— forparticipants="not a list"or a list containing a stringChanges
_base_group_chat.py: Added explicit type validation at the top ofBaseGroupChat.__init__— checks thatparticipantsis alistand that every element is aChatAgentorTeaminstance, raising a descriptiveTypeErrorbefore any internal logic runs._round_robin_group_chat.py: Updated theRaisesdocstring to document the newTypeError.tests/test_group_chat.py: Addedtest_group_chat_invalid_participants— a synchronous test covering all four bad-input cases:None, a string, an integer, and a list containing a non-agent item.Before / After
The fix is in
BaseGroupChat, so it covers all subclasses (RoundRobinGroupChat,SelectorGroupChat,Swarm,MagenticOneGroupChat) automatically.