ToolCall
Derive LLM tool-call schemas from Elixir @spec and @doc, then dispatch the
call back to the function.
No DSL, no second schema, no runtime reading of Docs/Dbgi chunks.
defmodule MyApp.Tools.Weather do
use ToolCall
@doc """
Get the forecast for a city.
## Parameters
* `city` - city name
* `days` - how many days ahead
"""
@spec get_weather(city :: String.t(), days :: pos_integer() | nil) ::
{:ok, map()} | {:error, String.t()}
def get_weather(city, days \\ 3) do
{:ok, %{city: city, days: days, temp: 21.5}}
end
end
ToolCall.emit(MyApp.Tools.Weather, :openai)
ToolCall.run(MyApp.Tools.Weather, :get_weather, %{"city" => "Oslo"})
#=> {:ok, %{city: "Oslo", days: 3, temp: 21.5}}
Installation
def deps do
[tool_call: "~> 0.3"]
end
Requires Elixir ~> 1.18 and Erlang/OTP 27.1+. The OTP floor is enforced at
compile time; there are no runtime dependencies.
What you get
ToolCall.emit/3— OpenAI, Anthropic, MCP and Gemini schemas; the provider-call targets are precompiled per module, MCP and Gemini on demand.ToolCall.run/4— required/unknown argument checks, coercion, exception wrapping, optional result validation, per-call timeouts, approval policies and dispatch audit hooks.ToolCall.Runner.resolve/4+ToolCall.Runner.execute/2— split validation and invocation;resolvereturns a%ToolCall.Call{}that can be gated and executed later.ToolCall.Approval+ToolCall.Approval.Request— approval policy hook and a serializable pending request for human-in-the-loop flows.ToolCall.Audit+ToolCall.Audit.Entry— one dispatch audit entry per attempt.ToolCall.Timeout— timeout policy behaviour and per-invocation task runner.ToolCall.tools/1andToolCall.describe/2— the IR and provider-neutral schema descriptions.ToolCall.Stream— folds streaming tool-call deltas (OpenAI, Anthropic, Gemini) into complete calls forrun/3.use ToolCall, types: [...]— customToolCall.TypeProviderintegrations;ToolCall.Providers.URIandToolCall.Providers.Versionare optional string providers for those standard-library structs.use ToolCall, timeout: ...,approval: ...,audit: ...— module-level policies; callToolCall.validate_policies!/1at startup to check them.ToolCall.PolicyValidation— one-shot supervision child (one per supervisor, with all modules) that runs the startup policy validation before the rest of the tree.mix tool_call.export— JSON for OpenAI, Anthropic, MCP or Gemini.mix tool_call.clean— removes orphaned typedoc companion beams.
Documentation
The full documentation is generated by mix docs:
CHANGELOG.md— release history.docs/usage.md— defining, emitting, dispatching, exporting, conventions, and error terms.docs/design.md— architecture, type mapping, typedoc companions, provider subsets, and design boundaries.docs/projection.md— canonical target schema matrix and loss notes.docs/pitfalls.md— compile-time traps and their trade-offs.docs/number-handling.md— large integers and JSON precision.docs/roadmap.md— current status and remaining work.
Development
mix deps.get
mix ci
mix coveralls.html
mix ci runs compile/format checks, tests, spec_lint, Credo, Dialyzer,
ExDNA and Reach. mix coveralls.html writes the HTML coverage report to
cover/. CI uploads the report to Codecov when CODECOV_TOKEN is configured.
License
MIT