{"record":{"id":"7bd1ded6ee46e35c","repo":"microsoft/autogen","slug":"the-first-participant-must-be-able-to-produce-a-ha","errorCode":null,"errorMessage":"The first participant must be able to produce a handoff messages.","messagePattern":"The first participant must be able to produce a handoff messages\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_swarm_group_chat.py","lineNumber":264,"sourceCode":"            if not isinstance(participant, ChatAgent):\n                raise TypeError(f\"Participant {participant} must be a ChatAgent.\")\n        super().__init__(\n            name=name or self.DEFAULT_NAME,\n            description=description or self.DEFAULT_DESCRIPTION,\n            participants=[participant for participant in participants],\n            group_chat_manager_name=\"SwarmGroupChatManager\",\n            group_chat_manager_class=SwarmGroupChatManager,\n            termination_condition=termination_condition,\n            max_turns=max_turns,\n            runtime=runtime,\n            custom_message_types=custom_message_types,\n            emit_team_events=emit_team_events,\n        )\n        # The first participant must be able to produce handoff messages.\n        first_participant = self._participants[0]\n        assert isinstance(first_participant, ChatAgent)\n        if HandoffMessage not in first_participant.produced_message_types:\n            raise ValueError(\"The first participant must be able to produce a handoff messages.\")\n\n    def _create_group_chat_manager_factory(\n        self,\n        name: str,\n        group_topic_type: str,\n        output_topic_type: str,\n        participant_topic_types: List[str],\n        participant_names: List[str],\n        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    ) -> Callable[[], SwarmGroupChatManager]:\n        def _factory() -> SwarmGroupChatManager:\n            return SwarmGroupChatManager(\n                name,\n                group_topic_type,","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_swarm_group_chat.py#L246-L282","documentation":"Swarm.__init__ raises ValueError when the first participant does not declare HandoffMessage in its produced_message_types. The swarm starts by letting the first agent speak, and control transfer only happens via handoff messages — an agent that cannot produce them dead-ends the run at turn one.","triggerScenarios":"The first participant is a ChatAgent subclass whose produced_message_types omits HandoffMessage (e.g. a custom agent or one configured without handoffs); AssistantAgent instances include it by default, custom agents often forget it.","commonSituations":"Writing a custom ChatAgent for swarm entry; reordering participants so a non-handoff agent lands first; porting agents from older versions where produced_message_types handling differed.","solutions":["Make the first participant an AssistantAgent or an agent whose produced_message_types includes HandoffMessage.","In a custom ChatAgent class, set produced_message_types = (HandoffMessage, TextMessage, MultiModalMessage) (as applicable).","Reorder participants so a handoff-capable agent is first."],"exampleFix":"# before\nclass EntryAgent(ChatAgent):\n    produced_message_types = (TextMessage,)  # ValueError as first participant\n\n# after\nfrom autogen_agentchat.messages import HandoffMessage, TextMessage\nclass EntryAgent(ChatAgent):\n    produced_message_types = (HandoffMessage, TextMessage)","handlingStrategy":"type-guard","validationCode":"from autogen_agentchat.messages import HandoffMessage\nfirst = participants[0]\nassert HandoffMessage in first.produced_message_types, \"First swarm participant must produce HandoffMessage\"","typeGuard":"from autogen_agentchat.agents import ChatAgent\nfrom autogen_agentchat.messages import HandoffMessage\n\ndef can_produce_handoff(agent: ChatAgent) -> bool:\n    return HandoffMessage in agent.produced_message_types","tryCatchPattern":null,"preventionTips":["Put an AssistantAgent (handoff-capable by default) first in the Swarm participant list.","For custom ChatAgent classes, always include HandoffMessage in produced_message_types."],"tags":["autogen","swarm","handoff","participants","custom-agent"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}