R6 class representing a callable tool for LLM function calling.
A Tool connects an LLM's tool call request to an R function.
Public fields
name
The unique name of the tool.
description
A description of what the tool does.
parameters
A z_object schema defining the tool's parameters.
layer
Tool layer: "llm" (loaded into context) or "computer" (executed via bash/filesystem).
Methods
Method new()
Initialize a Tool.
Usage
Tool$new(name, description, parameters, execute, layer = "llm")
Arguments
name
Unique tool name (used by LLM to call the tool).
description
Description of the tool's purpose.
parameters
A z_object schema defining expected parameters.
execute
An R function that implements the tool logic.
layer
Tool layer: "llm" or "computer" (default: "llm").
Convert tool to API format.
Usage
Tool$to_api_format(provider = "openai")
Arguments
provider
Provider name ("openai" or "anthropic"). Default "openai".
Returns
A list in the format expected by the API.
Method run()
Execute the tool with given arguments.
Usage
Tool$run(args, envir = NULL)
Arguments
args
A list or named list of arguments.
envir
Optional environment in which to evaluate the tool function.
When provided, the environment is passed as .envir in the args list,
allowing the execute function to access and modify session variables.
Returns
The result of executing the tool function.
Method clone()
The objects of this class are cloneable with this method.
Arguments
deep
Whether to make a deep clone.