{"record":{"id":"c6774148288a6ec1","repo":"microsoft/autogen","slug":"participant-participant-must-be-a-chatagent-c67741","errorCode":null,"errorMessage":"Participant {participant} must be a ChatAgent.","messagePattern":"Participant (.+?) must be a ChatAgent\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_swarm_group_chat.py","lineNumber":247,"sourceCode":"\n    DEFAULT_NAME = \"Swarm\"\n    DEFAULT_DESCRIPTION = \"A team of agents.\"\n\n    def __init__(\n        self,\n        participants: List[ChatAgent],\n        *,\n        name: str | None = None,\n        description: str | None = None,\n        termination_condition: TerminationCondition | None = None,\n        max_turns: int | None = None,\n        runtime: AgentRuntime | None = None,\n        custom_message_types: List[type[BaseAgentEvent | BaseChatMessage]] | None = None,\n        emit_team_events: bool = False,\n    ) -> None:\n        for participant in participants:\n            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","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_swarm_group_chat.py#L229-L265","documentation":"Swarm.__init__ raises TypeError when any participant is not an instance of ChatAgent. Swarm handoff mechanics rely on per-agent HandoffMessage production and tool-based handoffs, which only ChatAgent (e.g. AssistantAgent) provides.","triggerScenarios":"Passing a Team, an autogen_core BaseAgent, or any non-ChatAgent object in participants to Swarm(); wrapping a team and passing the wrapper if it is not a ChatAgent subclass.","commonSituations":"Trying to nest a RoundRobinGroupChat or GraphFlow inside Swarm; passing raw autogen_core agents from a custom runtime.","solutions":["Use only AssistantAgent/ChatAgent instances as Swarm participants.","To include a team's behavior, either flatten its agents into the swarm or use GraphFlow which supports Team nodes.","For a custom agent, subclass autogen_agentchat.agents.ChatAgent and implement its abstract methods, including handoff support."],"exampleFix":"# before\nswarm = Swarm(participants=[researcher, RoundRobinGroupChat([coder, reviewer])])  # TypeError\n\n# after\nswarm = Swarm(participants=[researcher, coder, reviewer])","handlingStrategy":"type-guard","validationCode":"from autogen_agentchat.agents import ChatAgent\nassert all(isinstance(p, ChatAgent) for p in participants), \"Swarm requires ChatAgent participants\"","typeGuard":"from autogen_agentchat.agents import ChatAgent\n\ndef all_chat_agents(participants: Sequence[object]) -> bool:\n    return all(isinstance(p, ChatAgent) for p in participants)","tryCatchPattern":null,"preventionTips":["Do not pass Teams or autogen_core agents to Swarm.","Subclass ChatAgent for custom swarm members and implement handoff support."],"tags":["autogen","swarm","participants","type-error"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}