Ollixir.Tool (Ollixir v0.1.1)

Copy Markdown View Source

Tool definition helpers for function calling.

Provides utilities to define tools declaratively and convert Elixir functions to tool definitions.

Summary

Functions

Define a tool with a name, description, and parameters.

Create a tool definition from a function reference.

Create a tool definition from module, function name, and arity.

Convert a list that may contain functions to tool definitions.

Same as prepare/1 but raises on error.

Types

param_opts()

@type param_opts() :: [
  type: param_type(),
  required: boolean(),
  description: String.t(),
  enum: [any()],
  default: any(),
  items: param_opts()
]

param_type()

@type param_type() :: :string | :integer | :number | :boolean | :array | :object

tool_def()

@type tool_def() :: %{
  type: String.t(),
  function: %{
    name: String.t(),
    description: String.t() | nil,
    parameters: map()
  }
}

Functions

define(name, opts)

@spec define(
  atom() | String.t(),
  keyword()
) :: tool_def()

Define a tool with a name, description, and parameters.

from_function(fun)

@spec from_function(function()) :: {:ok, tool_def()} | {:error, term()}

Create a tool definition from a function reference.

from_mfa(module, function, arity)

@spec from_mfa(module(), atom(), non_neg_integer()) ::
  {:ok, tool_def()} | {:error, term()}

Create a tool definition from module, function name, and arity.

prepare(tools)

@spec prepare([function() | tool_def()]) :: {:ok, [tool_def()]} | {:error, term()}

Convert a list that may contain functions to tool definitions.

prepare!(tools)

@spec prepare!([function() | tool_def()]) :: [tool_def()]

Same as prepare/1 but raises on error.