microsoft/autogen · error · ValueError

Agent state for {name} not found in the saved state.

Error message

Agent state for {name} not found in the saved state.

What it means

load_state() validates that the saved TeamState contains an entry for every current participant by name. If a participant's name has no key in team_state.agent_states, the state was saved from a differently-composed team and cannot be applied.

Source

Thrown at python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat.py:818

        The state is loaded by calling the :meth:`~autogen_core.AgentRuntime.agent_load_state` method
        on each participant and the group chat manager with their internal agent ID.
        See :meth:`~autogen_agentchat.teams.BaseGroupChat.save_state` for the expected format of the state.
        """
        if not self._initialized:
            await self._init(self._runtime)

        if self._is_running:
            raise RuntimeError("The team cannot be loaded while it is running.")
        self._is_running = True

        try:
            team_state = TeamState.model_validate(state)
            # Load the state of all participants.
            for name, agent_type in zip(self._participant_names, self._participant_topic_types, strict=True):
                agent_id = AgentId(type=agent_type, key=self._team_id)
                if name not in team_state.agent_states:
                    raise ValueError(f"Agent state for {name} not found in the saved state.")
                await self._runtime.agent_load_state(agent_id, team_state.agent_states[name])
            # Load the state of the group chat manager.
            agent_id = AgentId(type=self._group_chat_manager_topic_type, key=self._team_id)
            if self._group_chat_manager_name not in team_state.agent_states:
                raise ValueError(f"Agent state for {self._group_chat_manager_name} not found in the saved state.")
            await self._runtime.agent_load_state(agent_id, team_state.agent_states[self._group_chat_manager_name])

        except ValidationError as e:
            raise ValueError(
                "Invalid state format. The expected state format has changed since v0.4.9. "
                "Please read the release note on GitHub."
            ) from e

        finally:
            # Indicate that the team is no longer running.
            self._is_running = False

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Reconstruct the team with exactly the same participant names as when the state was saved.
  2. Inspect saved['agent_states'].keys() and the team's participant names, then reconcile (rename agents or re-save state).
  3. If a participant is genuinely new, either exclude it or initialize its state manually instead of using the team-level load.

Example fix

# before
team = RoundRobinGroupChat([assistant, critic])  # state saved with only [assistant]
await team.load_state(saved)  # ValueError: Agent state for critic not found

# after
team = RoundRobinGroupChat([assistant])  # match the saved composition
await team.load_state(saved)
Defensive patterns

Strategy: validation

Validate before calling

expected = set(team._participant_names) | {team._group_chat_manager_name}
if not expected <= set(state["agent_states"]):
    missing = expected - set(state["agent_states"])
    raise ValueError(f"state does not match team composition; missing: {missing}")
await team.load_state(state)

Prevention

When it happens

Trigger: Calling load_state(saved) where the team now has an agent (e.g. 'critic') that did not exist — or was named differently — when save_state() was called; also when the saved dict was hand-edited or truncated.

Common situations: Adding/removing/renaming agents between sessions; loading a checkpoint into a team built from different config; partial state files from interrupted saves.

Related errors


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