ExAgent.Tools (ExAgent v0.1.0)

Copy Markdown View Source

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
end

Then wire them into an agent:

agent = ExAgent.new(model: "test", tools: MyApp.Tools.tools())

Rules:

  • deftool — the first argument is the RunContext (named ctx by 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 in ExAgent.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).

Functions

deftool(head, list)

(macro)

Define a tool that receives the RunContext as its first argument.

tool_plain(head, list)

(macro)

Define a tool that takes only its parameters (no context).