ToolExecutor

org.llm4s.toolapi.ToolExecutor
@Experimental
object ToolExecutor

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.

Attributes

Source
ToolExecutor.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def execute(registry: ToolRegistry, request: ToolCallRequest, config: ToolExecutionConfig): Outcome

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.

Attributes

Source
ToolExecutor.scala

Executes several tool calls with a configurable strategy.

Executes several tool calls with a configurable strategy.

Value parameters

config

The timeout and retry policy of each call

requests

The tool call requests to execute

strategy

Sequential, parallel, or parallel with a concurrency limit

Attributes

Returns

The results, in the same order as requests

Source
ToolExecutor.scala

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.)

Attributes

Source
ToolExecutor.scala