{"record":{"id":"528fac585e693727","repo":"microsoft/autogen","slug":"invalid-message-type-in-message-buffer-type-mess","errorCode":null,"errorMessage":"Invalid message type in message buffer: {type(message)}","messagePattern":"Invalid message type in message buffer: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_chat_agent_container.py","lineNumber":212,"sourceCode":"    async def on_unhandled_message(self, message: Any, ctx: MessageContext) -> None:\n        raise ValueError(f\"Unhandled message in agent container: {type(message)}\")\n\n    async def save_state(self) -> Mapping[str, Any]:\n        agent_state = await self._agent.save_state()\n        state = ChatAgentContainerState(\n            agent_state=agent_state, message_buffer=[message.dump() for message in self._message_buffer]\n        )\n        return state.model_dump()\n\n    async def load_state(self, state: Mapping[str, Any]) -> None:\n        container_state = ChatAgentContainerState.model_validate(state)\n        self._message_buffer = []\n        for message_data in container_state.message_buffer:\n            message = self._message_factory.create(message_data)\n            if isinstance(message, BaseChatMessage):\n                self._message_buffer.append(message)\n            else:\n                raise ValueError(f\"Invalid message type in message buffer: {type(message)}\")\n        await self._agent.load_state(container_state.agent_state)\n","sourceCodeStart":194,"sourceCodeEnd":214,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_chat_agent_container.py#L194-L214","documentation":"Raised by ChatAgentContainer.load_state when deserializing a saved container state whose message buffer contains an entry that the MessageFactory resolves to something that is not a BaseChatMessage (e.g. an event type, or a payload whose 'type' field maps to the wrong class). The buffer must hold chat messages only; anything else corrupts the agent's input history, so loading is aborted.","triggerScenarios":"Calling team.load_state(saved_state) where the checkpoint was produced by a different team configuration whose message factory maps the same type string to a non-message class; hand-editing checkpoint JSON and putting an event type in message_buffer; version upgrade changing factory type mappings.","commonSituations":"Persisting team state across service restarts; sharing checkpoints between environments with different custom_message_types declarations; schema drift after a library upgrade.","solutions":["Load state only into a team constructed with the same participants and custom_message_types as when it was saved.","Validate checkpoint JSON before loading: every message_buffer entry must deserialize to a chat message type.","Regenerate checkpoints after upgrading autogen versions or changing custom message type registrations."],"exampleFix":"// before\nteam2 = RoundRobinGroupChat([agent_b])  # different config\nawait team2.load_state(saved_state)  # buffer types mismatch\n\n// after\nteam2 = RoundRobinGroupChat([agent_a], custom_message_types=[MyMsg])  # same as save-time config\nawait team2.load_state(saved_state)","handlingStrategy":"validation","validationCode":"from autogen_agentchat.messages import MessageFactory\nfactory = MessageFactory()\nfor custom in CUSTOM_TYPES:\n    factory.register_message_type(custom)\nstate = json.load(open(\"checkpoint.json\"))\nfor node_state in _iter_agent_states(state):\n    for entry in node_state.get(\"message_buffer\", []):\n        obj = factory.create(entry)\n        if not isinstance(obj, BaseChatMessage):\n            raise ValueError(f\"Checkpoint contains non-message entry of type {type(obj)}\")","typeGuard":"def is_chat_message_payload(factory: MessageFactory, data: dict) -> bool:\n    return isinstance(factory.create(data), BaseChatMessage)","tryCatchPattern":"try:\n    await team.load_state(saved)\nexcept ValueError as e:\n    if \"Invalid message type in message buffer\" in str(e):\n        # checkpoint incompatible with current team config; rebuild config or regenerate checkpoint\n        ...","preventionTips":["Save and load with identical team configurations (participants and custom_message_types).","Version your checkpoints and record the config fingerprint alongside.","Regenerate checkpoints after library upgrades or custom-type changes."],"tags":["state","serialization","checkpoints","messages"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}