Class Decisions

java.lang.Object
dyntabs.ai.decision.Decisions

public final class Decisions extends Object
The answers from one EasyAI.decide(...) call — one entry per question you asked.

Why this wrapper exists (it is not cosmetic)

The underlying answers carry a real trap: probabilities are optional. When the model does not report them, the raw probabilityOf(...) and margin() accessors throw IllegalStateException, and confidence() can be null. Code written against the happy path looks correct, passes review, and fails in production on the first answer that arrives without probabilities.

So every accessor here that can be absent returns OptionalDouble instead of throwing, and the ones that are always present return a plain double. The type tells you which is which, at compile time.

Thresholds are deliberate, never defaulted

There is no isYes(name) — only isYes(String, double). A yes/no answer is a probability, and turning a probability into a decision means choosing a line. That line is a business judgement, so the API makes you write it down where a reviewer can see it. "A measured probability crossed a threshold I chose" is a defensible sentence; "the AI decided" is not.

Mistakes are named, not cryptic

Asking for a question you never asked, or reading a choice answer as yes/no, fails with a message that names the question and lists what is actually available — rather than a ClassCastException or a null.


 Decisions d = EasyAI.decide(ticketText)
     .yesNo("urgent",   "Is the customer blocked from working?")
     .choice("team",    "Which team should handle this?", "billing", "technical", "sales")
     .scale("severity", "How severe is the impact?", "low", "medium", "high")
     .ask();

 if (d.isYes("urgent", 0.80)) pager.wake();        // the 0.80 is YOUR call, in the open
 route(d.choice("team"));
 double severity = d.mean("severity");             // 0.0 .. levels-1, can land between levels

 d.margin("team").ifPresent(m -> { if (m < 0.15) queueForHuman(); });   // only if reported
 

Analogy: a lab report. It states each measurement and its confidence; it does not tell you whether to operate. The threshold for acting is the clinician's, written in the notes.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    choice(String name)
    The option the model selected for a choice question.
    The model's own confidence in a choice or scale answer, when it reports one.
    boolean
    Whether the model declined to answer a particular question.
    boolean
    isYes(String name, double threshold)
    Turn a yes/no probability into a decision at your threshold.
    margin(String name)
    The gap between the winning option and the runner-up — the cleanest signal of "the model is unsure, send this to a human".
    double
    mean(String name)
    The position of a scale answer across the levels you offered, as a probability-weighted index.
     
     
    All per-option probabilities for a choice question.
    double
    The raw probability of "yes" for a yes/no question — useful for logging the number you actually decided on, or for feeding a gauge.
    probabilityOf(String name, String option)
    How likely a specific option was, if the model reported per-option probabilities.
    dev.langchain4j.model.decision.response.DecisionResponse
    raw()
    The raw LangChain4J response — the escape hatch, so using EasyAI never means losing access to the layer underneath.
    A short, readable line per answer — what gets logged or shown in an activity timeline.
    dev.langchain4j.model.output.TokenUsage
     
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Method Details

    • isYes

      public boolean isYes(String name, double threshold)
      Turn a yes/no probability into a decision at your threshold.
      Parameters:
      name - the question name you used when asking
      threshold - the probability at or above which this counts as "yes", between 0.0 and 1.0
      Returns:
      true if the reported probability reaches threshold
      Throws:
      IllegalArgumentException - if threshold is outside 0.0–1.0, or the question is unknown or was not a yes/no question
    • probability

      public double probability(String name)
      The raw probability of "yes" for a yes/no question — useful for logging the number you actually decided on, or for feeding a gauge.
      Parameters:
      name - the question name
      Returns:
      the probability of "yes", 0.0–1.0
    • choice

      public String choice(String name)
      The option the model selected for a choice question.
      Parameters:
      name - the question name
      Returns:
      the chosen option, exactly as you spelled it when asking
    • probabilityOf

      public OptionalDouble probabilityOf(String name, String option)
      How likely a specific option was, if the model reported per-option probabilities.
      Parameters:
      name - the question name
      option - one of the options you offered
      Returns:
      the probability, or OptionalDouble.empty() if the model reported none
    • probabilities

      public Map<String,Double> probabilities(String name)
      All per-option probabilities for a choice question.
      Parameters:
      name - the question name
      Returns:
      the probabilities, or an empty map if the model reported none (never null)
    • margin

      public OptionalDouble margin(String name)
      The gap between the winning option and the runner-up — the cleanest signal of "the model is unsure, send this to a human".
      Parameters:
      name - the question name
      Returns:
      the margin, or OptionalDouble.empty() if no probabilities were reported
    • confidence

      public OptionalDouble confidence(String name)
      The model's own confidence in a choice or scale answer, when it reports one.
      Parameters:
      name - the question name
      Returns:
      the confidence, or OptionalDouble.empty() if the model did not report it
    • mean

      public double mean(String name)
      The position of a scale answer across the levels you offered, as a probability-weighted index.

      It can land between two levels — with levels low, medium, high a mean of 1.4 means "somewhere between medium and high, closer to medium". That in-between value is the point of a scale question; rounding it away throws the information out.

      Parameters:
      name - the question name
      Returns:
      the weighted index, from 0.0 to levels - 1
    • isRefused

      public boolean isRefused(String name)
      Whether the model declined to answer a particular question.

      Check this before reading an answer when a question could touch content the model refuses to judge; reading a refused answer is an error, not an empty result.

      Parameters:
      name - the question name
      Returns:
      true if the model refused this question
    • names

      public Set<String> names()
      Returns:
      the names of every question answered, in the order the provider returned them.
    • modelName

      public String modelName()
      Returns:
      the model that answered, as reported by the provider.
    • tokenUsage

      public dev.langchain4j.model.output.TokenUsage tokenUsage()
      Returns:
      token usage for the call, for cost accounting (may be null).
    • raw

      public dev.langchain4j.model.decision.response.DecisionResponse raw()
      The raw LangChain4J response — the escape hatch, so using EasyAI never means losing access to the layer underneath.
      Returns:
      the underlying response
    • summary

      public String summary()
      A short, readable line per answer — what gets logged or shown in an activity timeline.

      Deliberately includes the numbers, not just the verdicts: an audit trail that says urgent=0.91 is reviewable, one that says urgent=yes is not.

      Returns:
      e.g. "urgent=0.91, team=technical (margin 0.42), severity=1.40"
    • toString

      public String toString()
      Overrides:
      toString in class Object