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
def on(event: HookEvent, matcher: Optional[str], sequential: bool, timeout: float, priority: int) -> CallableParameters
ParamField
HookEventThe event to hook
ParamField
Optional[str]Optional regex pattern to match targets
ParamField
boolWhether to run sequentially
ParamField
floatTimeout in seconds
ParamField
intExecution order (lower runs earlier). Default 100
Returns
ResponseField
CallableDecorator function
Usage
@registry.on(HookEvent.BEFORE_TOOL)
def my_hook(event_data):
return HookResult.allow()Uses
asyncio.iscoroutinefunctionregister_functionfuncwraps
Source
View on GitHubpraisonaiagents/hooks/registry.py at line 179