{"record":{"id":"887f6a9565d18837","repo":"microsoft/autogen","slug":"message-type-msg-class-is-not-registered-wit","errorCode":null,"errorMessage":"Message type {msg.__class__} is not registered with the message factory. Please register it with the message factory by adding it to the custom_message_types list when creating the team.","messagePattern":"Message type (.+?) is not registered with the message factory\\. Please register it with the message factory by adding it to the custom_message_types list when creating the team\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat.py","lineNumber":477,"sourceCode":"        elif isinstance(task, str):\n            messages = [TextMessage(content=task, source=\"user\")]\n        elif isinstance(task, BaseChatMessage):\n            messages = [task]\n        elif isinstance(task, list):\n            if not task:\n                raise ValueError(\"Task list cannot be empty.\")\n            messages = []\n            for msg in task:\n                if not isinstance(msg, BaseChatMessage):\n                    raise ValueError(\"All messages in task list must be valid BaseChatMessage types\")\n                messages.append(msg)\n        else:\n            raise ValueError(\"Task must be a string, a BaseChatMessage, or a list of BaseChatMessage.\")\n        # Check if the messages types are registered with the message factory.\n        if messages is not None:\n            for msg in messages:\n                if not self._message_factory.is_registered(msg.__class__):\n                    raise ValueError(\n                        f\"Message type {msg.__class__} is not registered with the message factory. \"\n                        \"Please register it with the message factory by adding it to the \"\n                        \"custom_message_types list when creating the team.\"\n                    )\n\n        if self._is_running:\n            raise ValueError(\"The team is already running, it cannot run again until it is stopped.\")\n        self._is_running = True\n\n        if self._embedded_runtime:\n            # Start the embedded runtime.\n            assert isinstance(self._runtime, SingleThreadedAgentRuntime)\n            self._runtime.start()\n\n        if not self._initialized:\n            await self._init(self._runtime)\n\n        shutdown_task: asyncio.Task[None] | None = None","sourceCodeStart":459,"sourceCodeEnd":495,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat.py#L459-L495","documentation":"Before a run starts, the team verifies every message in the task is a class known to its MessageFactory so that serialization/round-trip of the session will work. Custom message types must be declared via custom_message_types at team construction; built-ins are registered automatically.","triggerScenarios":"team.run_stream(task=[MyCustomMessage(...)]) when MyCustomMessage was not listed in custom_message_types when the team was created. Registration cannot be done after construction, so this check fails the run before any agent executes.","commonSituations":"An agent returns a custom message type that was registered for the agent but the user forgot the matching custom_message_types entry on the team; adding a new custom message class to an agent without updating the team constructor.","solutions":["Recreate the team with custom_message_types=[MyCustomMessage, ...] included.","Keep a single module-level list of all custom message classes and pass it to every team constructor.","As a stopgap, convert the custom message to a TextMessage before passing it as a task."],"exampleFix":"# before\nteam = RoundRobinGroupChat([agent])  # agent produces MyCustomMessage\nawait team.run(task=[MyCustomMessage(content=\"x\")])  # ValueError\n\n# after\nteam = RoundRobinGroupChat([agent], custom_message_types=[MyCustomMessage])\nawait team.run(task=[MyCustomMessage(content=\"x\")])","handlingStrategy":"validation","validationCode":"CUSTOM_MESSAGES = [MyCustomMessage, OtherCustomMessage]  # single source of truth\nteam = RoundRobinGroupChat(agents, custom_message_types=CUSTOM_MESSAGES)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Maintain one module-level list of custom message types and pass it to every team constructor.","When an agent's produced_message_types includes a custom class, mirror it in the team config.","Add a startup check comparing agent.produced_message_types against the team's registered types."],"tags":["python","autogen","custom-message","message-factory","task"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}