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

> on_event: Decorator to register an event handler.

# on\_event

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

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

Decorator to register an event handler.

## Signature

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def on_event(event_type: Union[EventType, str]) -> Callable
```

## Parameters

<ParamField query="event_type" type="Union" required={true}>
  No description available.
</ParamField>

### Returns

<ResponseField name="Returns" type="Callable">
  The result of the operation.
</ResponseField>

## Usage

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
@gateway.on_event(EventType.MESSAGE)
    async def handle_message(event: GatewayEvent):
        print(f"Message: {event.data}")
```

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-agents/praisonaiagents/gateway/protocols.py#L365">
  `praisonaiagents/gateway/protocols.py` at line 365
</Card>
