View Source Anthropic.Tools.ToolBehaviour behaviour (anthropic_community v0.4.3)
Defines a behaviour for creating tools that can be used with Anthropic's AI models.
This module provides a set of callbacks and basic functions to support tool description and invocation, as described in the Anthropic documentation.
To create a new tool, define a module that implements the Anthropic.Tools.ToolBehaviour
behaviour.
The module should implement the following callbacks:
description/0
: Returns a string describing the purpose and functionality of the tool.parameters/0
: Returns a list of parameter specifications, where each parameter is represented as a tuple of{name, type, description}
.invoke/1
: Invokes the tool with the provided Keyword list arguments and returns the result as a string.
Example:
defmodule MyTool do
use Anthropic.Tools.ToolBehaviour
def description do
"A tool that performs a specific task."
end
def parameters do
[
{:param1, :string, "Description of param1."},
{:param2, :integer, "Description of param2."}
]
end
def invoke(keyword_list) do
# Implement the tool's functionality here
# Use the provided arguments to perform the task
# Return the result as a string
end
end
Summary
Callbacks
Returns a string describing the purpose and functionality of the tool.
Invokes the tool with the provided list of string arguments and returns the result as a string.
Returns a list of parameter specifications for the tool.
Types
@type parameter() :: {atom(), parameter_type(), String.t()}
@type parameter_type() :: :string | :float | :integer
Callbacks
@callback description() :: String.t()
Returns a string describing the purpose and functionality of the tool.
Invokes the tool with the provided list of string arguments and returns the result as a string.
@callback parameters() :: [parameter()]
Returns a list of parameter specifications for the tool.
Each parameter is represented as a tuple of {name, type, description}
, where:
name
is an atom representing the parameter name.type
is an atom representing the parameter type (:string
,:float
, or:integer
).description
is a string describing the purpose of the parameter.