ExAgent.RequestError (ExAgent v3.0.0)

View Source

Structured error returned by providers for transport/API failures.

Stability — Stable.

A provider model can return {:error, %ExAgent.RequestError{}}. Match a provider failure from ExAgent.run/3 as {:error, %ExAgent.RunError{reason: {:model_request_failed, %ExAgent.RequestError{}}}}. ExAgent.run!/3 raises that ExAgent.RunError.

reason: :context_overflow means the provider explicitly rejected the request because the context exceeded its window. Custom adapters can return this reason and attach available usage in partial_response.

Inside a run, every model failure has this shape, also one reported by the continuation preflight validate_resume/4 of a persisted run, except a missing callback (:model_continuation_preflight_required) or one that broke its contract (:invalid_model_continuation_preflight). A reason a custom model returns outside this struct ({:error, :busy}), an exception it raises and the dispatcher's own failures ({:unsupported, :streaming}, :incomplete_stream, :invalid_stream_event, :invalid_model_result, :invalid_model_identity) arrive wrapped with provider: nil; Fallback's own failures use provider: :fallback. A continuation history that belongs to another target, routing or mode is reason: {:continuation_mismatch, :target | :routing | :mode}.

A ReqLLM audio attachment larger than 1 MiB decoded fails before transport with reason: {:attachment_limit, :audio}. The profile, catalogue and MIME checks for audio use reason: {:unsupported, :modality}.

A provider file reference on a model or Fallback leaf of another provider fails before dispatch with reason: :file_reference_provider_mismatch. An unqualified transport, profile or MIME fails with reason: {:unsupported, :file_reference}. For these admission failures, details contains the model's :provider string and its zero-based :leaf_index in Fallback traversal order. A single model has index 0. Malformed reference metadata in a model request projection fails with reason: :invalid_file_reference.

An adapter reports a terminal response that is not :stop or :tool_calls as reason: {:incomplete_response, finish_reason} with the response in partial_response; the run turns it into RunError.reason = {:incomplete_response, finish_reason}.

transport identifies a connection failure such as :econnrefused or :closed. In streaming, :timeout can also mean the wait for the next event expired. A stream can report a transport failure after emitting text. retry_after_ms is the provider's minimum delay before another attempt, in milliseconds, when available on an HTTP error. ReqLLM saturates oversized delays at the maximum signed 64-bit integer. Fallback skips that wait.

model carries optional updated live model state from a dispatched request. When the request used a Fallback group, that field carries the updated group if any candidate reported state. In a RunError's model-request failure, RequestError.model is nil and the live state is in RunError.partial.model. The run treats values outside the types of model and partial_response as absent and keeps the provider failure details.

Summary

Types

t()

@type t() :: %ExAgent.RequestError{
  body: term() | nil,
  details: map() | nil,
  model: struct() | nil,
  partial_response: ExAgent.Message.Response.t() | nil,
  provider: atom() | nil,
  reason: term(),
  retry_after_ms: non_neg_integer() | nil,
  status: pos_integer() | nil,
  transport: atom() | nil
}