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

> HookDefinition: Hook definition

# HookDefinition

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

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

Hook definition

```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: HookDefinition"]
    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                                           |
| --------- | ---------------------- | ----------------------------------------------------- |
| `id`      | `String`               | Unique ID                                             |
| `event`   | `HookEvent`            | Event to hook                                         |
| `matcher` | `Option&lt;String&gt;` | Optional matcher pattern (regex for tool names, etc.) |
| `func`    | `HookFn`               | Hook function                                         |
| `enabled` | `bool`                 | Whether hook is enabled                               |
| `name`    | `Option&lt;String&gt;` | Hook name (for debugging)                             |

## Methods

### `new`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn new(
        event: HookEvent,
        func: impl Fn(&HookInput) -> HookResult + Send + Sync + 'static,
    ) -> Self
```

Create a new hook definition

**Parameters:**

| Name    | Type                 |
| ------- | -------------------- |
| `event` | `HookEvent`          |
| `func`  | `impl Fn(&HookInput` |

### `with_matcher`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn with_matcher(mut self, pattern: impl Into<String>) -> Self
```

Set matcher pattern

**Parameters:**

| Name      | Type                      |
| --------- | ------------------------- |
| `pattern` | `impl Into&lt;String&gt;` |

### `with_name`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn with_name(mut self, name: impl Into<String>) -> Self
```

Set name

**Parameters:**

| Name   | Type                      |
| ------ | ------------------------- |
| `name` | `impl Into&lt;String&gt;` |

### `matches`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn matches(&self, target: &str) -> bool
```

Check if this hook matches the target

**Parameters:**

| Name     | Type   |
| -------- | ------ |
| `target` | `&str` |

### `execute`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn execute(&self, input: &HookInput) -> HookResult
```

Execute the hook

**Parameters:**

| Name    | Type         |
| ------- | ------------ |
| `input` | `&HookInput` |

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-rust/praisonai/src/hooks/mod.rs#L285">
  `praisonai/src/hooks/mod.rs` at line 285
</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>
