Hook Runner • AI Agent SDK
HookRunner: Executes hooks from a registry.
HookRunner
Defined in the runner module.
AI Agent
Executes hooks from a registry.
Supports:
- Python function hooks (sync and async)
- Shell command hooks
- Sequential and parallel execution
- Timeout handling
- Result aggregation
%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#8B0000', 'primaryTextColor': '#fff', 'primaryBorderColor': '#710101', 'lineColor': '#189AB4', 'secondaryColor': '#189AB4', 'tertiaryColor': '#fff' }}}%%
graph TD
event["Event Trigger"] --> hook["Hook: HookRunner"]
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
ParamField
Optional[HookRegistry]No description available.
ParamField
floatNo description available.
ParamField
Optional[str]No description available.
Methods
registry()
Get the hook registry.
execute()Execute all hooks for an event.
execute_async()Alias of execute() for call sites expecting an explicit async entry point.
execute_sync()Synchronous version of execute.
is_blocked()Check if any hook blocked execution.
get_blocking_reason()Get the reason for blocking from results.
aggregate_context()Aggregate additional context from all results.
Usage
registry = HookRegistry()
runner = HookRunner(registry)
# Execute hooks for an event
results = await runner.execute(
event=HookEvent.BEFORE_TOOL,
input_data=BeforeToolInput(
tool_name="write_file",
tool_input={"path": "/tmp/test.txt"}
)
)
# Check if any hook blocked
if runner.is_blocked(results):
print("Tool execution blocked by hook")Source
View on GitHubpraisonaiagents/hooks/runner.py at line 32