ExAgent. Models. Test
(ExAgent v3.0.0)
View Source
A deterministic, in-process model for development and tests.
Stability — Stable.
Drop-in replacement for a real provider: it never hits the network and returns
scripted (or default) Message.Responses. This is the workhorse that lets the
agent loop be developed and unit-tested offline.
Configuration:
%Test{}— always replies with a generic text response.%Test{label: "x"}— replies with the fixed string"x"as text.:systemand:model_name— model identity strings for separate quota buckets. Omitting either field or setting it toniluses"test".:usage— use:unknown(the default) or aMessage.Usagestruct for generated text and tool-call replies. Explicit responses supply their own usage.%Test{script: [...]}— returns each item in order; an item may be aMessage.Response, a string (wrapped as a text part), a{:tool_calls, [ToolCall]}tuple, a request built withstream/2, or a functionfn messages, params -> item.:profile— a customExAgent.ModelProfilestruct. To enable audio while keeping the default tool and image capabilities, use%Test{profile: %{ExAgent.Model.profile(%Test{}) | supports_audio_input: true}}. To accept a PDF reference under the test provider, setfile_references: [{"test", "application/pdf"}]in the profile.
An initially empty script uses the label or generic response. A nonempty
script must cover every expected model request, including requests after tools
and corrective output. Exhausting it fails the request; it does not silently
supply a generic response. Two-argument functions receive the message list and
parameters. A script error (exhausted or invalid item) fails the request with
%ExAgent.RequestError{provider: :test, reason: exception}.
Summary
Functions
Builds one request for %Test{script: [...]}. The event list defines exact
chunk boundaries. End it with a separate {:finish, response} or
{:error, %ExAgent.RequestError{}} terminal. A dispatched terminal advances
the script index, including on a retryable error. Supply :stop or
:tool_calls on a response meant to succeed.
Types
@type script_item() :: ExAgent.Message.Response.t() | String.t() | {:tool_calls, [ExAgent.Message.Part.ToolCall.t()]} | stream_script() | ([ExAgent.Message.t()], ExAgent.ModelRequestParameters.t() -> script_item())
@type stream_event() :: {:text_delta | :commentary_delta | :thinking_delta, String.t()} | {:tool_call_delta, %{ optional(:name) => String.t() | nil, index: non_neg_integer(), fragment: String.t() }} | {:usage, ExAgent.Message.Usage.t() | :unknown} | {:await, (-> term())}
@opaque stream_script()
@type t() :: %ExAgent.Models.Test{ index: non_neg_integer(), label: String.t() | nil, model_name: String.t() | nil, profile: ExAgent.ModelProfile.t() | nil, script: [script_item()], system: String.t() | nil, usage: ExAgent.Message.Usage.t() | :unknown }
@type terminal() :: {:finish, ExAgent.Message.Response.t()} | {:error, ExAgent.RequestError.t()}
Functions
@spec stream([stream_event()], terminal()) :: stream_script()
Builds one request for %Test{script: [...]}. The event list defines exact
chunk boundaries. End it with a separate {:finish, response} or
{:error, %ExAgent.RequestError{}} terminal. A dispatched terminal advances
the script index, including on a retryable error. Supply :stop or
:tool_calls on a response meant to succeed.
alias ExAgent.{Models.Test, RequestError}
failure = %RequestError{provider: :test, reason: :timeout, transport: :timeout}
%Test{script: [Test.stream([{:text_delta, "draft"}], {:error, failure})]}Text and thinking deltas carry UTF-8 strings. Tool argument previews carry
%{index: index, name: name_or_nil, fragment: json_fragment} and are delivered
when the caller requests them. Supply actual tool calls in the finish response.
Usage events are cumulative snapshots. Use :unknown for unavailable counters.
The terminal inherits the last snapshot if it has no usage of its own.
An unknown snapshot alone leaves an error without a partial response.
An optional {:await, fn -> ... end} runs at that point in stream enumeration,
for example to signal the test process and wait for its reply. Give blocking
callbacks a finite timeout. Halting enumeration skips later callbacks.
A buffered request returns the specified terminal directly. Its partial text,
if any, comes from the error's partial_response. Streaming runs also retain
delivered text in RunError.partial.pending_response.