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.
%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#8B0000', 'primaryTextColor': '#fff', 'primaryBorderColor': '#710101', 'lineColor': '#189AB4', 'secondaryColor': '#189AB4', 'tertiaryColor': '#fff' }}}%%
graph LR
agent["Agent"] -- "uses" --> tool["Tool: wrap_tool_call"]
tool -- "returns" --> result["Result"]
style tool fill:#189AB4,color:#fff
style agent fill:#8B0000,color:#fff
style result fill:#8B0000,color:#fffSignature
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