Cyclium.Intent.GoalEvaluator behaviour (Cyclium v0.5.2)

Copy Markdown View Source

Called after each interactive episode converges within a conversation. Returns whether the conversation should continue, resolve, or abandon.

The goal's completion_criteria.mode picks the evaluator:

Nothing has to be configured for the default. A custom evaluator is declared on the expectation, in code; a module name inside the goal JSON is never resolved. When the goal asks for a callback and the expectation declares none, the conversation stays open (:continue) and a warning is logged.

Summary

Functions

The evaluator module an expectation declared (goal_evaluator: in the Actor DSL), or nil. Looks up the exact {actor, expectation} pair first, then any expectation of the actor (a conversation may not record its expectation).

Dispatches to the evaluator the goal's completion_criteria selects.

Callbacks

evaluate(goal, conversation_state, latest_result)

@callback evaluate(
  goal :: Cyclium.Intent.GoalSpec.t(),
  conversation_state :: map(),
  latest_result :: Cyclium.ConvergeResult.t()
) ::
  :continue
  | {:resolved, outcome :: binary(), result :: map()}
  | {:abandoned, reason :: binary()}

Functions

declared_for(actor_id, expectation_id)

@spec declared_for(atom() | binary() | nil, atom() | binary() | nil) :: module() | nil

The evaluator module an expectation declared (goal_evaluator: in the Actor DSL), or nil. Looks up the exact {actor, expectation} pair first, then any expectation of the actor (a conversation may not record its expectation).

evaluate(goal, conversation_state, result, opts \\ [])

@spec evaluate(
  Cyclium.Intent.GoalSpec.t(),
  map(),
  Cyclium.ConvergeResult.t(),
  keyword()
) ::
  :continue | {:resolved, binary(), map()} | {:abandoned, binary()}

Dispatches to the evaluator the goal's completion_criteria selects.

opts[:evaluator] is the module the expectation declared (see declared_for/2); it is used for evaluator_callback goals and for goals with no mode at all.