Class PersistedDecisionAnswers

java.lang.Object
dev.langchain4j.agentic.scope.PersistedDecisionAnswers

public final class PersistedDecisionAnswers extends Object
The persistable form of the answers that decision agents write to the AgenticScope: Choice and Scale are generic in their enum type, which the JSON serialization of the scope would lose, and none of the three types has a constructor a JSON library can call. The AgenticScopeJsonCodec converts them to these records before writing the scope and back after reading it.

The records keep one constant of the enum in a field declared as Enum, so that the codec writes its type next to it and resolves that type when reading, with its own class loader and allowlist, which always admits enums. The probabilities are kept by constant name.

  • Method Details

    • isCompositeAnswer

      public static boolean isCompositeAnswer(Object value)
      Whether the given value is an object with fields of the answer types, inherited ones included, like the record a decision agent returns to answer several questions in one call. Its fields cannot be converted in place, so such a value is not persisted, like a DecisionResult: the records of a recoverable system should have boolean and enum fields instead. The check runs on every agent output and on every state entry read by an untyped agent or persisted, so its result is computed once per class.
    • toPersisted

      public static Object toPersisted(Object value)
      The persistable form of the given value, or the value itself when it is not an answer of a decision agent.
    • fromPersisted

      public static Object fromPersisted(Object value)
      The answer restored from its persistable form, or the value itself when it is not one.