Convenience macro for defining function-backed tools with JSON schemas.
Usage:
defmodule MyTool do
use Codex.FunctionTool,
name: "add",
description: "Adds numbers",
parameters: %{left: :number, right: :number},
handler: fn %{"left" => left, "right" => right}, _ctx ->
{:ok, %{"sum" => left + right}}
end
endOptions:
:name- tool name (defaults to module name):description- human-friendly description:parameters- map of parameter names to type atoms or schema maps:required- list of required parameter names (defaults to all):schema- explicit JSON schema (overrides generated schema):strict?- when true sets"additionalProperties": false(default):handler- function to invoke (falls back tohandle/2orhandle/1):enabled?- predicate to gate invocation (arity 1 or 2):on_error- fallback handler invoked with the error (arity 2 or 3)
Summary
Functions
Constructs metadata map used for tool registration.
Builds a JSON schema map from a parameter definition.
Executes the configured handler with normalized arguments.