Expands the tool inputs a client accepts into LlmCall.ToolSpec structs.
This module builds what a request sends; it never runs a tool. Running one is
the caller's loop, and ToolCall.run/4 is one implementation of it.
Modules are an input form, not a canonical type: expand/2 turns a module or
a {module, opts} pair into LlmCall.ToolSpec structs with the schema
projected for the codec's protocol. Every entry point that forwards a request
to a codec expands tools first: complete/3, stream/3, encode/3,
validate_request/3, init_stream/3 and
Dialect.OpenAI.Responses.Connection.create/3; capabilities/3 reads no
tools. LlmCall.Codec.Conformance calls the codec callbacks directly, so a
request handed to one of its assertions must already carry
%LlmCall.ToolSpec{} entries.
Summary
Functions
Expands tools into one spec per tool.
Normalizes a request's tools into LlmCall.ToolSpec structs.
Types
@type input() :: LlmCall.Request.tool_entry()
A tool entry: a spec to keep, or a ToolCall module to expand.
Functions
@spec expand([input()], module()) :: {:ok, [LlmCall.ToolSpec.t()]} | {:error, LlmCall.Error.t()}
Expands tools into one spec per tool.
A %LlmCall.ToolSpec{} passes through unchanged; a module, or
{module, opts}, contributes one spec per tool, in the module's declaration
order, with the schema projected for codec's protocol. opts may carry
strict: boolean(): true asks for OpenAI's strict schema and false is
treated as absent. expand/2 does not police that per protocol — the resulting
%LlmCall.ToolSpec{strict: true} is what the codec's own validate_request/2
rejects when it has no per-tool flag, so a caller that only expands sees the spec
accepted here. Any other option, or a value
that is not a keyword list, is rejected. Errors are named after codec,
so a caller sees which protocol refused the request; an entry that is none of
the accepted forms, a module that does not use ToolCall, and a schema the
codec cannot express are :validation errors rather than raises.
@spec normalize_request(LlmCall.Request.t(), module()) :: {:ok, LlmCall.Request.t()} | {:error, LlmCall.Error.t()}
Normalizes a request's tools into LlmCall.ToolSpec structs.
The request-level companion to expand/2: complete/3, stream/3, encode/3,
validate_request/3, init_stream/3 and
Dialect.OpenAI.Responses.Connection.create/3 call this before the codec, so
the codec sees only specs. capabilities/3 reads no tools. Other fields pass
through unchanged and an expansion error is returned as-is.