ExAthena.Tools (ExAthena v0.7.1)

Copy Markdown View Source

Resolves tools into ExAthena.Tool.Spec structs for the provider and loop.

Consumers supply tools in one of two ways:

  1. At config time:

    config :ex_athena, tools: [MyApp.ToolA, MyApp.ToolB]
  2. Per-call:

    ExAthena.Loop.run(messages, tools: [MyApp.ToolA, ExAthena.Tools.Read])

Per-call wins; the configured list is the default when no tools are passed.

resolve/1 returns [ExAthena.Tool.Spec.t()]. Built-in modules are wrapped into :module specs; MCP-discovered tools are appended as :mcp specs (unless suppressed via mcp: false).

Summary

Functions

List the builtin tool modules.

Build the prompt-friendly list used by ExAthena.ToolCalls.augment_system_prompt/3 when we fall back to the TextTagged protocol.

Build the provider-facing tool schema list — the same shape Ollama / OpenAI-compatible providers send on the wire.

Find the spec that handles a call by name.

Resolve the tools to use for a call. Returns [Tool.Spec.t()].

Validate a list of specs. Raises if any module spec's module doesn't implement the Tool behaviour.

Functions

builtins()

@spec builtins() :: [module()]

List the builtin tool modules.

describe_for_prompt(specs)

@spec describe_for_prompt([ExAthena.Tool.Spec.t()]) :: [map()]

Build the prompt-friendly list used by ExAthena.ToolCalls.augment_system_prompt/3 when we fall back to the TextTagged protocol.

describe_for_provider(specs)

@spec describe_for_provider([ExAthena.Tool.Spec.t()]) :: [map()]

Build the provider-facing tool schema list — the same shape Ollama / OpenAI-compatible providers send on the wire.

find(specs, name)

@spec find([ExAthena.Tool.Spec.t()], String.t()) :: ExAthena.Tool.Spec.t() | nil

Find the spec that handles a call by name.

resolve(opts)

@spec resolve(keyword()) :: [ExAthena.Tool.Spec.t()]

Resolve the tools to use for a call. Returns [Tool.Spec.t()].

Accepts:

  • a list of modules (each wrapped into a :module spec)
  • :all — every builtin as specs
  • nil — falls back to config :ex_athena, tools: ... or :all

Options:

  • mcp: true | false | [server_name] — controls MCP tool inclusion. Defaults to true when the MCP supervisor is running, false otherwise. Pass false to suppress MCP tools entirely; pass a list of server names to include only tools from those servers.

validate!(specs)

@spec validate!([ExAthena.Tool.Spec.t()]) :: :ok

Validate a list of specs. Raises if any module spec's module doesn't implement the Tool behaviour.