> ## 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.

# Add Hook • AI Agent SDK

> add_hook: Register a hook callback. Simplified API.

# add\_hook

<div className="flex items-center gap-2">
  <Badge color="teal">Function</Badge>
</div>

> This function is defined in the [**registry**](../modules/registry) module.

Register a hook callback. Simplified API.

Accepts both string event names and HookEvent enums:
add\_hook('before\_tool', my\_callback)  # String
add\_hook(HookEvent.BEFORE\_TOOL, my\_callback)  # Enum

Can also be used as a decorator:
@add\_hook('before\_tool')
def my\_hook(data):
return HookResult.allow()

```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: add_hook"]
    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
```

## Signature

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def add_hook(event: Union[str, HookEvent], callback: Optional[Callable[[HookInput], HookResult]], priority: int, matcher: Optional[str]) -> Union[str, Callable]
```

## Parameters

<ParamField query="event" type="Union" required={true}>
  Hook event name ('before\_tool', 'after\_llm', etc.) or HookEvent enum
</ParamField>

<ParamField query="callback" type="Optional" required={false}>
  Function to call when hook fires (optional when using as decorator)
</ParamField>

<ParamField query="priority" type="int" required={false} default="10">
  Execution order (lower = earlier). Default 10. (Reserved for future use)
</ParamField>

<ParamField query="matcher" type="Optional" required={false}>
  Optional regex pattern to match specific targets (e.g., tool names)
</ParamField>

### Returns

<ResponseField name="Returns" type="Union[str, Callable]">
  Hook ID for later removal, or a decorator function if callback is None
</ResponseField>

### Exceptions

<AccordionGroup>
  <Accordion title="ValueError">
    If event string is not a valid HookEvent
  </Accordion>
</AccordionGroup>

## Uses

* `HookEvent`
* `ValueError`
* `register_function`
* `get_default_registry`

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-agents/praisonaiagents/hooks/registry.py#L346">
  `praisonaiagents/hooks/registry.py` at line 346
</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>
