Wrap Tool Call • AI Agent SDK
wrap_tool_call: Decorator to mark a function as a wrap_tool_call middleware.
wrap_tool_call
Function
</div>
This function is defined in the middleware module.
Decorator to mark a function as a wrap_tool_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_tool_call(func: WrapToolCallFn) -> WrapToolCallFnParameters
ParamField
WrapToolCallFnNo description available.
Returns
ResponseField
WrapToolCallFnThe result of the operation.
Usage
@wrap_tool_call
def retry_flaky_tool(request, call_next):
last_error = None
for _ in range(3):
try:
return call_next(request)
except Exception as e:
last_error = e
raise last_errorSource
View on GitHubpraisonaiagents/hooks/middleware.py at line 279