SafeTool

data class SafeTool<TArgs, TResult>(tool: Tool<TArgs, TResult>, environment: AIAgentEnvironment, clock: Clock)(source)

A wrapper class designed to safely execute a tool within a given AI agent environment. It provides mechanisms for handling tool execution results and differentiating between success and failure cases.

Constructors

Link copied to clipboard
constructor(tool: Tool<TArgs, TResult>, environment: AIAgentEnvironment, clock: Clock)

Types

Link copied to clipboard
sealed interface Result<TResult>

Represents a sealed interface for results, which can either be a success or a failure.

Functions

Link copied to clipboard
suspend fun execute(args: TArgs, serializer: JSONSerializer): SafeTool.Result<TResult>

Executes the tool with the provided arguments and returns the result.

Link copied to clipboard
suspend fun executeUnsafe(args: Any?, serializer: JSONSerializer): SafeTool.Result<TResult>

Executes a tool with the provided arguments in an unsafe manner. This method does not enforce type safety for the arguments provided to the tool.

Link copied to clipboard
suspend fun <TResult> SafeTool<ERROR CLASS: Symbol not found for ToolFromCallable.Args, TResult>.executeUnsafe(serializer: ERROR CLASS: Symbol not found for JSONSerializer, vararg args: Any?): SafeTool.Result<TResult>

Helper function for SafeTool that is created from ToolFromCallable. Allows a simpler execution by passing the ToolFromCallable.callable positional arguments directly as args instead of creating ToolFromCallable.Args manually.