Hook Registry • AI Agent SDK
HookRegistry: Registry for managing hooks.
HookRegistry
Defined in the registry module.
AI Agent
Registry for managing hooks.
Provides methods to register, unregister, and lookup hooks for different events.
%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#8B0000', 'primaryTextColor': '#fff', 'primaryBorderColor': '#710101', 'lineColor': '#189AB4', 'secondaryColor': '#189AB4', 'tertiaryColor': '#fff' }}}%%
graph TD
event["Event Trigger"] --> hook["Hook: HookRegistry"]
hook --> decision{"Decision"}
decision -- "Allow" --> proc["Process"]
decision -- "Deny" --> block["Block"]
style hook fill:#189AB4,color:#fff
style event fill:#8B0000,color:#fff
style proc fill:#8B0000,color:#fff
style block fill:#8B0000,color:#fffConstructor
boolNo description available.
Methods
Check if hooks are enabled.
enabled()Enable or disable hooks.
register()Register a hook definition.
register_function()Register a Python function as a hook.
register_command()Register a shell command as a hook.
on()Decorator to register a function as a hook.
unregister()Unregister a hook by ID.
get_hooks()Get all hooks for an event, optionally filtered by target.
has_hooks()Check if there are any hooks registered for an event.
clear()Clear all hooks or hooks for a specific event.
list_hooks()List all registered hooks.
enable_hook()Enable a specific hook.
disable_hook()Disable a specific hook.
set_global_timeout()Set the global timeout for all hooks.
Usage
registry = HookRegistry()
# Register a function hook using decorator
@registry.on(HookEvent.BEFORE_TOOL)
def validate_tool(event_data):
if event_data.tool_name == "dangerous":
return HookResult.deny("Tool is dangerous")
return HookResult.allow()
# Register a command hook
registry.register_command(
event=HookEvent.BEFORE_TOOL,
command="python /path/to/validator.py",
matcher="write_*"
)Source
View on GitHubpraisonaiagents/hooks/registry.py at line 20