LlmToolkit.Tool (llm_toolkit v0.1.0)

Copy Markdown View Source

Provider-neutral tool definition.

A tool is a pure data structure: name, description, and a JSON Schema describing the parameters the tool accepts. The callback (how to actually execute the tool) is not part of this struct — it is resolved at runtime by the host application via a LlmToolkit.ToolResolver.

This separation ensures tool definitions are serializable (YAML config, MCP exposure, storage) while callbacks remain a runtime concern.

Fields

  • name - Unique tool identifier (required)
  • description - Human-readable description for the LLM (required)
  • parameters - JSON Schema map describing accepted arguments (required)
  • metadata - Optional map for tags, version, source, etc.

Examples

iex> LlmToolkit.Tool.new(%{
...>   name: "search",
...>   description: "Search the knowledge base",
...>   parameters: %{
...>     "type" => "object",
...>     "properties" => %{"query" => %{"type" => "string"}}
...>   }
...> })
{:ok,
 %LlmToolkit.Tool{
   name: "search",
   description: "Search the knowledge base",
   parameters: %{
     "type" => "object",
     "properties" => %{"query" => %{"type" => "string"}}
   },
   metadata: %{}
 }}

Summary

Functions

Creates a Tool from a plain map, typically loaded from YAML.

Creates a new Tool from a map of attributes.

Types

t()

@type t() :: %LlmToolkit.Tool{
  description: String.t(),
  metadata: map(),
  name: String.t(),
  parameters: map()
}

Functions

from_map(map)

@spec from_map(map()) :: {:ok, t()} | {:error, term()}

Creates a Tool from a plain map, typically loaded from YAML.

Accepts string keys and converts them.

new(attrs)

@spec new(map()) :: {:ok, t()} | {:error, term()}

Creates a new Tool from a map of attributes.

Returns {:ok, tool} on success or {:error, reason} when required fields are missing or invalid.