R6 class representing a callable tool for LLM function calling. A Tool connects an LLM's tool call request to an R function.
nameThe unique name of the tool.
descriptionA description of what the tool does.
parametersA z_object schema defining the tool's parameters.
layerTool layer: "llm" (loaded into context) or "computer" (executed via bash/filesystem).
metaOptional metadata for the tool (e.g., caching configuration).
new()Initialize a Tool.
Tool$new(name, description, parameters, execute, layer = "llm", meta = NULL)nameUnique tool name (used by LLM to call the tool).
descriptionDescription of the tool's purpose.
parametersA z_object schema defining expected parameters.
executeAn R function that implements the tool logic.
layerTool layer: "llm" or "computer" (default: "llm").
metaOptional metadata list (e.g., cache_control).
to_api_format()Convert tool to API format.
Tool$to_api_format(provider = "openai")providerProvider name ("openai" or "anthropic"). Default "openai".
A list in the format expected by the API.
run()Execute the tool with given arguments.
Tool$run(args, envir = NULL)argsA list or named list of arguments.
envirOptional 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.
The result of executing the tool function.
clone()The objects of this class are cloneable with this method.
Tool$clone(deep = FALSE)deepWhether to make a deep clone.