Decision
Defines decisions that a DecisionModel answers over a single input.
Pair an input schema with named classification, rating, or probability
decisions using make, then answer them with DecisionModel.decide.
See
- make for building a definition from an input schema and decisions
Constructors
Creates a classification decision from labelled criteria. Throws if fewer than two labels are supplied.
See
- rate for an ordered scale
- probability for a single yes or no likelihood
Signature
declare function classify<Label extends string>(options: { readonly criteria: { [L in string]: string }; readonly instructions: string;}): Classify<Label>Example
(Choosing a department)
import { Decision } from "effect/unstable/ai"
const department = Decision.classify({ instructions: "Which team should handle this", criteria: { billing: "payments", technical: "bugs", sales: "pricing" }})Creates a decision definition from an input schema and named decisions.
DecisionModel.decide encodes the input with Schema.toCodecJson before
calling the provider. Answer keys and types are inferred from the decisions.
Throws if decisions is empty.
See
- Definition for the returned shape
Signature
declare function make<Input extends Constraint, Decisions extends Record<string, Any>>(options: { readonly decisions: Decisions; readonly input: Input;}): Definition<Input, Decisions>Example
(Defining ticket triage)
import { Schema } from "effect"import { Decision } from "effect/unstable/ai"
const Ticket = Schema.Struct({ subject: Schema.String, body: Schema.String})
const TicketTriage = Decision.make({ input: Ticket, decisions: { department: Decision.classify({ instructions: "Which team should handle this", criteria: { billing: "payments", technical: "bugs" } }), urgent: Decision.probability({ instructions: "The message is time-sensitive", criteria: { false: "No time pressure", true: "Needs action now" } }) }})probability
Creates a probability decision from instructions and optional outcome descriptions.
When criteria is supplied, descriptions for both false and true are required.
See
- classify for more than two outcomes
Signature
declare function probability(options: { readonly criteria?: { readonly false: string; readonly true: string; }; readonly instructions: string;}): ProbabilityExample
(Estimating urgency)
import { Decision } from "effect/unstable/ai"
const urgent = Decision.probability({ instructions: "The message is time-sensitive"})Example
(Providing outcome descriptions)
import { Decision } from "effect/unstable/ai"
const urgent = Decision.probability({ instructions: "The message is time-sensitive", criteria: { false: "The message can wait", true: "The message needs immediate attention" }})Creates a rating decision from an ordered list of criteria. Throws if fewer than two levels or duplicate levels are supplied.
See
- classify for unordered labels
Signature
declare function rate<Level extends string>(options: { readonly criteria: readonly Array<Level>; readonly instructions: string;}): Rate<Level>Example
(Rating frustration)
import { Decision } from "effect/unstable/ai"
const frustration = Decision.rate({ instructions: "How frustrated", criteria: ["calm", "frustrated", "angry"]})Models
Union of every decision kind.
Signature
type Any = Classify<string> | Rate<string> | ProbabilityDecision that assigns the input one label out of a set of criteria.
criteria maps labels to descriptions.
See
- classify for the constructor
- ClassifyAnswer for the answer produced by this decision
Signature
interface Classify<Label extends string> { readonly _tag: "Classify"; readonly criteria: { [L in string]: string }; readonly instructions: string;}ClassifyAnswer interface
Answer to a Classify decision.
label is chosen by the provider and need not have the highest probability.
confidence is an optional, provider-defined measure in [0, 1].
Signature
interface ClassifyAnswer<Label extends string> { readonly confidence?: number; readonly label: Label; readonly probabilities: { [L in string]: number };}Definition interface
Input schema and named decisions that run together in one provider call.
See
- make for the constructor
Signature
interface Definition<Input extends Schema.Constraint, Decisions extends Record<string, Any>> { readonly "~effect/ai/Decision": "~effect/ai/Decision"; readonly decisions: Decisions; readonly input: Input;}Probability interface
Decision that estimates how likely a statement about the input is to hold.
Optional criteria describes both outcomes when supplied.
The answer is the probability of true.
See
- probability for the constructor
- ProbabilityAnswer for the answer produced by this decision
Signature
interface Probability { readonly _tag: "Probability"; readonly criteria?: { readonly false: string; readonly true: string; }; readonly instructions: string;}ProbabilityAnswer interface
Answer to a Probability decision.
Signature
interface ProbabilityAnswer { readonly probability: number;}Decision that places the input on an ordered scale of criteria.
criteria lists levels from lowest to highest.
See
- rate for the constructor
- RateAnswer for the answer produced by this decision
Signature
interface Rate<Level extends string> { readonly _tag: "Rate"; readonly criteria: readonly Array<Level>; readonly instructions: string;}RateAnswer interface
Answer to a Rate decision.
rating is the probability-weighted position on the scale and may fall
between two levels, within [0, criteria.length - 1]. label is the level
with the highest probability, choosing the first criteria entry on ties.
confidence is an optional, provider-defined measure in [0, 1].
Signature
interface RateAnswer<Level extends string> { readonly confidence?: number; readonly label: Level; readonly probabilities: { [L in string]: number }; readonly rating: number;}Type IDs
Utility Types
Answer type for a single decision.
Signature
type Answer<D extends Any> = D extends Classify<infer Label> ? ClassifyAnswer<Label> : D extends Rate<infer Level> ? RateAnswer<Level> : D extends Probability ? ProbabilityAnswer : neverAnswers keyed by decision name.
Signature
type Answers<Decisions extends Record<string, Any>> = { [K in keyof Decisions]: Answer<Decisions[K]> }