Before Model • AI Agent SDK

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

before_model

Function

</div>

This function is defined in the 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
def before_model(func: BeforeModelFn) -> BeforeModelFn

Parameters

ParamField BeforeModelFn

No description available.

Returns

ResponseField BeforeModelFn

The result of the operation.

Usage

python
@before_model
    def add_context(request):
        request.messages.append({"role": "system", "content": "Extra"})
        return request

Source

View on GitHub

praisonaiagents/hooks/middleware.py at line 198