{"record":{"id":"c70144f6f0a8f248","repo":"microsoft/autogen","slug":"invalid-next-speaker-next-speaker-from-the-ledg","errorCode":null,"errorMessage":"Invalid next speaker: {next_speaker} from the ledger, participants are: {self._participant_names}","messagePattern":"Invalid next speaker: (.+?) from the ledger, participants are: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_magentic_one/_magentic_one_orchestrator.py","lineNumber":432,"sourceCode":"        await self.publish_message(\n            GroupChatMessage(message=message),\n            topic_id=DefaultTopicId(type=self._output_topic_type),\n        )\n        # Log it to the output queue.\n        await self._output_message_queue.put(message)\n\n        # Broadcast it\n        await self.publish_message(  # Broadcast\n            GroupChatAgentResponse(response=Response(chat_message=message), name=self._name),\n            topic_id=DefaultTopicId(type=self._group_topic_type),\n            cancellation_token=cancellation_token,\n        )\n\n        # Request that the step be completed\n        next_speaker = progress_ledger[\"next_speaker\"][\"answer\"]\n        # Check if the next speaker is valid\n        if next_speaker not in self._participant_name_to_topic_type:\n            raise ValueError(\n                f\"Invalid next speaker: {next_speaker} from the ledger, participants are: {self._participant_names}\"\n            )\n        participant_topic_type = self._participant_name_to_topic_type[next_speaker]\n        await self.publish_message(\n            GroupChatRequestPublish(),\n            topic_id=DefaultTopicId(type=participant_topic_type),\n            cancellation_token=cancellation_token,\n        )\n\n        # Send the message to the next speaker\n        if self._emit_team_events:\n            select_msg = SelectSpeakerEvent(content=[next_speaker], source=self._name)\n            await self.publish_message(\n                GroupChatMessage(message=select_msg),\n                topic_id=DefaultTopicId(type=self._output_topic_type),\n            )\n            await self._output_message_queue.put(select_msg)\n","sourceCodeStart":414,"sourceCodeEnd":450,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_magentic_one/_magentic_one_orchestrator.py#L414-L450","documentation":"The MagenticOne orchestrator raises ValueError when the ledger's next_speaker.answer is not a name in the participant-to-topic mapping. The orchestrator must publish GroupChatRequestPublish to the next speaker's topic, so an unknown name has no route.","triggerScenarios":"The ledger model hallucinates a speaker name ('Planner' when no such participant exists), returns a name with different casing/whitespace, or the model was not shown the current participant list in its context.","commonSituations":"Long conversations where the model forgets exact agent names; participants added/renamed between runs while reusing a saved thread; single-agent teams are special-cased, so this only fires with 2+ participants.","solutions":["Give participants short, unambiguous, distinct names; avoid names the model tends to conflate.","Use a stronger model for MagenticOneGroupChat's model_client so the ledger follows the provided participant list.","Catch the ValueError, call await team.reset() (or resume with a corrected thread) and re-run the task.","Make sure participant descriptions make each agent's role/name clear in the orchestrator prompt context."],"exampleFix":"# before\nagents = [\n    AssistantAgent(\"helper\", ...),\n    AssistantAgent(\"Helper2\", ...),  # near-duplicate names invite hallucinated speakers\n]\n\n# after\nagents = [\n    AssistantAgent(\"researcher\", ...),\n    AssistantAgent(\"coder\", ...),\n    AssistantAgent(\"reviewer\", ...),\n]","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    result = await team.run(task=task)\nexcept ValueError as e:\n    if \"Invalid next speaker\" in str(e):\n        await team.reset()\n        result = await team.run(task=task)  # retry; hallucinated name is nondeterministic\n    else:\n        raise","preventionTips":["Use short, unique, role-distinct participant names.","Keep participant count modest so the ledger model tracks names correctly.","Avoid renaming participants mid-project while reusing saved threads."],"tags":["autogen","magentic-one","next-speaker","llm-output","routing"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}