ExAgent.Eval.Online (ExAgent v3.0.0)

View Source

Sample already confirmed terminals with an existing ExAgent.Eval evaluator.

Stability — Stable.

Start a supervised queue for one trusted scope and evaluator version. Obtain its local handle once, then use offer/3 after the runtime acknowledgement. A queue admits samples without calling its owner or a Store. The evaluator runs in a separate task and receives a bounded view. For C7 receipts the worker first checks the exact final record by reading it. Evaluation never runs the target or dispatches its tools.

The default is content-free. Even with content: true the evaluator only receives text explicitly authorized in an offer. Tool evidence carries the declared name, opaque call reference and status. Results and errors export without text, arguments, tool results or evaluator explanations.

A custom evaluator receives the usual case and output fields. Its result view contains :run_id and :status, with scope and source in the case's metadata. It can receive failed or cancelled runs, including a :cancelled_before_start terminal for a queued turn with a reserved run ID and a confirmed :cancelled event for an active or paused Server turn. A cancellation with status :uncertain needs reconciliation before grading. Graded text is optional.

Summary

Types

The bounded outcome supplied to a custom Online evaluator. Its case input, expected answer and output come from the content authorized in offer/3. See ExAgent.Eval.Case.from_run/2 to project it into a regression case.

Functions

Returns a specification to start this module under a supervisor.

Return a handle for fast local admission. Resolve it again after restarting the queue.

Offer a confirmed result to this queue. Do this after the target returns, from a Server terminal event consumer, or after receiving a Session turn acknowledgement. Pass {:session, reply} with the result of ExAgent.Session.chat/4. For a turn the host commits separately, use {:session, reply, outcome} with the turn acknowledgement and run outcome or {:continuation, reference}. The worker checks exact C7 references.

Start a queue. Required options are :scope (a trusted identifier or nil) and :evaluator. The queue uses the evaluator's version by default. Pass :version to set it explicitly or to use an unversioned evaluator. Change the version whenever evaluator behavior changes.

Types

handle()

@opaque handle()

outcome()

@type outcome() :: {:ok, ExAgent.Result.t()} | {:error, ExAgent.RunError.t() | term()}

sample()

@type sample() :: %{
  case: ExAgent.Eval.Case.t(),
  output: String.t() | nil,
  result: %{run_id: String.t(), status: atom()},
  error: atom() | nil,
  online: %{
    budget: map(),
    transcript: String.t() | nil,
    tools: [map()],
    tools_complete: boolean()
  }
}

The bounded outcome supplied to a custom Online evaluator. Its case input, expected answer and output come from the content authorized in offer/3. See ExAgent.Eval.Case.from_run/2 to project it into a regression case.

terminal()

@type terminal() ::
  {:run, outcome()}
  | {:server,
     outcome()
     | ExAgent.Event.t()
     | {:ok, ExAgent.Server.cancelled_admission_receipt()}}
  | {:session, outcome()}
  | {:session, {:ok, term(), term()}, outcome() | {:continuation, map()}}
  | {:continuation, map()}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

handle(queue)

@spec handle(GenServer.server()) :: handle()

Return a handle for fast local admission. Resolve it again after restarting the queue.

offer(queue, terminal, opts \\ [])

@spec offer(handle(), terminal(), keyword()) ::
  {:ok, :enqueued | :not_sampled | :duplicate} | {:error, atom()}

Offer a confirmed result to this queue. Do this after the target returns, from a Server terminal event consumer, or after receiving a Session turn acknowledgement. Pass {:session, reply} with the result of ExAgent.Session.chat/4. For a turn the host commits separately, use {:session, reply, outcome} with the turn acknowledgement and run outcome or {:continuation, reference}. The worker checks exact C7 references.

To recover a queued cancellation after a Server restart, offer {:server, reply} with the {:ok, receipt} from Server.receipt/3. The receipt must confirm :cancelled_before_start in the queue's scope. For an active cancellation, offer the confirmed Server event. The partial run reply only certifies interruption of the worker.

Returns {:ok, :enqueued | :not_sampled | :duplicate} or {:error, reason}. :full means this sample was shed. :unconfirmed_terminal means the input was a pause, provisional failure or missing acknowledgement. A later C7 read can discard an enqueued sample when its receipt cannot be confirmed. Durable grading also emits a discard if it cannot confirm an export claim. The queue remembers that sample in its bounded duplicate window.

  • :content optionally supplies a map of authorized UTF-8 :input, :output, :expected and :transcript strings.
  • :tools optionally supplies {:complete | :partial, observations}. Pass each :tool_call_finished Event or terminal [:exagent, :tool, :stop] observation of the run once. A repeated provider ID can be a new call. Only the first 64 observations are retained. Use :complete for a complete capture. When omitted, C7 journal evidence is partial.

  • :trace_context defaults to the caller's OTel span context. Pass a context captured in the evaluated operation when enqueueing across a process boundary. :response_id can carry an explicitly authorized provider completion ID.

Call from the trusted host. Server terminal Events must use the queue's :scope. A C7 receipt and any accompanying tool Events use the namespace of the configured source Store. Bind native results and tool-stop telemetry to the correct scope before offering them.

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

Start a queue. Required options are :scope (a trusted identifier or nil) and :evaluator. The queue uses the evaluator's version by default. Pass :version to set it explicitly or to use an unversioned evaluator. Change the version whenever evaluator behavior changes.

  • :sample_rate defaults to 0.01. Use 1.0 for every run in the scope.
  • :capacity defaults to 64, including the active sample.
  • :seen_capacity defaults to 4096 remembered keys after completion.
  • :timeout_ms defaults to 5000 per evaluation. The built-in judge gets one reviewer attempt and a :judge_max_tokens output limit (512 by default).
  • :content defaults to false. Authorized text has a combined :max_content_bytes limit (16384 by default).
  • :store is the authorized source Store for C7 receipts. A namespace supplied by the receipt must match this descriptor.
  • :grading_backend defaults to :memory. For Jobs use {:durable, jobs, expires_at_ms} with the queue's scope as the Jobs namespace and an absolute Unix millisecond expiry. The first admission fixes the deadline for this evaluation. Apply ExAgent.Jobs.Durable.migration_sql/0 for durable grading.
  • :otel optionally receives an OTLP/HTTP JSON logs request with the named evaluation event. The callback runs in a background task. Return :ok after confirming dispatch and {:error, reason} otherwise. The [:exagent, :eval, :online, :delivery] event reports :dispatched or :delivery_unconfirmed using the result's ID.

:name accepts the same registrations as a GenServer. Use non-secret identifiers for the scope, evaluator and version.