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
Constructor
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 31