{"record":{"id":"d99118254b1e7754","repo":"microsoft/autogen","slug":"the-target-message-target-is-not-one-of-the-part","errorCode":null,"errorMessage":"The target {message.target} is not one of the participants {self._participant_names}. If you are resuming Swarm with a new HandoffMessage make sure to set the target to a valid participant as the target.","messagePattern":"The target (.+?) is not one of the participants (.+?)\\. If you are resuming Swarm with a new HandoffMessage make sure to set the target to a valid participant as the target\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_swarm_group_chat.py","lineNumber":54,"sourceCode":"            participant_topic_types,\n            participant_names,\n            participant_descriptions,\n            output_message_queue,\n            termination_condition,\n            max_turns,\n            message_factory,\n            emit_team_events,\n        )\n        self._current_speaker = self._participant_names[0]\n\n    async def validate_group_state(self, messages: List[BaseChatMessage] | None) -> None:\n        \"\"\"Validate the start messages for the group chat.\"\"\"\n        # Check if any of the start messages is a handoff message.\n        if messages:\n            for message in messages:\n                if isinstance(message, HandoffMessage):\n                    if message.target not in self._participant_names:\n                        raise ValueError(\n                            f\"The target {message.target} is not one of the participants {self._participant_names}. \"\n                            \"If you are resuming Swarm with a new HandoffMessage make sure to set the target to a valid participant as the target.\"\n                        )\n                    return\n\n        # Check if there is a handoff message in the thread that is not targeting a valid participant.\n        for existing_message in reversed(self._message_thread):\n            if isinstance(existing_message, HandoffMessage):\n                if existing_message.target not in self._participant_names:\n                    raise ValueError(\n                        f\"The existing handoff target {existing_message.target} is not one of the participants {self._participant_names}. \"\n                        \"If you are resuming Swarm with a new task make sure to include in your task \"\n                        \"a HandoffMessage with a valid participant as the target. For example, if you are \"\n                        \"resuming from a HandoffTermination, make sure the new task is a HandoffMessage \"\n                        \"with a valid participant as the target.\"\n                    )\n                # The latest handoff message should always target a valid participant.\n                # Do not look past the latest handoff message.","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_swarm_group_chat.py#L36-L72","documentation":"SwarmGroupChatManager.validate_group_state raises ValueError when a HandoffMessage in the task's start messages targets a name that is not among the team's participants. The swarm routes control to the handoff target, so an invalid target has nowhere to go.","triggerScenarios":"Calling team.run(task=HandoffMessage(target=\"agent_x\", ...)) where agent_x is not in this Swarm's participants; resuming a swarm run with a handoff message copied from a differently-composed team.","commonSituations":"Resuming after HandoffTermination and constructing the new task HandoffMessage with a stale or misspelled target; changing the participant roster between runs while reusing saved handoff messages.","solutions":["Set the HandoffMessage target to a name present in this Swarm's participants (match agent.name exactly).","When resuming from HandoffTermination, take the target from your new task design and verify against [p.name for p in participants].","Rebuild the swarm with the intended target participant if it was removed."],"exampleFix":"# before\nawait swarm.run(task=HandoffMessage(content=\"next\", target=\"helper\", source=\"researcher\"))  # no 'helper'\n\n# after\nawait swarm.run(task=HandoffMessage(content=\"next\", target=\"coder\", source=\"researcher\"))  # exact participant name","handlingStrategy":"validation","validationCode":"participant_names = [a.name for a in agents]\nif isinstance(task_message, HandoffMessage):\n    assert task_message.target in participant_names, f\"target must be one of {participant_names}\"","typeGuard":"def is_valid_handoff_target(msg: HandoffMessage, participant_names: Sequence[str]) -> bool:\n    return msg.target in participant_names","tryCatchPattern":null,"preventionTips":["When resuming a swarm, double-check the HandoffMessage target against current participants.","Keep a single source of truth for participant names and use it for both team construction and handoff targets."],"tags":["autogen","swarm","handoff","resume","validation"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}