Class DurableEvaluator<S>

Object
akka.javasdk.evaluation.DurableEvaluator<S>
Type Parameters:
S - The type of the state accumulated across the steps of this evaluation.

public abstract class DurableEvaluator<S> extends Object
A DurableEvaluator is a stateful component that evaluates agent interactions in multiple steps, with durable execution across those steps.

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.

  • Constructor Details

    • DurableEvaluator

      public DurableEvaluator()
  • Method Details

    • onEvaluation

      public abstract DurableEvaluator.Effect onEvaluation(EvaluationContext context)
      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.Effect with the first step transition, or directly the outcome
    • emptyState

      public S 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

      protected final S 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

      protected final EvaluationContext evaluationContext()
      The evaluation being run: the subject under evaluation, the evaluation id and the configuration of the evaluator. Available in onEvaluation(akka.javasdk.evaluation.EvaluationContext) and in every step method. The configuration is read from the running service for each step, so a step that runs after a deployment with a changed configuration sees the changed configuration.
      Throws:
      IllegalStateException - if accessed outside a handler method
    • effects

      protected final DurableEvaluator.Effect.Builder<S> effects()
      Returns a builder for the DurableEvaluator.Effect returned by onEvaluation(akka.javasdk.evaluation.EvaluationContext) and step methods.
    • settings

      public DurableEvaluator.Settings settings()
      Override to configure timeouts and retries for this evaluator.