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.
  • :system and :model_name — model identity strings for separate quota buckets. Omitting either field or setting it to nil uses "test".
  • :usage — use :unknown (the default) or a Message.Usage struct for generated text and tool-call replies. Explicit responses supply their own usage.
  • %Test{script: [...]} — returns each item in order; an item may be a Message.Response, a string (wrapped as a text part), a {:tool_calls, [ToolCall]} tuple, a request built with stream/2, or a function fn messages, params -> item.
  • :profile — a custom ExAgent.ModelProfile struct. 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, set file_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

script_item()

stream_event()

@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())}

stream_script()

@opaque stream_script()

t()

@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
}

terminal()

@type terminal() ::
  {:finish, ExAgent.Message.Response.t()} | {:error, ExAgent.RequestError.t()}

Functions

stream(events, terminal)

@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.