{"record":{"id":"9b30791a4cb4b632","repo":"microsoft/autogen","slug":"no-serializers-found-for-type-t","errorCode":null,"errorMessage":"No serializers found for type {t}.","messagePattern":"No serializers found for type (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"python/packages/autogen-core/src/autogen_core/_routed_agent.py","lineNumber":515,"sourceCode":"            if callable(getattr(cls, attr, None)):\n                # Since we are getting it from the class, self is not bound\n                handler = getattr(cls, attr)\n                if hasattr(handler, \"is_message_handler\"):\n                    handlers.append(cast(MessageHandler[Any, Any, Any], handler))\n        return handlers\n\n    @classmethod\n    def _handles_types(cls) -> List[Tuple[Type[Any], List[MessageSerializer[Any]]]]:\n        # TODO handle deduplication\n        handlers = cls._discover_handlers()\n        types: List[Tuple[Type[Any], List[MessageSerializer[Any]]]] = []\n        types.extend(cls.internal_extra_handles_types)\n        for handler in handlers:\n            for t in handler.target_types:\n                # TODO: support different serializers\n                serializers = try_get_known_serializers_for_type(t)\n                if len(serializers) == 0:\n                    raise ValueError(f\"No serializers found for type {t}.\")\n\n                types.append((t, try_get_known_serializers_for_type(t)))\n        return types\n","sourceCodeStart":497,"sourceCodeEnd":519,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-core/src/autogen_core/_routed_agent.py#L497-L519","documentation":"RoutedAgent._handles_types() walks every handler's target types and calls try_get_known_serializers_for_type for each; if no serializer can be found for a type, ValueError is raised when the agent's type metadata is built (typically at runtime/agent-type registration, blocking startup). This means the annotated message class is neither a supported serializable model nor one with a registered serializer.","triggerScenarios":"Annotating a handler with a plain Python class, TypedDict, dataclass, or non-pydantic type with no serializer registered; annotating with types from other frameworks; using a type that is pydantic but fails its known-serializer detection.","commonSituations":"Using dataclasses or TypedDicts instead of pydantic BaseModel for messages; forgetting to register a custom serializer via a serialization registry before constructing/registering the agent runtime; annotating handler parameters with helper or generic types accidentally exposed in a union.","solutions":["Define message types as pydantic BaseModel subclasses (pydantic-based serialization is auto-detected)","If the type cannot be a BaseModel, register a serializer for it (e.g. a MessageSerializer implementation added to the type registry / try_get_known_serializers_for_type path) before creating the agent runtime","Remove non-message types (str, int, helper classes) accidentally included in the handler's message annotation union"],"exampleFix":"# before\n@rpc\nasync def handle(self, message: AskDict, ctx: MessageContext) -> None: ...  # AskDict is a TypedDict\n\n# after\nfrom pydantic import BaseModel\n\nclass Ask(BaseModel):\n    query: str\n\n@rpc\nasync def handle(self, message: Ask, ctx: MessageContext) -> None: ...","handlingStrategy":"validation","validationCode":"from pydantic import BaseModel\nfrom autogen_core import try_get_known_serializers_for_type\n\ndef all_handler_types_serializable(agent_cls) -> bool:\n    for t, _ in agent_cls._handles_types():\n        pass\n    return True  # _handles_types raises ValueError for unserializable types\n\ndef type_is_serializable(t: type) -> bool:\n    if issubclass(t, BaseModel):\n        return True\n    return len(try_get_known_serializers_for_type(t)) > 0","typeGuard":"from pydantic import BaseModel\nfrom autogen_core import try_get_known_serializers_for_type\n\ndef has_serializer(t: type) -> bool:\n    return issubclass(t, BaseModel) or len(try_get_known_serializers_for_type(t)) > 0","tryCatchPattern":"try:\n    await runtime.register_agent_type(agent_type)\nexcept ValueError as e:\n    if \"No serializers found\" in str(e):\n        # convert the annotated type to a pydantic BaseModel or register a serializer, then retry\n        raise","preventionTips":["Model every message/request/response as a pydantic BaseModel subclass from day one","Never annotate handler parameters with builtin/helper types (str, int, dict, dataclasses)","Register custom MessageSerializer implementations before constructing or registering the runtime","Add a startup test that instantiates and registers every agent type to fail fast on serialization gaps"],"tags":["python","serialization","pydantic","startup","autogen-core"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}