{"record":{"id":"acefc76d9d27c81e","repo":"microsoft/semantic-kernel","slug":"subclasses-should-implement-this-method-acefc7","errorCode":null,"errorMessage":"Subclasses should implement this method","messagePattern":"Subclasses should implement this method","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/strategies/termination/termination_strategy.py","lineNumber":36,"sourceCode":"@experimental\nclass TerminationStrategy(KernelBaseModel):\n    \"\"\"A strategy for determining when an agent should terminate.\"\"\"\n\n    maximum_iterations: int = Field(default=99)\n    automatic_reset: bool = False\n    agents: list[Agent] = Field(default_factory=list)\n\n    async def should_agent_terminate(self, agent: \"Agent\", history: list[\"ChatMessageContent\"]) -> bool:\n        \"\"\"Check if the agent should terminate.\n\n        Args:\n            agent: The agent to check.\n            history: The history of messages in the conversation.\n\n        Returns:\n            True if the agent should terminate, False otherwise\n        \"\"\"\n        raise NotImplementedError(\"Subclasses should implement this method\")\n\n    async def should_terminate(self, agent: \"Agent\", history: list[\"ChatMessageContent\"]) -> bool:\n        \"\"\"Check if the agent should terminate.\n\n        Args:\n            agent: The agent to check.\n            history: The history of messages in the conversation.\n\n        Returns:\n            True if the agent should terminate, False otherwise\n        \"\"\"\n        logger.info(f\"Evaluating termination criteria for {agent.id}\")\n\n        if self.agents and not any(a.id == agent.id for a in self.agents):\n            logger.info(f\"Agent {agent.id} is out of scope\")\n            return False\n\n        should_terminate = await self.should_agent_terminate(agent, history)","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/strategies/termination/termination_strategy.py#L18-L54","documentation":"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.","triggerScenarios":"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.","commonSituations":"Using TerminationStrategy instead of a concrete subclass (e.g. KernelFunctionTerminationStrategy) or a custom subclass; forgetting to override should_agent_terminate when subclassing.","solutions":["Subclass TerminationStrategy and implement `async def should_agent_terminate(self, agent, history) -> bool`.","Use a built-in concrete strategy such as KernelFunctionTerminationStrategy.","If you intended the default behavior, pick the appropriate built-in rather than the abstract base."],"exampleFix":"// before\nclass MyTerm(TerminationStrategy):\n    pass  # forgot to implement should_agent_terminate\n\n// after\nclass MyTerm(TerminationStrategy):\n    async def should_agent_terminate(self, agent, history) -> bool:\n        return history[-1].content.strip().lower() == \"done\"","handlingStrategy":"type-guard","validationCode":"import inspect\nif type(strategy) is TerminationStrategy:\n    raise TypeError('use a concrete subclass, not the abstract TerminationStrategy')\nif 'should_agent_terminate' not in {n for _, n in inspect.getmembers(type(strategy), predicate=inspect.isfunction)}:\n    # ensure the method is overridden, not inherited\n    if type(strategy).should_agent_terminate is TerminationStrategy.should_agent_terminate:\n        raise TypeError('subclass must override should_agent_terminate')","typeGuard":"def is_concrete_termination_strategy(strategy) -> bool:\n    return type(strategy).should_agent_terminate is not TerminationStrategy.should_agent_terminate","tryCatchPattern":null,"preventionTips":["Always subclass TerminationStrategy and implement should_agent_terminate","Prefer built-in concrete strategies (e.g. KernelFunctionTerminationStrategy)","Never instantiate the abstract base directly"],"tags":["agents","termination-strategy","abstract","agent-group-chat"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}