Wrapper for tool call execution with multi-call support.
ToolCallWrapper = Callable[[ToolCallRequest, Callable[[ToolCallRequest], ToolMessage | Command]], ToolMessage | Command]Wrapper receives:
request: ToolCallRequest with tool_call, tool, state, and runtime. execute: Callable to execute the tool (CAN BE CALLED MULTIPLE TIMES).
The execute callable can be invoked multiple times for retry logic, with potentially modified requests each time. Each call to execute is independent and stateless.
When implementing middleware for create_agent, use
AgentMiddleware.wrap_tool_call which provides properly typed
state parameter for better type safety.