EndpointTools

org.llm4s.tapir.EndpointTools
@Experimental
object EndpointTools

Turns tapir endpoints a service already has into tools a model can call, with each tool's parameter schema derived from the endpoint's own inputs.

val tools: Result[ToolRegistry] = EndpointTools.registry(
 uri"https://orders.internal",
 HttpClientSyncBackend(),
 EndpointTools.tool("get_order", getOrder),
 EndpointTools.tool("cancel_order", cancelOrder)
)

A call decodes the model's arguments with the endpoint's own codecs, so its types and validators check them before anything is sent, then calls the endpoint through sttp. Every failure (an argument the endpoint rejects, an error response, a server error, a request that cannot be sent) is a tool error the model reads; nothing throws.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def registry(baseUri: Uri, backend: SttpBackend[Identity, Any], tools: EndpointTool*): Result[ToolRegistry]

The tools, each calling its endpoint at baseUri through backend; or a ValidationError listing every endpoint that cannot be a tool and why: an input the model cannot supply (a stream, a multipart or binary body, a cookie, a required header nobody supplies), a type its schema cannot state (a map, a recursive type, a sealed hierarchy that is not an enumeration), a binary or streaming output, an invalid or repeated tool name.

The tools, each calling its endpoint at baseUri through backend; or a ValidationError listing every endpoint that cannot be a tool and why: an input the model cannot supply (a stream, a multipart or binary body, a cookie, a required header nobody supplies), a type its schema cannot state (a map, a recursive type, a sealed hierarchy that is not an enumeration), a binary or streaming output, an invalid or repeated tool name.

Attributes

def requiringApproval(tools: EndpointTool*): Set[String]

The names of the tools that require approval, for an agent's approval middleware: new ApprovalMiddleware(call => Option.when(gated(call.spec.name))("changes data")).

The names of the tools that require approval, for an agent's approval middleware: new ApprovalMiddleware(call => Option.when(gated(call.spec.name))("changes data")).

Attributes

def tool[A, I, E, O](name: String, endpoint: Endpoint[A, I, E, O, Any]): EndpointTool

endpoint as the tool name. It requires approval unless its method is safe (GET, HEAD or OPTIONS, or none, which tapir sends as GET): an agent then asks before a call that may change something.

endpoint as the tool name. It requires approval unless its method is safe (GET, HEAD or OPTIONS, or none, which tapir sends as GET): an agent then asks before a call that may change something.

Attributes

def tool[A, I, E, O](name: String, endpoint: Endpoint[A, I, E, O, Any], requiresApproval: Boolean): EndpointTool

endpoint as the tool name, requiring approval when requiresApproval is true.

endpoint as the tool name, requiring approval when requiresApproval is true.

Attributes