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

# Before Model • AI Agent SDK

> before_model: Decorator to mark a function as a before_model hook.

# before\_model

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

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

Decorator to mark a function as a before\_model hook.

The function receives a ModelRequest and should return a (possibly modified) ModelRequest.

## Signature

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def before_model(func: BeforeModelFn) -> BeforeModelFn
```

## Parameters

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

### Returns

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

## Usage

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
@before_model
    def add_context(request):
        request.messages.append({"role": "system", "content": "Extra"})
        return request
```

## Source

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