SafeTool

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.

Parameters

TArgs

The type of arguments accepted by the underlying tool. Must extend Tool.Args.

TResult

The type of result produced by the underlying tool. Must extend ToolResult.

Constructors

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

Types

Link copied to clipboard
sealed interface Result<TResult : ToolResult>

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): SafeTool.Result<TResult>

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

Link copied to clipboard
suspend fun executeRaw(args: TArgs): String

Executes a raw tool call with the given arguments, returning the resulting content as a string.

Link copied to clipboard

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.