wrap_tool_call(
self,
request: ToolCallRequest,
handler: Callable[[ToolCallRequest], ToolMessage | Command| Name | Type | Description |
|---|---|---|
request* | ToolCallRequest | |
handler* | Callable[[ToolCallRequest], ToolMessage | Command[Any]] |
Intercept tool execution for retries, monitoring, or modification.
Async version is awrap_tool_call
Multiple middleware compose automatically (first defined = outermost).
Exceptions propagate unless handle_tool_errors is configured on ToolNode.
The handler Callable can be invoked multiple times for retry logic.
Each call to handler is independent and stateless.
Tool call request with call dict, BaseTool, state, and runtime.
Access state via request.state and runtime via request.runtime.
Callable to execute the tool (can be called multiple times).