Class DecisionBuilder
What this replaces
Routing, triage, classification and gating are usually done with a full chat completion and a structured-output prompt. That is slow, costs a whole generation, and returns a word when what you needed was a number you can threshold. A decision call returns the number:
// one question, no names, no response object to unpack
if (EasyAI.decide(ticketText).isYes("Is the customer completely blocked?", 0.80)) {
pager.wake();
}
String team = EasyAI.decide(ticketText)
.choose("Which team should handle this?", "billing", "technical", "sales");
Several questions, one call
The cost win is asking everything at once. Name each question, then read the answers back by that name:
Decisions d = EasyAI.decide(ticketText)
.yesNo("urgent", "Is the customer completely blocked?")
.choice("team", "Which team should handle this?", "billing", "technical", "sales")
.scale("severity", "How severe is the business impact?", "low", "medium", "high")
.ask();
if (d.isYes("urgent", 0.80)) pager.wake();
route(d.choice("team"));
d.margin("team").ifPresent(m -> { if (m < 0.15) queueForHuman(); });
Why this fits the rest of EasyAI
It is the same principle as EasyAI.flow(): the deterministic spine stays in Java,
the model is only a sensor. A decision slots straight into a flow's condition, so a pipeline
can branch on a measured probability while remaining auditable — the model supplies the reading,
your Java supplies the threshold:
EasyAI.flow()
.step("read", ctx -> ticketText)
.stepIf("escalate",
ctx -> EasyAI.decide(ctx.inputText()).isYes("Is the customer angry?", 0.75),
ctx -> escalationService.open(ctx))
.run(ticketText);
Analogy: a thermometer, not a doctor. It gives you 38.7 °C. What counts as a fever, and what you do about it, stays with the person who has to answer for the decision.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionask()Send every question added so far as one call.Add a single-choice question.Add a single-choice question from a list.Add a single-choice question whose options carry descriptions.Ask one choice question and get the selected option.booleanAsk one yes/no question and decide at your threshold — the shortest useful form.doubleprobability(String question) Ask one yes/no question and get the raw probability, deciding yourself.doubleAsk one scale question and get the weighted position across the levels.Add an ordered-scale question.withApiKey(String apiKey) Override the API key for this call (otherwiseeasyai.decision.api-key, theneasyai.api-key).withBaseUrl(String baseUrl) Override the base URL for this call.withConfig(DecisionConfig config) Replace the whole configuration instead of overriding single values.withEventListener(EasyAIListener eventListener) Register a listener for the liveEasyAIEventstream, so a decision appears in your activity timeline like every other EasyAI operation, underEasyAIEvent.Source.DECISION.Name the decision model for this call (defaultDecisionConfig.DEFAULT_MODEL).withProvider(String provider) Override the provider for this call.Add a yes/no question.Add a yes/no question, spelling out what counts as yes and what counts as no.
-
Method Details
-
withConfig
Replace the whole configuration instead of overriding single values.- Parameters:
config- fully built decision settings;nullrestores properties-based defaults- Returns:
- this builder
-
withModel
Name the decision model for this call (defaultDecisionConfig.DEFAULT_MODEL).- Parameters:
modelName- the provider's decision-model id- Returns:
- this builder
-
withProvider
Override the provider for this call.- Parameters:
provider- provider id (currently"openai")- Returns:
- this builder
-
withApiKey
Override the API key for this call (otherwiseeasyai.decision.api-key, theneasyai.api-key).- Parameters:
apiKey- the provider API key- Returns:
- this builder
-
withBaseUrl
Override the base URL for this call. ReadDecisionConfigfirst: decisions use a dedicated endpoint that OpenAI-compatible chat providers do not implement.- Parameters:
baseUrl- the endpoint to call- Returns:
- this builder
-
withEventListener
Register a listener for the liveEasyAIEventstream, so a decision appears in your activity timeline like every other EasyAI operation, underEasyAIEvent.Source.DECISION.The event detail carries the numbers and the threshold, not just the verdict — which is what turns a timeline into an audit trail.
- Parameters:
eventListener- the listener (may benullto disable events)- Returns:
- this builder
-
yesNo
Add a yes/no question.- Parameters:
name- the name to read the answer back byquestion- the question, phrased so that "yes" is unambiguous- Returns:
- this builder
-
yesNo
Add a yes/no question, spelling out what counts as yes and what counts as no.Worth the extra two arguments when the boundary is the hard part — "urgent" means different things to a support desk and to a payments team, and saying so beats hoping the model guesses your definition.
- Parameters:
name- the name to read the answer back byquestion- the questionyesWhen- what makes the answer yesnoWhen- what makes the answer no- Returns:
- this builder
-
choice
Add a single-choice question.- Parameters:
name- the name to read the answer back byquestion- the questionoptions- at least two options; the answer comes back as one of these strings- Returns:
- this builder
-
choice
Add a single-choice question from a list.- Parameters:
name- the name to read the answer back byquestion- the questionoptions- at least two options- Returns:
- this builder
-
choice
Add a single-choice question whose options carry descriptions.Use this when the option names are codes your system understands but a model would not —
"L2_NET"means nothing on its own,"L2_NET" -> "network/connectivity faults"does.- Parameters:
name- the name to read the answer back byquestion- the questionoptionDescriptions- option → what it means; at least two entries- Returns:
- this builder
-
scale
Add an ordered-scale question.The answer is a probability-weighted position across the levels, so it can land between two of them — which is usually the honest answer.
- Parameters:
name- the name to read the answer back byquestion- the questionlevels- at least two levels, in order from lowest to highest- Returns:
- this builder
-
ask
Send every question added so far as one call.- Returns:
- the answers
- Throws:
IllegalArgumentException- if no question was added
-
isYes
Ask one yes/no question and decide at your threshold — the shortest useful form.- Parameters:
question- the questionthreshold- the probability at or above which this counts as "yes" (0.0–1.0)- Returns:
trueif the reported probability reachesthreshold
-
probability
Ask one yes/no question and get the raw probability, deciding yourself.- Parameters:
question- the question- Returns:
- the probability of "yes", 0.0–1.0
-
choose
Ask one choice question and get the selected option.- Parameters:
question- the questionoptions- at least two options- Returns:
- the chosen option, exactly as spelled here
-
rate
Ask one scale question and get the weighted position across the levels.- Parameters:
question- the questionlevels- at least two levels, in order from lowest to highest- Returns:
- the weighted index, from 0.0 to
levels.length - 1
-