add_hook
Function
This function is defined in the registry module.Register a hook callback. Simplified API. Accepts both string event names and HookEvent enums: add_hook(‘before_tool’, my_callback) # String add_hook(HookEvent.BEFORE_TOOL, my_callback) # Enum Can also be used as a decorator: @add_hook(‘before_tool’) def my_hook(data): return HookResult.allow()
Signature
Parameters
Union[str, HookEvent]
required
Hook event name (‘before_tool’, ‘after_llm’, etc.) or HookEvent enum
Optional
Function to call when hook fires (optional when using as decorator)
int
default:"100"
Execution order (lower = earlier). Default 100 — same default bucket as
register_function/on, so hooks added through either API keep registration order unless an explicit priority is given.Optional[str]
Optional regex pattern to match specific targets (e.g., tool names)
Returns
Union[str, Callable]
Hook ID for later removal, or a decorator function if callback is None
Exceptions
ValueError
ValueError
If event string is not a valid HookEvent
Uses
HookEventValueErrorregister_functionget_default_registry
Source
View on GitHub
praisonaiagents/hooks/registry.py at line 382
