{"record":{"id":"f161781db05a1461","repo":"microsoft/autogen","slug":"the-maximum-number-of-turns-must-be-greater-than-0","errorCode":null,"errorMessage":"The maximum number of turns must be greater than 0.","messagePattern":"The maximum number of turns must be greater than 0\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat_manager.py","lineNumber":62,"sourceCode":"        participant_descriptions: List[str],\n        output_message_queue: asyncio.Queue[BaseAgentEvent | BaseChatMessage | GroupChatTermination],\n        termination_condition: TerminationCondition | None,\n        max_turns: int | None,\n        message_factory: MessageFactory,\n        emit_team_events: bool = False,\n    ):\n        super().__init__(\n            description=\"Group chat manager\",\n            sequential_message_types=[\n                GroupChatStart,\n                GroupChatAgentResponse,\n                GroupChatTeamResponse,\n                GroupChatMessage,\n                GroupChatReset,\n            ],\n        )\n        if max_turns is not None and max_turns <= 0:\n            raise ValueError(\"The maximum number of turns must be greater than 0.\")\n        if len(participant_topic_types) != len(participant_descriptions):\n            raise ValueError(\"The number of participant topic types, agent types, and descriptions must be the same.\")\n        if len(set(participant_topic_types)) != len(participant_topic_types):\n            raise ValueError(\"The participant topic types must be unique.\")\n        if group_topic_type in participant_topic_types:\n            raise ValueError(\"The group topic type must not be in the participant topic types.\")\n        self._name = name\n        self._group_topic_type = group_topic_type\n        self._output_topic_type = output_topic_type\n        self._participant_names = participant_names\n        self._participant_name_to_topic_type = {\n            name: topic_type for name, topic_type in zip(participant_names, participant_topic_types, strict=True)\n        }\n        self._participant_descriptions = participant_descriptions\n        self._message_thread: List[BaseAgentEvent | BaseChatMessage] = []\n        self._output_message_queue = output_message_queue\n        self._termination_condition = termination_condition\n        self._max_turns = max_turns","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat_manager.py#L44-L80","documentation":"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).","triggerScenarios":"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).","commonSituations":"Using 0 intending 'unlimited' — the correct way is max_turns=None; dynamically derived turn counts that can hit zero.","solutions":["Use max_turns=None (or omit it) for unlimited turns.","Set a positive integer, e.g. max_turns=10.","Sanitize computed values: max_turns = n if n and n > 0 else None."],"exampleFix":"# before\nteam = RoundRobinGroupChat([agent], max_turns=0)  # ValueError\n\n# after\nteam = RoundRobinGroupChat([agent], max_turns=None)  # unlimited","handlingStrategy":"validation","validationCode":"max_turns = max_turns if max_turns and max_turns > 0 else None\nteam = RoundRobinGroupChat(agents, max_turns=max_turns)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use max_turns=None for unlimited turns; 0 is invalid, not 'off'.","Sanitize computed turn limits before passing them to the team.","Document that max_turns must be a positive int or None."],"tags":["python","autogen","group-chat","max-turns","validation"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}