create_custom_tool
create_custom_tool.RdDefine a user-supplied tool for an agent. Unlike create_tool, the caller
provides the R function to invoke (impl). Custom tools are outside the
package's allowlist-and-hash enforcement, so the caller vouches for the
code. An agent will refuse to carry a custom tool unless the agent is
created with allow_custom_tools = TRUE (see create_agent).
Usage
create_custom_tool(name, function_name, description, parameters = list(), impl)Arguments
- name
Character: The name of the tool, e.g. "Addition".
- function_name
Character: The name to expose to the model, e.g. "add_numbers".
- description
Character: The description of the tool.
- parameters
List of
ToolParameter: The parameters of the tool, each defined using tool_param.- impl
Function: The R function to invoke when the tool is called. Its formal argument names must match the
namefields ofparameters.
Examples
add_numbers <- function(x, y) x + y
tool_addition <- create_custom_tool(
name = "Addition",
function_name = "add_numbers",
description = "Performs arithmetic addition of two numbers.",
parameters = list(
tool_param("x", "number", "The first number to add", required = TRUE),
tool_param("y", "number", "The second number to add", required = TRUE)
),
impl = add_numbers
)