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
- Known subtypes
-
class Failedtrait ToolParameterErrorclass InvalidNestingclass MissingParameterclass MultipleErrorsclass NullParameterclass TypeMismatch
