ToolHandlerError

org.llm4s.toolapi.ToolHandlerError
See theToolHandlerError companion object
@Stable
sealed trait ToolHandlerError

What a tool's handler returns when it cannot do what was asked: a ToolParameterError when the call's arguments are at fault, which is what SafeParameterExtractor's getters return, or a ToolHandlerError.Failed when the tool itself says no. A handler reads its arguments and reports its own failures in one for comprehension:

.withHandler { args =>
 for {
   city    <- args.getString("city")                    // Left(ToolParameterError) when missing or mistyped
   _       <- Either.cond(city.nonEmpty, (), ToolHandlerError.failed("city is empty"))
   weather <- lookup(city).toRight(ToolHandlerError.failed(s"no such city: $city")) // the tool's own failure
 } yield weather
}

ToolFunction.execute turns the first into ToolCallError.InvalidArguments, with every parameter error in its parameterErrors, and the second into ToolCallError.HandlerError.

A String is not a ToolHandlerError: write Left(ToolHandlerError.failed("message")), and turn a helper's Either[String, A] into a handler's with .left.map(ToolHandlerError.failed).

It is a sealed trait and not a union of String and ToolParameterError, so that Java and Scala 2.13 callers can read the signatures that name it (ToolFunction, and through it CompletionOptions).

Attributes

Companion
object
Source
ToolParameterError.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Members list

Value members

Abstract methods

The error as text: the handler's own message, or what is wrong with the arguments.

The error as text: the handler's own message, or what is wrong with the arguments.

Attributes

Source
ToolParameterError.scala