microsoft/semantic-kernel · error · NotImplementedError

Subclasses should implement this method

Error message

Subclasses should implement this method

What it means

TerminationStrategy.should_agent_terminate is the abstract hook subclasses must implement; the base implementation unconditionally raises NotImplementedError. should_terminate dispatches to it per matching agent, so using the base class directly surfaces this error.

Source

Thrown at python/semantic_kernel/agents/strategies/termination/termination_strategy.py:36

@experimental
class TerminationStrategy(KernelBaseModel):
    """A strategy for determining when an agent should terminate."""

    maximum_iterations: int = Field(default=99)
    automatic_reset: bool = False
    agents: list[Agent] = Field(default_factory=list)

    async def should_agent_terminate(self, agent: "Agent", history: list["ChatMessageContent"]) -> bool:
        """Check if the agent should terminate.

        Args:
            agent: The agent to check.
            history: The history of messages in the conversation.

        Returns:
            True if the agent should terminate, False otherwise
        """
        raise NotImplementedError("Subclasses should implement this method")

    async def should_terminate(self, agent: "Agent", history: list["ChatMessageContent"]) -> bool:
        """Check if the agent should terminate.

        Args:
            agent: The agent to check.
            history: The history of messages in the conversation.

        Returns:
            True if the agent should terminate, False otherwise
        """
        logger.info(f"Evaluating termination criteria for {agent.id}")

        if self.agents and not any(a.id == agent.id for a in self.agents):
            logger.info(f"Agent {agent.id} is out of scope")
            return False

        should_terminate = await self.should_agent_terminate(agent, history)

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Subclass TerminationStrategy and implement `async def should_agent_terminate(self, agent, history) -> bool`.
  2. Use a built-in concrete strategy such as KernelFunctionTerminationStrategy.
  3. If you intended the default behavior, pick the appropriate built-in rather than the abstract base.

Example fix

// before
class MyTerm(TerminationStrategy):
    pass  # forgot to implement should_agent_terminate

// after
class MyTerm(TerminationStrategy):
    async def should_agent_terminate(self, agent, history) -> bool:
        return history[-1].content.strip().lower() == "done"
Defensive patterns

Strategy: type-guard

Validate before calling

import inspect
if type(strategy) is TerminationStrategy:
    raise TypeError('use a concrete subclass, not the abstract TerminationStrategy')
if 'should_agent_terminate' not in {n for _, n in inspect.getmembers(type(strategy), predicate=inspect.isfunction)}:
    # ensure the method is overridden, not inherited
    if type(strategy).should_agent_terminate is TerminationStrategy.should_agent_terminate:
        raise TypeError('subclass must override should_agent_terminate')

Type guard

def is_concrete_termination_strategy(strategy) -> bool:
    return type(strategy).should_agent_terminate is not TerminationStrategy.should_agent_terminate

Prevention

When it happens

Trigger: Instantiating the base TerminationStrategy (not a subclass) and running a chat that reaches termination evaluation, or calling should_agent_terminate directly on the base class.

Common situations: Using TerminationStrategy instead of a concrete subclass (e.g. KernelFunctionTerminationStrategy) or a custom subclass; forgetting to override should_agent_terminate when subclassing.

Related errors


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