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

# on • AI Agent SDK

> on: Decorator to register a function as a hook.

# on

<div className="flex items-center gap-2">
  <Badge color="purple">Method</Badge>
</div>

> This is a method of the [**HookRegistry**](../classes/HookRegistry) class in the [**registry**](../modules/registry) module.

Decorator to register a function as a hook.

## Signature

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def on(event: HookEvent, matcher: Optional[str], sequential: bool, timeout: float) -> Callable
```

## Parameters

<ParamField query="event" type="HookEvent" required={true}>
  The event to hook
</ParamField>

<ParamField query="matcher" type="Optional" required={false}>
  Optional regex pattern to match targets
</ParamField>

<ParamField query="sequential" type="bool" required={false} default="False">
  Whether to run sequentially
</ParamField>

<ParamField query="timeout" type="float" required={false} default="60.0">
  Timeout in seconds
</ParamField>

### Returns

<ResponseField name="Returns" type="Callable">
  Decorator function
</ResponseField>

## Usage

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
@registry.on(HookEvent.BEFORE_TOOL)
    def my_hook(event_data):
        return HookResult.allow()
```

## Uses

* `asyncio.iscoroutinefunction`
* `register_function`
* `func`
* `wraps`

## Source

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