> ## 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 • Rust AI Agent SDK

> HookRunner: Hook runner for executing hooks in a workflow

# HookRunner

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

<Badge color="orange">Rust AI Agent SDK</Badge>

Hook runner for executing hooks in a workflow

```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
```

## Fields

| Name       | Type                      | Description |
| ---------- | ------------------------- | ----------- |
| `registry` | `Arc&lt;HookRegistry&gt;` | -           |

## Methods

### `new`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn new(registry: HookRegistry) -> Self
```

Create a new hook runner

**Parameters:**

| Name       | Type           |
| ---------- | -------------- |
| `registry` | `HookRegistry` |

### `before_tool`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn before_tool(
        &self,
        session_id: &str,
        tool_name: &str,
        args: serde_json::Value,
    ) -> Result<HookResult>
```

Run before-tool hooks

**Parameters:**

| Name         | Type                |
| ------------ | ------------------- |
| `session_id` | `&str`              |
| `tool_name`  | `&str`              |
| `args`       | `serde_json::Value` |

### `after_tool`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn after_tool(
        &self,
        session_id: &str,
        tool_name: &str,
        result: serde_json::Value,
    ) -> Result<HookResult>
```

Run after-tool hooks

**Parameters:**

| Name         | Type                |
| ------------ | ------------------- |
| `session_id` | `&str`              |
| `tool_name`  | `&str`              |
| `result`     | `serde_json::Value` |

### `before_agent`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn before_agent(
        &self,
        session_id: &str,
        agent_name: &str,
        message: &str,
    ) -> Result<HookResult>
```

Run before-agent hooks

**Parameters:**

| Name         | Type   |
| ------------ | ------ |
| `session_id` | `&str` |
| `agent_name` | `&str` |
| `message`    | `&str` |

### `after_agent`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn after_agent(
        &self,
        session_id: &str,
        agent_name: &str,
        response: &str,
    ) -> Result<HookResult>
```

Run after-agent hooks

**Parameters:**

| Name         | Type   |
| ------------ | ------ |
| `session_id` | `&str` |
| `agent_name` | `&str` |
| `response`   | `&str` |

### `on_error`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn on_error(&self, session_id: &str, error: &str) -> Result<HookResult>
```

Run on-error hooks

**Parameters:**

| Name         | Type   |
| ------------ | ------ |
| `session_id` | `&str` |
| `error`      | `&str` |

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-rust/praisonai/src/hooks/mod.rs#L461">
  `praisonai/src/hooks/mod.rs` at line 461
</Card>

***

## Related Documentation

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

  <Card title="Rust Events" icon="bolt" href="/docs/rust/events" />

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