{"record":{"id":"6cbbdcffdec44808","repo":"microsoft/autogen","slug":"component-type-not-defined","errorCode":null,"errorMessage":"component_type not defined","messagePattern":"component_type not defined","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-core/src/autogen_core/_component_config.py","lineNumber":169,"sourceCode":"        Returns:\n            ComponentModel: The model representing the component.\n        \"\"\"\n        if self.component_provider_override is not None:\n            provider = self.component_provider_override\n        else:\n            provider = _type_to_provider_str(self.__class__)\n            # Warn if internal module name is used,\n            if \"._\" in provider:\n                warnings.warn(\n                    \"Internal module name used in provider string. This is not recommended and may cause issues in the future. Silence this warning by setting component_provider_override to this value.\",\n                    stacklevel=2,\n                )\n\n        if \"<locals>\" in provider:\n            raise TypeError(\"Cannot dump component with local class\")\n\n        if not hasattr(self, \"component_type\"):\n            raise AttributeError(\"component_type not defined\")\n\n        description = self.component_description\n        if description is None and self.__class__.__doc__:\n            # use docstring as description\n            docstring = self.__class__.__doc__.strip()\n            for marker in [\"\\n\\nArgs:\", \"\\n\\nParameters:\", \"\\n\\nAttributes:\", \"\\n\\n\"]:\n                docstring = docstring.split(marker)[0]\n            description = docstring.strip()\n\n        obj_config = self._to_config().model_dump(exclude_none=True)\n        model = ComponentModel(\n            provider=provider,\n            component_type=self.component_type,\n            version=self.component_version,\n            component_version=self.component_version,\n            description=description,\n            label=self.component_label or self.__class__.__name__,\n            config=obj_config,","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-core/src/autogen_core/_component_config.py#L151-L187","documentation":"dump_component requires the ClassVar component_type to label the ComponentModel. The implementation checks hasattr(self, 'component_type'); inheriting from ComponentToConfig/ComponentBase without setting component_type (it is declared but only as a ClassVar annotation without a default on ComponentToConfig) leaves the attribute missing, so AttributeError is raised.","triggerScenarios":"class MyComp(ComponentToConfig): pass (no component_type assignment) then MyComp().dump_component(); overriding component_type with None; typos like component_typ.","commonSituations":"Minimal component subclasses written from examples that omit the field; copy-paste from a protocol stub; subclasses that delete the attribute.","solutions":["Declare component_type on the subclass: component_type: ClassVar[ComponentType] = ComponentType.model (or the appropriate enum value).","Also set component_version (defaults to 1) and optionally component_description/label.","Add a trivial test that calls dump_component() to catch missing metadata early."],"exampleFix":"# before\nclass MyComp(ComponentToConfig):\n    def _to_config(self) -> MyConfig: ...\n# MyComp().dump_component() -> AttributeError\n\n# after\nfrom autogen_core import ComponentType\n\nclass MyComp(ComponentToConfig):\n    component_type: ClassVar[ComponentType] = ComponentType.model\n    component_version: ClassVar[int] = 1\n\n    def _to_config(self) -> MyConfig: ...","handlingStrategy":"validation","validationCode":"if not hasattr(MyComp, \"component_type\"):\n    raise TypeError(\"set component_type: ClassVar[ComponentType] on the subclass\")","typeGuard":"def has_component_type(cls: type) -> bool:\n    return hasattr(cls, \"component_type\") and cls.component_type is not None","tryCatchPattern":"try:\n    model = comp.dump_component()\nexcept AttributeError as e:\n    if \"component_type\" in str(e):\n        # add the missing ClassVar and retry\n        raise\n    raise","preventionTips":["Declare component_type (and component_version) on every component subclass.","Write a tiny pytest that calls dump_component() for each registered component.","Use a shared base class in your project that enforces the metadata."],"tags":["autogen-core","component-config","classvar","dump"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}