agentscope-ai/agentscope · error · RuntimeError

f"{type(self).__name__} does not implement on_check_permissi

Error message

f"{type(self).__name__} does not implement on_check_permission"

What it means

Middleware.on_check_permission base stub raises RuntimeError when executed by the permission chain (execute_chain): every middleware participating in permission resolution must implement on_check_permission and return a PermissionDecision.

Source

Thrown at src/agentscope/middleware/_base.py:209

        Args:
            agent (`Agent`):
                The Agent instance performing the permission check.
            input_kwargs (`dict`):
                Dictionary containing:

                - ``tool_call`` (``ToolCallBlock``): validated call metadata
                  used to correlate the permission decision.
                - ``tool`` (``ToolBase``): the resolved tool instance.
                - ``tool_input`` (``dict``): the parsed and validated input.
            next_handler (`Callable[..., Awaitable[PermissionDecision]]`):
                Callable that executes the next middleware or the built-in
                permission resolution.

        Returns:
            `PermissionDecision`:
                The decision the agent should consume.
        """
        raise RuntimeError(
            f"{type(self).__name__} does not implement on_check_permission",
        )

    async def on_model_call(
        self,
        agent: "Agent",
        input_kwargs: dict,
        next_handler: Callable[
            ...,
            Awaitable["ChatResponse" | AsyncGenerator["ChatResponse", None]],
        ],
    ) -> "ChatResponse" | AsyncGenerator["ChatResponse", None]:
        """Hook for intercepting the model API call.

        Args:
            agent: The Agent instance executing this middleware
            input_kwargs: Dictionary containing:
                - messages: list[Msg]

View on GitHub (pinned to e90f1c7592)

Solutions

  1. Implement async on_check_permission(self, agent, tool_name, args, next_handler) returning a PermissionDecision (or delegating to next_handler)
  2. If the middleware has no permission concern, ensure it's not part of the permission chain / provides a pass-through implementation
  3. Align middleware signatures with the current agentscope version's base class

Example fix

// before
class LoggingMiddleware(Middleware):
    async def on_model_call(self, agent, messages, next_handler):
        return await next_handler(messages)
# permission chain -> RuntimeError 236

// after
from agentscope.middleware import PermissionDecision

class LoggingMiddleware(Middleware):
    async def on_check_permission(self, agent, tool_name, args, next_handler):
        return await next_handler(tool_name, args)  # passthrough decision

    async def on_model_call(self, agent, messages, next_handler):
        return await next_handler(messages)
Defensive patterns

Strategy: type-guard

Validate before calling

from agentscope.middleware import Middleware
assert type(mw).on_check_permission is not Middleware.on_check_permission

Type guard

def implements_on_check_permission(mw) -> bool:
    from agentscope.middleware import Middleware
    return type(mw).on_check_permission is not Middleware.on_check_permission

Prevention

When it happens

Trigger: A middleware registered in the permission-check chain that does not override on_check_permission; or an override delegating to super(). Raised whenever the agent evaluates permissions for a tool call with that chain active.

Common situations: Custom middlewares added to an agent with permission middleware enabled without implementing the permission hook; upgrading agentscope where permission middleware became part of the default chain; misordered chains that route permission checks through unrelated middlewares.

Related errors


AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28). Data as JSON: /api/errors/7babfcdc595b46a8. Report an issue: GitHub.