Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ def __init__(
):
self._name = name
self._description = description
if not isinstance(participants, list):
raise TypeError(
f"participants must be a list of ChatAgent or Team instances, got {type(participants).__name__!r}."
)
for i, participant in enumerate(participants):
if not isinstance(participant, (ChatAgent, Team)):
raise TypeError(
f"participants[{i}] must be a ChatAgent or Team instance, "
f"got {type(participant).__name__!r}."
)
if len(participants) == 0:
raise ValueError("At least one participant is required.")
if len(participants) != len(set(participant.name for participant in participants)):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class RoundRobinGroupChat(BaseGroupChat, Component[RoundRobinGroupChatConfig]):
emit_team_events (bool, optional): Whether to emit team events through :meth:`BaseGroupChat.run_stream`. Defaults to False.

Raises:
TypeError: If participants is not a list or contains non-agent/non-team items.
ValueError: If no participants are provided or if participant names are not unique.

Examples:
Expand Down
20 changes: 20 additions & 0 deletions python/packages/autogen-agentchat/tests/test_group_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,26 @@ async def test_round_robin_group_chat_unknown_task_message_type(runtime: AgentRu
)


def test_group_chat_invalid_participants() -> None:
"""Test that BaseGroupChat raises clear TypeError for invalid participants."""
agent = _EchoAgent("agent", "An echo agent.")

with pytest.raises(TypeError, match="participants must be a list"):
RoundRobinGroupChat(participants=None) # type: ignore[arg-type]

with pytest.raises(TypeError, match="participants must be a list"):
RoundRobinGroupChat(participants="not a list") # type: ignore[arg-type]

with pytest.raises(TypeError, match="participants must be a list"):
RoundRobinGroupChat(participants=42) # type: ignore[arg-type]

with pytest.raises(TypeError, match=r"participants\[1\] must be a ChatAgent or Team instance"):
RoundRobinGroupChat(participants=[agent, "bad"]) # type: ignore[list-item]

with pytest.raises(TypeError, match=r"participants\[0\] must be a ChatAgent or Team instance"):
RoundRobinGroupChat(participants=[42]) # type: ignore[list-item]


@pytest.mark.asyncio
async def test_round_robin_group_chat_unknown_agent_message_type() -> None:
model_client = ReplayChatCompletionClient(["Hello"])
Expand Down