Imp.GEPA.ReflectionStrategy behaviour (Imp v0.5.0)

Copy Markdown View Source

Public behaviour for trusted custom GEPA reflection strategies.

Implement reflect/3 for a stateless strategy. For durable contextual state, implement reflect/4, dump_state/1, and load_state/1, then wrap the module and initial context with contextual/2. Checkpoints retain validated data and module identity; they never serialize executable code.

Summary

Functions

Builds a durable contextual strategy from a trusted behaviour module.

Types

candidate()

@type candidate() :: map()

component_name()

@type component_name() :: atom()

job()

@type job() :: {candidate(), map(), [component_name()]}

proposal()

@type proposal() :: map()

Callbacks

dump_state(term)

(optional)
@callback dump_state(term()) :: term()

load_state(term)

(optional)
@callback load_state(term()) :: term()

reflect(candidate, map, list)

(optional)
@callback reflect(candidate(), map(), [component_name()]) :: proposal()

reflect(candidate, map, list, term)

@callback reflect(candidate(), map(), [component_name()], term()) ::
  {proposal(), term()}
  | {:ok, proposal(), term()}
  | {:error, term()}
  | proposal()

reflect_many(list, term)

(optional)
@callback reflect_many([job()], term()) ::
  {[proposal()], term()} | {:ok, [proposal()], term()} | {:error, term()}

total_cost(term)

(optional)
@callback total_cost(term()) :: number()

Functions

contextual(module, context)

@spec contextual(module(), term()) :: struct()

Builds a durable contextual strategy from a trusted behaviour module.