agentscope-ai/agentscope · error · RuntimeError

{type(self).__name__} does not implement on_acting

Error message

{type(self).__name__} does not implement on_acting

What it means

Middleware.on_acting base stub raises RuntimeError when invoked: a middleware in the acting (tool-execution) phase chain did not override on_acting, which is required to intercept ToolChunk/ToolResponse streams.

Source

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

        Args:
            agent (`Agent`):
                The Agent instance executing this middleware.
            input_kwargs (`dict`):
                Dictionary containing:

                - ``tool_call`` (``ToolCallBlock``): the tool call to execute.
                  By the time this hook is invoked the tool call has already
                  been validated and permitted.
            next_handler (`Callable[..., AsyncGenerator]`):
                Callable that executes the next middleware or
                ``_acting_impl``.

        Yields:
            `ToolChunk | ToolResponse`:
                Intermediate ``ToolChunk`` objects followed by a final
                ``ToolResponse`` produced by the tool.
        """
        raise RuntimeError(
            f"{type(self).__name__} does not implement on_acting",
        )
        yield  # pylint: disable=unreachable

    async def on_check_permission(
        self,
        agent: "Agent",
        input_kwargs: dict,
        next_handler: Callable[..., Awaitable["PermissionDecision"]],
    ) -> "PermissionDecision":
        """Hook for intercepting permission checking for one tool call.

        This hook runs after the tool has been resolved and its input has been
        parsed and validated, but before the resulting decision is consumed by
        the agent.

        Middleware can delegate with ``next_handler(**input_kwargs)``, replace
        the returned decision, or return a decision without delegating. The

View on GitHub (pinned to e90f1c7592)

Solutions

  1. Implement async on_acting(self, agent, tool_call, next_handler) yielding ToolChunk/ToolResponse via next_handler
  2. Remove the middleware from tool-execution chains if it doesn't apply
  3. Check the installed version's Middleware base class for the exact expected signature

Example fix

// before
class MetricsMiddleware(Middleware):
    async def on_model_call(self, agent, messages, next_handler):
        return await next_handler(messages)
# acting chain -> RuntimeError 235

// after
class MetricsMiddleware(Middleware):
    async def on_acting(self, agent, tool_call, next_handler):
        async for chunk in next_handler(tool_call):
            yield chunk

    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_acting is not Middleware.on_acting

Type guard

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

Prevention

When it happens

Trigger: A middleware lacking on_acting is registered in a chain that wraps tool execution; or an override calls super().on_acting(...). Raised during agent tool use.

Common situations: Permission-logging or audit middlewares written for other phases accidentally added to the acting chain; refactors that renamed the method; middleware subclasses built against an older API version where the hook was optional.

Related errors


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