Skip to content
Effect Days 2026 Get your ticket

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
16 exports Added in v4.0.0 Source

Constructors

classify

Added in v4.0.0 Source

Creates a classification decision from labelled criteria. Throws if fewer than two labels are supplied.

See

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"
}
})

make

Added in v4.0.0 Source

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

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

Added in v4.0.0 Source

Creates a probability decision from instructions and optional outcome descriptions. When criteria is supplied, descriptions for both false and true are required.

See

Signature

declare function probability(options: {
readonly criteria?: {
readonly false: string;
readonly true: string;
};
readonly instructions: string;
}): Probability

Example

(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"
}
})

rate

Added in v4.0.0 Source

Creates a rating decision from an ordered list of criteria. Throws if fewer than two levels or duplicate levels are supplied.

See

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

Any type

Added in v4.0.0 Source

Union of every decision kind.

Signature

type Any = Classify<string> | Rate<string> | Probability

Classify interface

Added in v4.0.0 Source

Decision that assigns the input one label out of a set of criteria. criteria maps labels to descriptions.

See

Signature

interface Classify<Label extends string> {
readonly _tag: "Classify";
readonly criteria: { [L in string]: string };
readonly instructions: string;
}

ClassifyAnswer interface

Added in v4.0.0 Source

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

Added in v4.0.0 Source

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

Added in v4.0.0 Source

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

Signature

interface Probability {
readonly _tag: "Probability";
readonly criteria?: {
readonly false: string;
readonly true: string;
};
readonly instructions: string;
}

ProbabilityAnswer interface

Added in v4.0.0 Source

Answer to a Probability decision.

Signature

interface ProbabilityAnswer {
readonly probability: number;
}

Rate interface

Added in v4.0.0 Source

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

Added in v4.0.0 Source

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

TypeId

Added in v4.0.0 Source

Brand for decision definitions.

Signature

declare const TypeId: "~effect/ai/Decision"

TypeId type

Added in v4.0.0 Source

Brand type for decision definitions.

Signature

type TypeId = "~effect/ai/Decision"

Utility Types

Answer type

Added in v4.0.0 Source

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 : never

Answers type

Added in v4.0.0 Source

Answers keyed by decision name.

Signature

type Answers<Decisions extends Record<string, Any>> = { [K in keyof Decisions]: Answer<Decisions[K]> }