ExAgent.Eval.Case (ExAgent v3.0.0)

View Source

One evaluation case: a name, the input and what to expect.

Stability — Stable.

Summary

Functions

Decode the versioned document produced by to_map/1.

Build a regression case from a settled agent terminal without running the agent.

Build a case. Options: :expected (what evaluators compare against), :metadata (any map, for custom evaluators) and :run_opts (merged into the run options for this case, for example deps:). Unknown or duplicate options raise ArgumentError. An agent target takes an ExAgent prompt. Pass a candidate ExAgent.Eval.Scenario for a scripted conversation. A function target defines its own input type.

Encode a case as a versioned JSON map. The input, expected value and metadata must be JSON data. Object keys are normalized to strings. Captured cases preserve their observation metadata on a round trip. The case must have empty run options. Supply host dependencies and executable configuration separately when running it.

Types

redactor()

(candidate API)
@type redactor() :: (:input | :expected | :output, term() -> {:ok, term()} | :drop)

source()

(candidate API)

t()

@type t() :: %ExAgent.Eval.Case{
  expected: term(),
  input: term(),
  metadata: map(),
  name: String.t(),
  run_opts: keyword(),
  version: String.t() | nil
}

Functions

from_map(doc)

@spec from_map(map()) ::
  {:ok, t()} | {:error, :invalid_case | :unsupported_case_version}

Decode the versioned document produced by to_map/1.

from_run(source, opts)

(candidate API)
@spec from_run(source(), keyword()) ::
  {:ok, t()}
  | {:error,
     :unconfirmed_terminal
     | :missing_input
     | {:redaction_failed, :input | :expected | :output}
     | {:unsupported, :continuation_workflow}}

Build a regression case from a settled agent terminal without running the agent.

The source can be a run result, a run error with a settled partial result, a value from ExAgent.run/3 or its stream terminal, an agent record read with ExAgent.Continuation.get/2, or the sample passed to an Online evaluator.

Supply a non-secret :name and an explicit :redact callback of arity two. The callback receives :input, :expected or :output and the corresponding value. Return {:ok, replacement} or :drop. The replacement input must be a valid agent prompt. Expected and observed outputs must be JSON data. Object keys are normalized to strings. Callback failures return {:error, {:redaction_failed, field}} without the value or exception.

Pass :input to supply a prompt separately. A C7 summary needs this option. With diagnostics enabled on the trusted C7 read, the retained prompt of that run can supply it. A successful diagnostic record also provides its retained accepted answer, when available. Guarded answers use the accepted display text, which can contain JSON text for structured output. A run needs an explicit prompt if its starting user request is absent from the retained history. For an Online sample, an empty input can also mean content was absent. Supply input: "" to use an empty prompt. A missing or dropped input returns {:error, :missing_input}.

Pass :expected for the intended answer. An Online sample can supply it when the offer authorized it. The observed answer goes to metadata.observed_output after redaction. Metadata also records the source and terminal status. The case carries no model, receipt, transcript, run options or callback. Use :version as in new/3. Null or dropped optional values are omitted.

Pauses and unsettled attempts return {:error, :unconfirmed_terminal}. A C7 workflow record returns {:error, {:unsupported, :continuation_workflow}}. Invalid options raise ArgumentError before the redactor runs.

To reproduce offline, record a v4 fixture with an explicit test model and tool substitutes. A terminal captures an outcome and the retained history. Fixture matching needs the full model requests made by the test harness.

new(name, input, opts \\ [])

@spec new(String.t(), term(), keyword()) :: t()

Build a case. Options: :expected (what evaluators compare against), :metadata (any map, for custom evaluators) and :run_opts (merged into the run options for this case, for example deps:). Unknown or duplicate options raise ArgumentError. An agent target takes an ExAgent prompt. Pass a candidate ExAgent.Eval.Scenario for a scripted conversation. A function target defines its own input type.

Supply a non-secret :version when case data or configuration contains opaque values such as callbacks or process references. Change the version whenever those values' behavior changes. Without it, the case can still run and score, but its provenance is incomplete for baseline comparisons.

to_map(entry)

@spec to_map(t()) :: {:ok, map()} | {:error, :invalid_case}

Encode a case as a versioned JSON map. The input, expected value and metadata must be JSON data. Object keys are normalized to strings. Captured cases preserve their observation metadata on a round trip. The case must have empty run options. Supply host dependencies and executable configuration separately when running it.