microsoft/semantic-kernel · error · TypeError

Orchestration must be subclassed with two type parameters.

Error message

Orchestration must be subclassed with two type parameters.

What it means

When __orig_class__ is absent (i.e. you subclassed OrchestrationBase rather than subscripting an instance), _set_types falls back to __orig_bases__[0] and reads its type args. It requires exactly two args there; anything else (zero, one, three) is rejected. This is the path for declarative subclassing.

Source

Thrown at python/semantic_kernel/agents/orchestration/orchestration_base.py:174

        """
        if all([self.t_in is not None, self.t_out is not None]):
            return

        try:
            args = self.__orig_class__.__args__  # type: ignore[attr-defined]
            if len(args) == 1:
                self.t_in = args[0]
                self.t_out = DefaultTypeAlias  # type: ignore[assignment]
            elif len(args) == 2:
                self.t_in = args[0]
                self.t_out = args[1]
            else:
                raise TypeError("Orchestration must have two type parameters.")
        except AttributeError:
            args = get_args(self.__orig_bases__[0])  # type: ignore[attr-defined]

            if len(args) != 2:
                raise TypeError("Orchestration must be subclassed with two type parameters.")
            self.t_in = args[0] if isinstance(args[0], type) else getattr(args[0], "__default__", None)  # type: ignore[assignment]
            self.t_out = args[1] if isinstance(args[1], type) else getattr(args[1], "__default__", None)  # type: ignore[assignment]

        if any([self.t_in is None, self.t_out is None]):
            raise TypeError("Orchestration must have concrete types for all type parameters.")

    async def invoke(
        self,
        task: str | DefaultTypeAlias | TIn,
        runtime: CoreRuntime,
    ) -> OrchestrationResult[TOut]:
        """Invoke the multi-agent orchestration.

        This method is non-blocking and will return immediately.
        To wait for the result, use the `get` method of the `OrchestrationResult` object.

        Args:
            task (str, DefaultTypeAlias, TIn): The task to be executed by the agents.

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Subclass with exactly two type parameters: `class MyOrchestration(OrchestrationBase[str, str]): ...`.
  2. If using custom TypeVars, provide both: `class MyOrchestration(OrchestrationBase[TIn, TOut]): ...`.
  3. Prefer subscripting at instantiation (`OrchestrationBase[str, str](...)`) if you don't need a named subclass.

Example fix

// before
class MyOrchestration(OrchestrationBase):  # no type params
    pass

MyOrchestration(members)  # raises 'must be subclassed with two type parameters'

// after
class MyOrchestration(OrchestrationBase[str, str]):
    pass

MyOrchestration(members)
Defensive patterns

Strategy: type-guard

Validate before calling

# Subclass with exactly two type parameters
class MyOrchestration(OrchestrationBase[str, str]):
    pass

orch = MyOrchestration(members)

Type guard

from typing import get_args

def subclass_has_two_params(cls) -> bool:
    bases = getattr(cls, "__orig_bases__", ())
    if not bases:
        return False
    return len(get_args(bases[0])) == 2

Prevention

When it happens

Trigger: Declaring `class MyOrchestration(OrchestrationBase):` (no type params) or with a count other than two, then instantiating it directly so __orig_class__ is not set and the __orig_bases__ branch runs.

Common situations: Subclassing OrchestrationBase without specifying TypeVars, e.g. `class Foo(OrchestrationBase): pass; Foo(members)`. Subclassing with a single TypeVar. A subclass that loses its generic parameterization.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/a0f689e04866db62. Report an issue: GitHub.