ExAgent.Tool (ExAgent v0.2.0)

Copy Markdown View Source

Normalized tool definition for LLM function-calling.

Represents a tool that an LLM can invoke, including its name, description, JSON Schema parameters, and the actual function to execute.

Summary

Functions

Creates a new tool with validated attributes.

Types

t()

@type t() :: %ExAgent.Tool{
  description: String.t(),
  function: (map() -> any()),
  name: String.t(),
  parameters: map()
}

Functions

new(attrs)

@spec new(keyword()) :: {:ok, t()} | {:error, String.t()}

Creates a new tool with validated attributes.

Examples

iex> {:ok, tool} = ExAgent.Tool.new(name: "search", description: "Search the web", parameters: %{}, function: fn _ -> :ok end)
iex> tool.name
"search"

iex> ExAgent.Tool.new(description: "Search", parameters: %{}, function: fn _ -> :ok end)
{:error, "name is required"}

iex> ExAgent.Tool.new(name: "search", parameters: %{}, function: fn _ -> :ok end)
{:error, "description is required"}