Wrap Model Call • AI Agent SDK

wrap_model_call: Decorator to mark a function as a wrap_model_call middleware.

wrap_model_call

Function

</div>

This function is defined in the middleware module.

Decorator to mark a function as a wrap_model_call middleware.

The function receives (request, call_next) and should call call_next(request) to continue the chain, or return early to short-circuit.

Signature

python
def wrap_model_call(func: WrapModelCallFn) -> WrapModelCallFn

Parameters

ParamField WrapModelCallFn

No description available.

Returns

ResponseField WrapModelCallFn

The result of the operation.

Usage

python
@wrap_model_call
    def retry_on_error(request, call_next):
        for _ in range(3):
            try:
                return call_next(request)
            except Exception:
                pass
        raise RuntimeError("All retries failed")

Source

View on GitHub

praisonaiagents/hooks/middleware.py at line 228