{"record":{"id":"2b7b380e9b8254db","repo":"agentscope-ai/agentscope","slug":"f-type-self-name-does-not-implement-on-syst","errorCode":null,"errorMessage":"f\"{type(self).__name__} does not implement on_system_prompt\"","messagePattern":"f\"(.+?) does not implement on_system_prompt\"","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/agentscope/middleware/_base.py","lineNumber":282,"sourceCode":"    async def on_system_prompt(\n        self,\n        agent: \"Agent\",\n        current_prompt: str,\n    ) -> str:\n        \"\"\"Transform the system prompt string.\n\n        This uses a transformer/pipeline pattern rather than onion pattern.\n        Multiple middlewares are applied sequentially, each receiving the\n        output of the previous one.\n\n        Args:\n            agent: The Agent instance executing this middleware\n            current_prompt: The current system prompt string\n\n        Returns:\n            str: The transformed system prompt\n        \"\"\"\n        raise RuntimeError(\n            f\"{type(self).__name__} does not implement on_system_prompt\",\n        )\n\n    async def list_tools(self) -> list[ToolBase]:\n        \"\"\"List available tools provided by this middleware. Optional to\n        implement.\n\n        Returns:\n            `list[ToolBase]`:\n                A list of tools provided by this middleware.\n        \"\"\"\n        return []\n\n    async def get_middleware_key(self) -> str:\n        \"\"\"Get the unique key for this middleware, used to save middleware\n        states in `AgentState` instances.\n\n        Optionally, middleware classes can override this method to","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/middleware/_base.py#L264-L300","documentation":"Middleware.on_system_prompt base stub raises RuntimeError when _get_system_prompt dispatches to a middleware that did not override on_system_prompt. Middlewares in the system-prompt chain must implement this hook to transform or pass through the prompt string.","triggerScenarios":"Agent construction/reply startup calls _get_system_prompt, which walks the middleware chain; any middleware in that chain without an on_system_prompt override raises. Also triggered by overrides calling super().on_system_prompt(...).","commonSituations":"Custom middlewares registered on an agent but written without the system-prompt hook; upgrading agentscope where the system-prompt chain now includes all registered middlewares; ordering bugs inserting a base-like stub into the chain.","solutions":["Implement async on_system_prompt(self, agent, current_prompt) -> str returning the (possibly transformed) prompt","Have unrelated middlewares return current_prompt unchanged","Verify method name spelling and signature against the current base class"],"exampleFix":"// before\nclass PersonaMiddleware(Middleware):\n    async def on_acting(self, agent, tool_call, next_handler):\n        async for c in next_handler(tool_call):\n            yield c\n# _get_system_prompt -> RuntimeError 239\n\n// after\nclass PersonaMiddleware(Middleware):\n    async def on_system_prompt(self, agent, current_prompt):\n        return current_prompt + \"\\nAlways answer in the user's language.\"\n\n    async def on_acting(self, agent, tool_call, next_handler):\n        async for c in next_handler(tool_call):\n            yield c","handlingStrategy":"type-guard","validationCode":"from agentscope.middleware import Middleware\nassert type(mw).on_system_prompt is not Middleware.on_system_prompt","typeGuard":"def implements_on_system_prompt(mw) -> bool:\n    from agentscope.middleware import Middleware\n    return type(mw).on_system_prompt is not Middleware.on_system_prompt","tryCatchPattern":null,"preventionTips":["Default every middleware's on_system_prompt to returning current_prompt unchanged","Add an agent smoke test that constructs the system prompt with all middlewares registered","Watch for hook signature changes across agentscope upgrades"],"tags":["middleware","system-prompt","hook-not-implemented"],"backgroundTag":"abstract-method-not-implemented","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}