Create middleware with wrap_tool_call hook from a function.
Async version is awrap_tool_call.
Converts a function with handler callback into middleware that can intercept tool calls, implement retry logic, monitor execution, and modify responses.
wrap_tool_call(
func: _CallableReturningToolResponse | None = None,
*,
tools: list[BaseTool] | None = None,
name: str | None = None
) -> Callable[[_CallableReturningToolResponse], AgentMiddleware] | AgentMiddleware| Name | Type | Description |
|---|---|---|
func | _CallableReturningToolResponse | None | Default: NoneFunction accepting (request, handler) that calls
handler(request) to execute the tool and returns final Can be sync or async. |
tools | list[BaseTool] | None | Default: NoneAdditional tools to register with this middleware. |
name | str | None | Default: NoneMiddleware class name. Defaults to function name. |