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
def wrap_model_call(func: WrapModelCallFn) -> WrapModelCallFnParameters
ParamField
WrapModelCallFnNo description available.
Returns
ResponseField
WrapModelCallFnThe result of the operation.
Usage
@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 GitHubpraisonaiagents/hooks/middleware.py at line 228