Class Decisions
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 TypeMethodDescriptionThe option the model selected for a choice question.confidence(String name) The model's own confidence in a choice or scale answer, when it reports one.booleanWhether the model declined to answer a particular question.booleanTurn a yes/no probability into a decision at your threshold.The gap between the winning option and the runner-up — the cleanest signal of "the model is unsure, send this to a human".doubleThe position of a scale answer across the levels you offered, as a probability-weighted index.names()probabilities(String name) All per-option probabilities for a choice question.doubleprobability(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.probabilityOf(String name, String option) How likely a specific option was, if the model reported per-option probabilities.dev.langchain4j.model.decision.response.DecisionResponseraw()The raw LangChain4J response — the escape hatch, so using EasyAI never means losing access to the layer underneath.summary()A short, readable line per answer — what gets logged or shown in an activity timeline.dev.langchain4j.model.output.TokenUsagetoString()
-
Method Details
-
isYes
Turn a yes/no probability into a decision at your threshold.- Parameters:
name- the question name you used when askingthreshold- the probability at or above which this counts as "yes", between 0.0 and 1.0- Returns:
trueif the reported probability reachesthreshold- Throws:
IllegalArgumentException- ifthresholdis outside 0.0–1.0, or the question is unknown or was not a yes/no question
-
probability
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
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
How likely a specific option was, if the model reported per-option probabilities.- Parameters:
name- the question nameoption- one of the options you offered- Returns:
- the probability, or
OptionalDouble.empty()if the model reported none
-
probabilities
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
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
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
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, higha mean of1.4means "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
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:
trueif the model refused this question
-
names
- Returns:
- the names of every question answered, in the order the provider returned them.
-
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
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.91is reviewable, one that saysurgent=yesis not.- Returns:
- e.g.
"urgent=0.91, team=technical (margin 0.42), severity=1.40"
-
toString
-