Nous.Eval.Optimizer.Adapter behaviour (nous v0.21.1)

Copy Markdown View Source

How Nous.Eval.Optimizer evaluates a candidate profile and turns the result into evidence for the reflector (the GEPA adapter shape).

The default, Nous.Eval.Optimizer.AgentAdapter, runs the eval task with Nous.Eval.run/2 and the candidate applied to every agent the task builds. An adapter for another system implements the same five callbacks and is passed as adapter: {module, opts}.

Contract

  • evaluate/3 never raises per case: a case that crashed, timed out or errored is in the result with score 0.0. It reports what it spent (metric_calls, tokens, cost) and the run status; the optimizer charges the spend whatever the status and uses only :completed evaluations for decisions.
  • reflective_records/2 builds records from train evaluations only and raises ArgumentError for any other split: validation and test content never reaches the reflector, only their scores reach the optimizer. Records are rendered under the evaluation's feedback policy (see "Feedback policy" in Nous.Eval.Optimizer).

Summary

Types

A batch to evaluate

One piece of reflector evidence, for one train case

Callbacks

The agent the profiles are written for, with its base text: component keys are validated and profiles sealed against it, and the guard filter receives it with each profile applied.

Every case the optimizer may draw batches from.

Evaluates profile on batch.

Prepares the adapter for task (no model call).

The reflector evidence for component_keys: %{key => [record]}. Raises ArgumentError unless the evaluation's split is "train".

Types

batch()

@type batch() :: %{
  case_ids: [String.t()],
  split: String.t(),
  k: pos_integer(),
  budget: keyword(),
  feedback: :diagnostic | :with_expected,
  seed: integer() | nil
}

A batch to evaluate:

  • :case_ids - the cases
  • :split - the split label recorded on the evaluation
  • :k - samples per case
  • :budget - the most this evaluation may spend ([max_tokens: n, max_cost: usd, max_samples: n], see "Budgets" in Nous.Eval.run/2)
  • :feedback - the feedback policy for its reflective records
  • :seed - the base seed (the same for every evaluation, so a parent and its child see the same sample seeds)

reflective_record()

@type reflective_record() :: %{
  :case_id => String.t(),
  :score => float(),
  :inputs => String.t(),
  :outputs => String.t(),
  :tool_calls => [map()],
  :feedback => [map()],
  optional(:expected) => map()
}

One piece of reflector evidence, for one train case:

  • :case_id, :score - the case and its objective (from the scorer structs, never parsed from text)
  • :inputs - the case input as text (untrusted)
  • :outputs - the agent's output or error (untrusted)
  • :tool_calls - [%{name, arguments, outcome, result}] from the trace (untrusted)
  • :feedback - one map per score: :scorer, :passed?, :value, :reason (trusted, scorer-authored), :paths (mismatched argument or output paths; untrusted), :missing_tools (expected tool names that were not called), :critique (a judge's critique; untrusted)
  • :expected - the case's expected map, present only under :with_expected for a train case

Callbacks

agent(state)

@callback agent(state :: term()) :: Nous.Agent.t()

The agent the profiles are written for, with its base text: component keys are validated and profiles sealed against it, and the guard filter receives it with each profile applied.

cases(state)

@callback cases(state :: term()) :: [Nous.Eval.Case.t()]

Every case the optimizer may draw batches from.

evaluate(state, profile, batch)

@callback evaluate(state :: term(), profile :: Nous.Profile.t(), batch()) ::
  {:ok, Nous.Eval.Optimizer.Evaluation.t()} | {:error, term()}

Evaluates profile on batch.

init(task, opts)

@callback init(task :: module(), opts :: keyword()) ::
  {:ok, state :: term()} | {:error, term()}

Prepares the adapter for task (no model call).

reflective_records(t, component_keys)

@callback reflective_records(
  Nous.Eval.Optimizer.Evaluation.t(),
  component_keys :: [String.t()]
) :: %{
  required(String.t()) => [reflective_record()]
}

The reflector evidence for component_keys: %{key => [record]}. Raises ArgumentError unless the evaluation's split is "train".