{"record":{"id":"575e298eec5054a7","repo":"microsoft/autogen","slug":"agent-state-for-name-not-found-in-the-saved-stat","errorCode":null,"errorMessage":"Agent state for {name} not found in the saved state.","messagePattern":"Agent state for (.+?) not found in the saved state\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat.py","lineNumber":818,"sourceCode":"\n        The state is loaded by calling the :meth:`~autogen_core.AgentRuntime.agent_load_state` method\n        on each participant and the group chat manager with their internal agent ID.\n        See :meth:`~autogen_agentchat.teams.BaseGroupChat.save_state` for the expected format of the state.\n        \"\"\"\n        if not self._initialized:\n            await self._init(self._runtime)\n\n        if self._is_running:\n            raise RuntimeError(\"The team cannot be loaded while it is running.\")\n        self._is_running = True\n\n        try:\n            team_state = TeamState.model_validate(state)\n            # Load the state of all participants.\n            for name, agent_type in zip(self._participant_names, self._participant_topic_types, strict=True):\n                agent_id = AgentId(type=agent_type, key=self._team_id)\n                if name not in team_state.agent_states:\n                    raise ValueError(f\"Agent state for {name} not found in the saved state.\")\n                await self._runtime.agent_load_state(agent_id, team_state.agent_states[name])\n            # Load the state of the group chat manager.\n            agent_id = AgentId(type=self._group_chat_manager_topic_type, key=self._team_id)\n            if self._group_chat_manager_name not in team_state.agent_states:\n                raise ValueError(f\"Agent state for {self._group_chat_manager_name} not found in the saved state.\")\n            await self._runtime.agent_load_state(agent_id, team_state.agent_states[self._group_chat_manager_name])\n\n        except ValidationError as e:\n            raise ValueError(\n                \"Invalid state format. The expected state format has changed since v0.4.9. \"\n                \"Please read the release note on GitHub.\"\n            ) from e\n\n        finally:\n            # Indicate that the team is no longer running.\n            self._is_running = False\n","sourceCodeStart":800,"sourceCodeEnd":835,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat.py#L800-L835","documentation":"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.","triggerScenarios":"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.","commonSituations":"Adding/removing/renaming agents between sessions; loading a checkpoint into a team built from different config; partial state files from interrupted saves.","solutions":["Reconstruct the team with exactly the same participant names as when the state was saved.","Inspect saved['agent_states'].keys() and the team's participant names, then reconcile (rename agents or re-save state).","If a participant is genuinely new, either exclude it or initialize its state manually instead of using the team-level load."],"exampleFix":"# before\nteam = RoundRobinGroupChat([assistant, critic])  # state saved with only [assistant]\nawait team.load_state(saved)  # ValueError: Agent state for critic not found\n\n# after\nteam = RoundRobinGroupChat([assistant])  # match the saved composition\nawait team.load_state(saved)","handlingStrategy":"validation","validationCode":"expected = set(team._participant_names) | {team._group_chat_manager_name}\nif not expected <= set(state[\"agent_states\"]):\n    missing = expected - set(state[\"agent_states\"])\n    raise ValueError(f\"state does not match team composition; missing: {missing}\")\nawait team.load_state(state)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Store team composition (participant names) alongside saved state and verify before load.","Rebuild teams with the exact same agent names as when the state was saved.","Treat agent roster changes as requiring a new conversation, not a state load."],"tags":["python","autogen","state","save-load","participants"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}