Skip to main content

HookRegistry

Defined in the registry module.
AI Agent Registry for managing hooks. Provides methods to register, unregister, and lookup hooks for different events.

Constructor

enabled
bool
default:"True"
No description available.

Methods

enabled()

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 GitHub

praisonaiagents/hooks/registry.py at line 19

Hooks Concept

Hook Events

Callbacks