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

  1. Use the string constants: pass `family=ModelFamily.GPT_4O` (or the plain string "gpt-4o") in ModelInfo.
  2. When deserializing, map strings to constants: `getattr(ModelFamily, name.upper())` or keep plain strings.
  3. 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

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


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/6c7ad5d80682a6d4. Report an issue: GitHub.