on • AI Agent SDK

on: Decorator to register a function as a hook.

on

Method

</div>

This is a method of the HookRegistry class in the registry module.

Decorator to register a function as a hook.

Signature

python
def on(event: HookEvent, matcher: Optional[str], sequential: bool, timeout: float, priority: int) -> Callable

Parameters

ParamField HookEvent

The event to hook

ParamField Optional[str]

Optional regex pattern to match targets

ParamField bool

Whether to run sequentially

ParamField float

Timeout in seconds

ParamField int

Execution order (lower runs earlier). Default 100

Returns

ResponseField Callable

Decorator function

Usage

python
@registry.on(HookEvent.BEFORE_TOOL)
    def my_hook(event_data):
        return HookResult.allow()

Uses

  • asyncio.iscoroutinefunction
  • register_function
  • func
  • wraps

Source

View on GitHub

praisonaiagents/hooks/registry.py at line 179