Runs the calls of a ToolRegistry with a timeout, with retries, asynchronously or as a batch.
A registry itself only runs one call on the caller's thread (ToolRegistry.execute). Everything here is built on that one method, so it applies to any registry, including one that finds its tools elsewhere (MCPToolRegistry).
ToolExecutor.execute(registry, request, config) // blocking, on this thread
ToolExecutor.executeAsync(registry, request, config) // Future
ToolExecutor.executeAll(registry, requests, strategy, config) // Future of the results, in request order
The agent runtime does not use this: it runs its tools itself and has its own middleware for timeouts and retries. Only the asynchronous methods take an ExecutionContext.
Executes a tool call on the calling thread with the timeout and retry policy of config.
Executes a tool call on the calling thread with the timeout and retry policy of config.
With ToolExecutionConfig.default (no timeout, no retry) this is registry.execute(request). A backoff between two attempts waits on the calling thread, interruptibly: an interruption ends the call as ToolCallError.Cancelled.
Executes a tool call asynchronously, with the timeout and retry policy of config.
Executes a tool call asynchronously, with the timeout and retry policy of config.
Each attempt runs on a thread of ec and holds it for the attempt only; tool execution typically blocks on I/O, so the attempt is marked blocking. The backoff between two attempts holds no thread: it is a scheduled delay, after which the next attempt is dispatched to ec, so a small pool keeps serving other work while many calls wait to retry. (The synchronous execute still waits on its caller's thread, interruptibly, because a synchronous caller has nothing to resume.)