Decision unstable
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.
Descriptions can be null when the label needs no explanation.
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]: Description | null }; readonly instructions: Description;}): Classify<Label>Example Choosing a department
import { Decision } from "effect/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/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
unstableCreates 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: Description; readonly true: Description; }; readonly instructions: Description;}): ProbabilityExample Estimating urgency
import { Decision } from "effect/ai"
const urgent = Decision.probability({ instructions: "The message is time-sensitive"})Example Providing outcome descriptions
import { Decision } from "effect/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.
Strings serve as both label and description; use { label, description }
to separate them. Answers use the label.
Throws if fewer than two levels or duplicate labels are supplied.
See
- classify for unordered labels
Signature
declare function rate<Level extends string>(options: { readonly criteria: readonly Array<Level | { readonly description: Description; readonly label: Level; }>; readonly instructions: Description;}): Rate<Level>Example Rating frustration
import { Decision } from "effect/ai"
const frustration = Decision.rate({ instructions: "How frustrated", criteria: ["calm", "frustrated", "angry"]})Example Describing levels with structure
import { Decision } from "effect/ai"
const severity = Decision.rate({ instructions: "How severe is the reported issue?", criteria: [ "cosmetic", { label: "degraded", description: { what: "Broken or degraded feature, but workaround exists", examples: ["export fails in one browser but works in another"] } }, { label: "blocking", description: { what: "Blocking issue; no workaround exists", examples: ["cannot log in", "data loss"] } } ]})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; use null for a label without a description.
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]: Description | null }; readonly instructions: Description;}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 };}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;}Decision instructions or descriptions: a string, JSON object, or JSON array.
Details
TypeScript interfaces lack the index signature required by Schema.JsonObject;
use object literals, type aliases, or Schema types instead.
Signature
type Description = string | Schema.JsonObject | Schema.JsonArrayDecision 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: Description; readonly true: Description; }; readonly instructions: Description;}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, with labels for answers and
descriptions for the provider.
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<{ readonly description: Description; readonly label: Level; }>; readonly instructions: Description;}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 label
of 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]> }