Class DurableEvaluator<S>
- Type Parameters:
S- The type of the state accumulated across the steps of this evaluation.
Use a DurableEvaluator instead of an Evaluator when the evaluation is long-running or
needs durable, multi-step execution, for example composed evaluations that accumulate state
across several judge calls, or evaluations that wait on human review. Each evaluation runs as its
own durable instance: if it is stopped for any reason, it resumes from the last completed step.
Like an Evaluator, a DurableEvaluator is bound to one or more agents through
configuration under akka.javasdk.evaluation.evaluators, keyed by the evaluator's
component id. The runtime invokes onEvaluation(EvaluationContext) for each interaction
of a bound agent. The evaluation then progresses through steps, methods returning DurableEvaluator.Effect,
until it finishes with DurableEvaluator.Effect.Builder.complete(akka.javasdk.evaluation.Evaluation) or DurableEvaluator.Effect.Builder.inconclusive(java.lang.String),
which records the outcome and cleans up the instance. There is no other way to finish: every
evaluation terminates with a recorded outcome, including step failures that exhaust their
retries.
Concrete class must be annotated with Component.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAn Effect is a description of what the runtime needs to do after `onEvaluation` or a step method is handled.static final classSettings for a durable evaluator.static interfaceRepresents an operation that accepts an input of type I and produces a result of type R. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final SReturns the state as currently stored.protected final DurableEvaluator.Effect.Builder<S> effects()Returns a builder for theDurableEvaluator.Effectreturned byonEvaluation(akka.javasdk.evaluation.EvaluationContext)and step methods.Returns the initial empty state object, passed into the step methods until a new state replaces it.protected final EvaluationContextThe evaluation being run: the subject under evaluation and the evaluation id.abstract DurableEvaluator.EffectonEvaluation(EvaluationContext context) Start the evaluation of the interaction identified by the given context.settings()Override to configure timeouts and retries for this evaluator.
-
Constructor Details
-
DurableEvaluator
public DurableEvaluator()
-
-
Method Details
-
onEvaluation
Start the evaluation of the interaction identified by the given context. Invoked by the runtime when a trigger fires for this evaluator.- Parameters:
context- identifies the interaction to evaluate- Returns:
- an
DurableEvaluator.Effectwith the first step transition, or directly the outcome
-
emptyState
Returns the initial empty state object, passed into the step methods until a new state replaces it.The default implementation of this method returns
null. It can be overridden to return a more sensible initial state. -
currentState
Returns the state as currently stored.Note that modifying the state directly will not update it in storage. To save the state, one must call
effects().updateState().- Throws:
IllegalStateException- if accessed outside a handler method
-
evaluationContext
The evaluation being run: the subject under evaluation and the evaluation id. Available inonEvaluation(akka.javasdk.evaluation.EvaluationContext)and in every step method.- Throws:
IllegalStateException- if accessed outside a handler method
-
effects
Returns a builder for theDurableEvaluator.Effectreturned byonEvaluation(akka.javasdk.evaluation.EvaluationContext)and step methods. -
settings
Override to configure timeouts and retries for this evaluator.
-