{"record":{"id":"525d26919c1cee36","repo":"microsoft/autogen","slug":"message-type-message-class-is-not-registered","errorCode":null,"errorMessage":"Message type {message.__class__} is not registered.","messagePattern":"Message type (.+?) is not registered\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_chat_agent_container.py","lineNumber":163,"sourceCode":"                    await self.publish_message(\n                        GroupChatAgentResponse(response=response, name=self._agent.name),\n                        topic_id=DefaultTopicId(type=self._parent_topic_type),\n                        cancellation_token=ctx.cancellation_token,\n                    )\n                except Exception as e:\n                    # Publish the error to the group chat.\n                    error_message = SerializableException.from_exception(e)\n                    await self.publish_message(\n                        GroupChatError(error=error_message),\n                        topic_id=DefaultTopicId(type=self._parent_topic_type),\n                        cancellation_token=ctx.cancellation_token,\n                    )\n                    # Raise the error to the runtime.\n                    raise\n\n    def _buffer_message(self, message: BaseChatMessage) -> None:\n        if not self._message_factory.is_registered(message.__class__):\n            raise ValueError(f\"Message type {message.__class__} is not registered.\")\n        # Buffer the message.\n        self._message_buffer.append(message)\n\n    async def _log_message(self, message: BaseAgentEvent | BaseChatMessage) -> None:\n        if not self._message_factory.is_registered(message.__class__):\n            raise ValueError(f\"Message type {message.__class__} is not registered.\")\n        # Log the message.\n        await self.publish_message(\n            GroupChatMessage(message=message),\n            topic_id=DefaultTopicId(type=self._output_topic_type),\n        )\n\n    @rpc\n    async def handle_pause(self, message: GroupChatPause, ctx: MessageContext) -> None:\n        \"\"\"Handle a pause event by pausing the agent.\"\"\"\n        if isinstance(self._agent, Team):\n            # If the agent is a team, pause the team.\n            await self._agent.pause()","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_chat_agent_container.py#L145-L181","documentation":"Raised by ChatAgentContainer._buffer_message when an incoming chat message's class is not registered with the team's MessageFactory. The factory only knows the built-in message types plus any types you declared via custom_message_types when creating the team; any other message type arriving in a participant's buffer (e.g., from the initial task, another agent's output, or a checkpoint replay) is rejected before buffering.","triggerScenarios":"Passing a custom BaseChatMessage subclass as the task input to team.run() without listing it in the team's custom_message_types; an agent producing a custom message type the team doesn't know; restoring state containing messages of an unregistered type.","commonSituations":"Defining domain-specific message classes for structured agent output; switching from passing strings/TextMessage to a custom type; teams created before the custom_message_types parameter existed (older autogen versions used message_factory instead).","solutions":["Pass your message class in custom_message_types=[MyMessageType] when constructing the team (RoundRobin, Selector, Swarm, MagenticOne, GraphFlow all accept it).","Ensure the custom type subclasses BaseChatMessage (or BaseAgentEvent for events) and implements serialization properly.","On version upgrades, migrate old message_factory-based configuration to custom_message_types."],"exampleFix":"// before\nteam = SelectorGroupChat(participants, model_client=client)  # MyApproval type unknown\nawait team.run(task=MyApproval(approved=True))\n\n// after\nteam = SelectorGroupChat(participants, model_client=client,\n    custom_message_types=[MyApproval])\nawait team.run(task=MyApproval(approved=True))","handlingStrategy":"type-guard","validationCode":"from autogen_agentchat.messages import MessageFactory\nfactory = MessageFactory()\nfor t in CUSTOM_TYPES:\n    factory.register_message_type(t)\nassert factory.is_registered(MyApproval), \"register MyApproval via custom_message_types\"","typeGuard":"def all_input_types_registered(task_msgs, team_custom_types: set[type]) -> bool:\n    return all(type(m) in team_custom_types or type(m).__name__ in BUILTIN_MESSAGE_TYPES for m in task_msgs)","tryCatchPattern":"try:\n    await team.run(task=my_msg)\nexcept ValueError as e:\n    if \"is not registered\" in str(e):\n        # add type(my_msg) to the team's custom_message_types and recreate the team\n        ...","preventionTips":["Maintain one module-level CUSTOM_TYPES list and pass it to every team constructor.","Subclass BaseChatMessage/BaseAgentEvent for custom types; strings and TextMessage need no registration.","After adding a custom type to an agent, update all teams hosting that agent."],"tags":["messages","custom-message-types","configuration","serialization"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}