Define tools as plain Elixir functions, with their JSON Schema derived from
:: type annotations and @doc strings — no hand-written schemas.
Define a module of tools with derived schemas:
defmodule MyApp.Tools do
use ExAgent.Tools
@doc "Get the weather for a city."
deftool get_weather(ctx, city :: String.t()) do
{:ok, ~s(#{city}: 22C, clear)}
end
@doc "Add two numbers."
tool_plain add(a :: integer(), b :: integer()) do
{:ok, a + b}
end
endThen wire them into an agent:
agent = ExAgent.new(model: "test", tools: MyApp.Tools.tools())Rules:
deftool— the first argument is theRunContext(namedctxby convention); remaining typed args become the tool's parameters.tool_plain— no context; every typed arg is a parameter.- Each parameter is described by
name :: type; supported types live inExAgent.Schema. Untyped params collapse to an unconstrained schema. - The function may return
value,{:ok, value}, or{:error, reason}.
Summary
Functions
Define a tool that receives the RunContext as its first argument.
Define a tool that takes only its parameters (no context).