{"record":{"id":"e6cd620999e15fdb","repo":"agentscope-ai/agentscope","slug":"type-self-name-does-not-implement-on-reason","errorCode":null,"errorMessage":"{type(self).__name__} does not implement on_reasoning","messagePattern":"(.+?) does not implement on_reasoning","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/agentscope/middleware/_base.py","lineNumber":119,"sourceCode":"    async def on_reasoning(\n        self,\n        agent: \"Agent\",\n        input_kwargs: dict,\n        next_handler: Callable[..., AsyncGenerator],\n    ) -> AsyncGenerator:\n        \"\"\"Hook for intercepting the reasoning process.\n\n        Args:\n            agent: The Agent instance executing this middleware\n            input_kwargs: Dictionary containing:\n                - tool_choice: ToolChoice (default None)\n            next_handler: Callable that executes the next middleware or\n            original method\n\n        Yields:\n            Various events from the reasoning process\n        \"\"\"\n        raise RuntimeError(\n            f\"{type(self).__name__} does not implement on_reasoning\",\n        )\n        yield  # pylint: disable=unreachable\n\n    async def on_acting(\n        self,\n        agent: \"Agent\",\n        input_kwargs: dict,\n        next_handler: Callable[..., AsyncGenerator],\n    ) -> AsyncGenerator:\n        \"\"\"Hook for intercepting the raw tool execution.\n\n        This hook wraps **only** the ``toolkit.call_tool`` call — i.e. the\n        pure I/O execution layer.  Permission checking, input validation, and\n        context writes are handled by the agent **outside** this hook and are\n        therefore not visible here.\n\n        This separation makes it safe to offload the ``next_handler``","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/middleware/_base.py#L101-L137","documentation":"Middleware.on_reasoning base stub raises RuntimeError when called, marking on_reasoning as an override-required hook for any middleware participating in the reasoning phase of the agent pipeline.","triggerScenarios":"A middleware without an on_reasoning override is included in the reasoning hook chain (agent streams reasoning events); or an override calls super().on_reasoning(...).","commonSituations":"Same family as 233: partial middleware implementations, template subclasses, or chains built generically that require every reasoning-phase middleware to implement the hook.","solutions":["Implement async on_reasoning(self, agent, ..., next_handler) that yields events, delegating to next_handler for passthrough","Exclude the middleware from reasoning-phase chains if it has no reasoning concern","Never delegate to the base implementation"],"exampleFix":"// before\nclass AuditMiddleware(Middleware):\n    async def on_model_call(self, agent, messages, next_handler):\n        return await next_handler(messages)\n# reasoning chain calls on_reasoning -> RuntimeError 234\n\n// after\nclass AuditMiddleware(Middleware):\n    async def on_reasoning(self, agent, reasoning, next_handler):\n        async for ev in next_handler(reasoning):\n            yield ev\n\n    async def on_model_call(self, agent, messages, next_handler):\n        return await next_handler(messages)","handlingStrategy":"type-guard","validationCode":"from agentscope.middleware import Middleware\nassert type(mw).on_reasoning is not Middleware.on_reasoning","typeGuard":"def implements_on_reasoning(mw) -> bool:\n    from agentscope.middleware import Middleware\n    return type(mw).on_reasoning is not Middleware.on_reasoning","tryCatchPattern":null,"preventionTips":["Use passthrough generators for hooks you don't need","Verify hook coverage when adding middlewares to reasoning-capable agents","Keep middleware templates with all hooks pre-implemented as passthroughs"],"tags":["middleware","hook-not-implemented","reasoning"],"backgroundTag":"abstract-method-not-implemented","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}