microsoft/autogen · error · AttributeError
component_type not defined
Error message
component_type not defined
What it means
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.
Source
Thrown at python/packages/autogen-core/src/autogen_core/_component_config.py:169
Returns:
ComponentModel: The model representing the component.
"""
if self.component_provider_override is not None:
provider = self.component_provider_override
else:
provider = _type_to_provider_str(self.__class__)
# Warn if internal module name is used,
if "._" in provider:
warnings.warn(
"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.",
stacklevel=2,
)
if "<locals>" in provider:
raise TypeError("Cannot dump component with local class")
if not hasattr(self, "component_type"):
raise AttributeError("component_type not defined")
description = self.component_description
if description is None and self.__class__.__doc__:
# use docstring as description
docstring = self.__class__.__doc__.strip()
for marker in ["\n\nArgs:", "\n\nParameters:", "\n\nAttributes:", "\n\n"]:
docstring = docstring.split(marker)[0]
description = docstring.strip()
obj_config = self._to_config().model_dump(exclude_none=True)
model = ComponentModel(
provider=provider,
component_type=self.component_type,
version=self.component_version,
component_version=self.component_version,
description=description,
label=self.component_label or self.__class__.__name__,
config=obj_config,View on GitHub (pinned to 027ecf0a37)
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.
Example fix
# before
class MyComp(ComponentToConfig):
def _to_config(self) -> MyConfig: ...
# MyComp().dump_component() -> AttributeError
# after
from autogen_core import ComponentType
class MyComp(ComponentToConfig):
component_type: ClassVar[ComponentType] = ComponentType.model
component_version: ClassVar[int] = 1
def _to_config(self) -> MyConfig: ... Defensive patterns
Strategy: validation
Validate before calling
if not hasattr(MyComp, "component_type"):
raise TypeError("set component_type: ClassVar[ComponentType] on the subclass") Type guard
def has_component_type(cls: type) -> bool:
return hasattr(cls, "component_type") and cls.component_type is not None Try / catch
try:
model = comp.dump_component()
except AttributeError as e:
if "component_type" in str(e):
# add the missing ClassVar and retry
raise
raise Prevention
- 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.
When it happens
Trigger: class MyComp(ComponentToConfig): pass (no component_type assignment) then MyComp().dump_component(); overriding component_type with None; typos like component_typ.
Common situations: Minimal component subclasses written from examples that omit the field; copy-paste from a protocol stub; subclasses that delete the attribute.
Related errors
- Cannot dump component with local class
- This component does not support dumping to config
- This component does not support loading from past versions
- Invalid
- Invalid agent type: {type}. Allowed values MUST match the re
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/6cbbdcffdec44808.
Report an issue: GitHub.