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
Hook event name (‘before_tool’, ‘after_llm’, etc.) or HookEvent enum
Function to call when hook fires (optional when using as decorator)
Execution order (lower = earlier). Default 10. (Reserved for future use)
Optional regex pattern to match specific targets (e.g., tool names)
Returns
Hook ID for later removal, or a decorator function if callback is None
Exceptions
ValueError
ValueError
If event string is not a valid HookEvent

