autogen icon indicating copy to clipboard operation
autogen copied to clipboard

RoundRobinGroupChat raises raw AttributeError/TypeError for invalid participants instead of a clear validation error

Open emberpath24 opened this issue 7 months ago • 1 comments

What happened?

Describe the bug Hi, I noticed that RoundRobinGroupChat does not seem to validate the type of the participants argument before using it.

When participants is accidentally set to None, a string, an integer, or a list containing a non-agent object, the constructor raises low-level Python errors such as:

  • TypeError: object of type 'NoneType' has no len()
  • TypeError: object of type 'int' has no len()
  • AttributeError: 'str' object has no attribute 'name'

I understand these are invalid inputs, but they are realistic user mistakes. It would be much easier to debug if AutoGen raised a clear TypeError or ValueError explaining that participants must be a non-empty list/sequence of ChatAgent instances.

To Reproduce from autogen_agentchat.agents import UserProxyAgent from autogen_agentchat.teams import RoundRobinGroupChat

Case 1: participants is None

RoundRobinGroupChat(participants=None)

Case 2: participants is not a sequence of agents

RoundRobinGroupChat(participants="not a list")

Case 3: participants contains a non-agent object

RoundRobinGroupChat(participants=[UserProxyAgent(name="valid_user"), "bad"])

Expected behavior The constructor should reject these invalid inputs with a clear validation error, for example:

TypeError: participants must be a non-empty sequence of ChatAgent instances

or a similar ValueError explaining which item is invalid.

Actual behavior The constructor raises internal implementation errors:

RoundRobinGroupChat(participants=None) -> TypeError: object of type 'NoneType' has no len()

RoundRobinGroupChat(participants="not a list") -> AttributeError: 'str' object has no attribute 'name'

RoundRobinGroupChat(participants=[UserProxyAgent(name="valid_user"), "bad"]) -> AttributeError: 'str' object has no attribute 'name'

** Environment** Package: autogen-agentchat Observed with the local AutoGen checkout / current environment. Python: 3.13

Additional context This is not a request to accept these inputs. The issue is only about error handling: invalid user input currently leaks internal AttributeError/TypeError instead of a clear validation message.

Which packages was the bug in?

Python AgentChat (autogen-agentchat>=0.4.0)

AutoGen library version.

Python dev (main branch)

Other library version.

No response

Model used

No response

Model provider

None

Other model provider

No response

Python version

3.10

.NET version

None

Operating system

MacOS

emberpath24 avatar Apr 14 '26 03:04 emberpath24

Hi! I'd like to work on this.

The fix would be to add explicit validation in BaseGroupChat.__init__ (the parent class used by RoundRobinGroupChat) before participants are used. Something like:

if not isinstance(participants, (list, tuple)) or len(participants) == 0:
    raise TypeError("participants must be a non-empty list of ChatAgent or Team instances.")
for p in participants:
    if not isinstance(p, (ChatAgent, Team)):
        raise TypeError(f"participants[{participants.index(p)}] is not a ChatAgent or Team instance: {type(p).__name__}")

This would surface a clear error for all the cases in the issue (None, int, str, list with non-agent items) before any internal code tries to iterate or access attributes.

Could you assign this to me? Happy to open a PR with tests.

nileshpatil6 avatar Apr 19 '26 19:04 nileshpatil6