> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Hook Runner • AI Agent SDK

> HookRunner: Executes hooks from a registry.

# HookRunner

> Defined in the [**runner**](../modules/runner) module.

<Badge color="blue">AI Agent</Badge>

Executes hooks from a registry.

Supports:

* Python function hooks (sync and async)
* Shell command hooks
* Sequential and parallel execution
* Timeout handling
* Result aggregation

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
%%{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:#fff
```

## Constructor

<ParamField query="registry" type="Optional" required={false}>
  No description available.
</ParamField>

<ParamField query="default_timeout" type="float" required={false} default="60.0">
  No description available.
</ParamField>

<ParamField query="cwd" type="Optional" required={false}>
  No description available.
</ParamField>

## Methods

<CardGroup cols={2}>
  <Card title="registry()" icon="function" href="../functions/HookRunner-registry">
    Get the hook registry.
  </Card>

  <Card title="execute()" icon="function" href="../functions/HookRunner-execute">
    Execute all hooks for an event.
  </Card>

  <Card title="execute_sync()" icon="function" href="../functions/HookRunner-execute_sync">
    Synchronous version of execute.
  </Card>

  <Card title="is_blocked()" icon="function" href="../functions/HookRunner-is_blocked">
    Check if any hook blocked execution.
  </Card>

  <Card title="get_blocking_reason()" icon="function" href="../functions/HookRunner-get_blocking_reason">
    Get the reason for blocking from results.
  </Card>

  <Card title="aggregate_context()" icon="function" href="../functions/HookRunner-aggregate_context">
    Aggregate additional context from all results.
  </Card>
</CardGroup>

## Usage

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-agents/praisonaiagents/hooks/runner.py#L30">
  `praisonaiagents/hooks/runner.py` at line 30
</Card>

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Hooks Concept" icon="anchor" href="/docs/concepts/hooks" />

  <Card title="Hook Events" icon="bolt" href="/docs/features/hook-events" />

  <Card title="Callbacks" icon="phone" href="/docs/features/callbacks" />
</CardGroup>
