microsoft/autogen · error · ValueError

The maximum number of turns must be greater than 0.

Error message

The maximum number of turns must be greater than 0.

What it means

The group chat manager's constructor validates max_turns: if provided, it must be > 0. A zero or negative limit is meaningless for turn counting and is rejected at team construction (the value flows from the team's max_turns parameter to the manager).

Source

Thrown at python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat_manager.py:62

        participant_descriptions: List[str],
        output_message_queue: asyncio.Queue[BaseAgentEvent | BaseChatMessage | GroupChatTermination],
        termination_condition: TerminationCondition | None,
        max_turns: int | None,
        message_factory: MessageFactory,
        emit_team_events: bool = False,
    ):
        super().__init__(
            description="Group chat manager",
            sequential_message_types=[
                GroupChatStart,
                GroupChatAgentResponse,
                GroupChatTeamResponse,
                GroupChatMessage,
                GroupChatReset,
            ],
        )
        if max_turns is not None and max_turns <= 0:
            raise ValueError("The maximum number of turns must be greater than 0.")
        if len(participant_topic_types) != len(participant_descriptions):
            raise ValueError("The number of participant topic types, agent types, and descriptions must be the same.")
        if len(set(participant_topic_types)) != len(participant_topic_types):
            raise ValueError("The participant topic types must be unique.")
        if group_topic_type in participant_topic_types:
            raise ValueError("The group topic type must not be in the participant topic types.")
        self._name = name
        self._group_topic_type = group_topic_type
        self._output_topic_type = output_topic_type
        self._participant_names = participant_names
        self._participant_name_to_topic_type = {
            name: topic_type for name, topic_type in zip(participant_names, participant_topic_types, strict=True)
        }
        self._participant_descriptions = participant_descriptions
        self._message_thread: List[BaseAgentEvent | BaseChatMessage] = []
        self._output_message_queue = output_message_queue
        self._termination_condition = termination_condition
        self._max_turns = max_turns

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Use max_turns=None (or omit it) for unlimited turns.
  2. Set a positive integer, e.g. max_turns=10.
  3. Sanitize computed values: max_turns = n if n and n > 0 else None.

Example fix

# before
team = RoundRobinGroupChat([agent], max_turns=0)  # ValueError

# after
team = RoundRobinGroupChat([agent], max_turns=None)  # unlimited
Defensive patterns

Strategy: validation

Validate before calling

max_turns = max_turns if max_turns and max_turns > 0 else None
team = RoundRobinGroupChat(agents, max_turns=max_turns)

Prevention

When it happens

Trigger: Creating a team with max_turns=0 or a negative number: RoundRobinGroupChat([...], max_turns=0). Also happens when max_turns is computed (e.g. len(some_list) that came out 0).

Common situations: Using 0 intending 'unlimited' — the correct way is max_turns=None; dynamically derived turn counts that can hit zero.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/f161781db05a1461. Report an issue: GitHub.