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

Copy Markdown View Source

A search strategy for Nous.Eval.Optimizer: how candidate profiles are proposed and which one is best.

The optimizer owns everything around the search: splits, the budget, the seed evaluation, the final pick's test-split acceptance, the report and persistence. A strategy only searches, through the helpers on Nous.Eval.Optimizer.Context (evaluate/4, derive/4, propose/4, feasible/3), which charge the budget and enforce the split and safety rules for it.

  • init/2 receives the seed candidate (the agent's base text as a profile) and may evaluate it.
  • step/2 runs one search step. Return {:halt, reason, state} when the search cannot continue (:budget_exhausted when a helper returned {:error, :budget_exhausted}, or an operational error).
  • best/1 picks the candidate to test. It must never look at test data: the optimizer has not evaluated the test split for any candidate but the seed when it asks.
  • summary/1 reports the candidates and rejections for the result.

Built-ins: Nous.Eval.Optimizer.Strategies.GEPA (default) and Nous.Eval.Optimizer.Strategies.OPRO.

Summary

Callbacks

best(state)

@callback best(state :: term()) :: Nous.Eval.Optimizer.Candidate.t()

init(seed, t)

@callback init(seed :: Nous.Eval.Optimizer.Candidate.t(), Nous.Eval.Optimizer.Context.t()) ::
  {:ok, state :: term()} | {:error, term()}

step(state, t)

@callback step(state :: term(), Nous.Eval.Optimizer.Context.t()) ::
  {:cont, state :: term()} | {:halt, reason :: term(), state :: term()}

summary(state)

@callback summary(state :: term()) :: %{
  candidates: [Nous.Eval.Optimizer.Candidate.t()],
  rejections: [map()]
}