ToolBuilder

org.llm4s.toolapi.ToolBuilder
See theToolBuilder companion object
class ToolBuilder[T, R]

Builder for ToolFunction definitions using a fluent API.

Obtained via the companion ToolBuilder object:

ToolBuilder[Map[String, Any], MyResult]("my_tool", "Does something", schema)
 .withHandler(extractor => Right(MyResult(...)))
 .buildSafe()

Value parameters

description

Natural-language description for the LLM

handler

Optional handler; must be set before calling buildSafe

name

Tool name

schema

Parameter schema

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def buildSafe(): Result[ToolFunction[T, R]]

Build the tool function, returning a Result for safe error handling.

Build the tool function, returning a Result for safe error handling.

Attributes

Returns

Right(ToolFunction) if handler is defined, Left(ValidationError) otherwise

def withHandler(handler: SafeParameterExtractor => Either[String, R]): ToolBuilder[T, R]

Set the handler function for this tool.

Set the handler function for this tool.

Value parameters

handler

Function that extracts parameters and executes the tool's logic

Attributes

Returns

A new builder with the handler registered

Deprecated methods

def build(): ToolFunction[T, R]

Build the tool function, throwing on failure.

Build the tool function, throwing on failure.

Prefer buildSafe which returns Result[ToolFunction] and avoids throwing.

Attributes

Throws
java.lang.IllegalStateException

if handler is not defined

Deprecated
[Since version 0.2.9] Use buildSafe() which returns Result[ToolFunction] for safe error handling