microsoft/autogen · error · TypeError
{cls.__name__} is a namespace class and cannot be instantiat
Error message
{cls.__name__} is a namespace class and cannot be instantiated. What it means
ModelFamily is a namespace class (a typed container of string constants like ModelFamily.GPT_4O, CLAUDE_3_5_SONNET) with helper static methods such as is_claude/is_openai. Its __new__ unconditionally raises TypeError to prevent instantiation or accidental subclass-with-instance use. You are meant to reference its attributes and static methods only.
Source
Thrown at python/packages/autogen-core/src/autogen_core/models/_model_client.py:98
"claude-4-opus",
"claude-4-sonnet",
# llama_models
"llama-3.3-8b",
"llama-3.3-70b",
"llama-4-scout",
"llama-4-maverick",
# mistral_models
"codestral",
"open-codestral-mamba",
"mistral",
"ministral",
"pixtral",
# unknown
"unknown",
]
def __new__(cls, *args: Any, **kwargs: Any) -> ModelFamily:
raise TypeError(f"{cls.__name__} is a namespace class and cannot be instantiated.")
@staticmethod
def is_claude(family: str) -> bool:
return family in (
ModelFamily.CLAUDE_3_HAIKU,
ModelFamily.CLAUDE_3_SONNET,
ModelFamily.CLAUDE_3_OPUS,
ModelFamily.CLAUDE_3_5_HAIKU,
ModelFamily.CLAUDE_3_5_SONNET,
ModelFamily.CLAUDE_3_7_SONNET,
ModelFamily.CLAUDE_4_OPUS,
ModelFamily.CLAUDE_4_SONNET,
)
@staticmethod
def is_gemini(family: str) -> bool:
return family in (
ModelFamily.GEMINI_1_5_FLASH,View on GitHub (pinned to 027ecf0a37)
Solutions
- Use the string constants: pass `family=ModelFamily.GPT_4O` (or the plain string "gpt-4o") in ModelInfo.
- When deserializing, map strings to constants: `getattr(ModelFamily, name.upper())` or keep plain strings.
- Remove any `ModelFamily(...)` constructor calls; call static helpers as `ModelFamily.is_claude(family)`.
Example fix
# before
family = ModelFamily("gpt-4o") # TypeError: namespace class
# after
family = ModelFamily.GPT_4O # or the plain string "gpt-4o" Defensive patterns
Strategy: type-guard
Validate before calling
def resolve_family(name: str) -> str:
return getattr(ModelFamily, name.upper(), ModelFamily.UNKNOWN) Type guard
from autogen_core.models import ModelFamily
def is_model_family_value(v: object) -> bool:
return isinstance(v, str) and v in ModelFamily.__dict__.values().__iter__().__class__ and v in {
val for k, val in vars(ModelFamily).items() if not k.startswith("_") and isinstance(val, str)
} Prevention
- ModelFamily is a namespace of str constants: reference attributes, never construct it.
- Keep ModelInfo['family'] as a plain string in configs and map to constants only in code.
- Exclude ModelFamily-typed fields from reflective deserialization.
When it happens
Trigger: `ModelFamily()` or `ModelFamily("gpt-4o")` — e.g. trying to construct a family object from a config string; subclassing ModelFamily and instantiating the subclass (TypeError is inherited via __new__); frameworks that reflectively instantiate annotated classes when deserializing a config containing ModelFamily.
Common situations: Deserializing model configs where a field is typed ModelFamily and the loader instantiates the class instead of resolving a constant; copy-paste from code that uses model="gpt-4o" strings; assuming ModelFamily is an Enum whose members are constructed.
Related errors
- Missing required field '{field}' in ModelInfo. Starting in v
- Invalid arguments
- SubscriptionInstantiationContext cannot be instantiated. It
- String based function with requirement objects are not direc
- buffer_size must be greater than 0.
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/6c7ad5d80682a6d4.
Report an issue: GitHub.