From cc1d9bc3221e9432a1819a12ef35c14abdc39613 Mon Sep 17 00:00:00 2001 From: Aman Sachan Date: Tue, 19 May 2026 03:37:05 +0000 Subject: [PATCH] fix: add participants validation with clear error messages in BaseGroupChat 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/autogen#7580 --- .../teams/_group_chat/_base_group_chat.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat.py b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat.py index 60f222912387..5bc86ff5eebe 100644 --- a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat.py +++ b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat.py @@ -78,8 +78,17 @@ def __init__( ): self._name = name self._description = description + if participants is None: + raise TypeError("participants must be a non-empty sequence of ChatAgent or Team instances.") + if not isinstance(participants, (list, tuple)): + raise TypeError("participants must be a list or tuple of ChatAgent or Team instances.") if len(participants) == 0: raise ValueError("At least one participant is required.") + for i, participant in enumerate(participants): + if not isinstance(participant, (ChatAgent, Team)): + raise TypeError( + f"participants[{i}] must be a ChatAgent or Team instance, got {type(participant).__name__}." + ) if len(participants) != len(set(participant.name for participant in participants)): raise ValueError("The participant names must be unique.") self._participants = participants