microsoft/autogen · error · ValueError

Invalid next speaker: {next_speaker} from the ledger, partic

Error message

Invalid next speaker: {next_speaker} from the ledger, participants are: {self._participant_names}

What it means

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.

Source

Thrown at python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_magentic_one/_magentic_one_orchestrator.py:432

        await self.publish_message(
            GroupChatMessage(message=message),
            topic_id=DefaultTopicId(type=self._output_topic_type),
        )
        # Log it to the output queue.
        await self._output_message_queue.put(message)

        # Broadcast it
        await self.publish_message(  # Broadcast
            GroupChatAgentResponse(response=Response(chat_message=message), name=self._name),
            topic_id=DefaultTopicId(type=self._group_topic_type),
            cancellation_token=cancellation_token,
        )

        # Request that the step be completed
        next_speaker = progress_ledger["next_speaker"]["answer"]
        # Check if the next speaker is valid
        if next_speaker not in self._participant_name_to_topic_type:
            raise ValueError(
                f"Invalid next speaker: {next_speaker} from the ledger, participants are: {self._participant_names}"
            )
        participant_topic_type = self._participant_name_to_topic_type[next_speaker]
        await self.publish_message(
            GroupChatRequestPublish(),
            topic_id=DefaultTopicId(type=participant_topic_type),
            cancellation_token=cancellation_token,
        )

        # Send the message to the next speaker
        if self._emit_team_events:
            select_msg = SelectSpeakerEvent(content=[next_speaker], source=self._name)
            await self.publish_message(
                GroupChatMessage(message=select_msg),
                topic_id=DefaultTopicId(type=self._output_topic_type),
            )
            await self._output_message_queue.put(select_msg)

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Give participants short, unambiguous, distinct names; avoid names the model tends to conflate.
  2. Use a stronger model for MagenticOneGroupChat's model_client so the ledger follows the provided participant list.
  3. Catch the ValueError, call await team.reset() (or resume with a corrected thread) and re-run the task.
  4. Make sure participant descriptions make each agent's role/name clear in the orchestrator prompt context.

Example fix

# before
agents = [
    AssistantAgent("helper", ...),
    AssistantAgent("Helper2", ...),  # near-duplicate names invite hallucinated speakers
]

# after
agents = [
    AssistantAgent("researcher", ...),
    AssistantAgent("coder", ...),
    AssistantAgent("reviewer", ...),
]
Defensive patterns

Strategy: fallback

Try / catch

try:
    result = await team.run(task=task)
except ValueError as e:
    if "Invalid next speaker" in str(e):
        await team.reset()
        result = await team.run(task=task)  # retry; hallucinated name is nondeterministic
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/c70144f6f0a8f248. Report an issue: GitHub.