--- name: effect-ai-decision-model description: Use Effect's Decision and DecisionModel APIs for System One models such as Jev. Covers typed classify/rate/probability/locate definitions, settled outcomes, images, TypeSafe/OpenRouter/OpenAI/Cloudflare providers, errors, and test implementations. --- # Effect AI Decision Model Baseline: `effect@4.1.7` and matching `@effect/*` packages. These AI APIs carry `@stability unstable`; inspect the consuming version's source before using newer contracts. References below are pinned to the stable tag. ## Define and call `Decision.make({ input, decisions })` pairs an input schema with a nonempty record of named decisions. One `DecisionModel.decide(definition, { input })` encodes one input and sends every decision together in one provider call. Answers retain the decision keys and inferred label literals. Keep definitions inferred rather than widening them to `Record`. ```ts import * as Decision from 'effect/ai/Decision'; import * as DecisionModel from 'effect/ai/DecisionModel'; import * as Effect from 'effect/Effect'; import * as Schema from 'effect/Schema'; class Ticket extends Schema.Class('Ticket')({ subject: Schema.String, body: Schema.String }) {} const Triage = Decision.make({ input: Ticket, decisions: { department: Decision.classify({ instructions: 'Which team should handle the ticket?', criteria: { billing: 'Payments, invoices, and refunds', technical: 'Bugs, outages, and integrations', other: 'Neither billing nor technical' } }), frustration: Decision.rate({ instructions: 'How frustrated is the customer?', criteria: ['Calm or neutral', 'Expresses frustration', 'Expresses intense anger'] }), urgent: Decision.probability({ instructions: 'Does the ticket need immediate attention?', criteria: { false: 'Can wait', true: 'Needs action now' } }) } }); type TriageAnswers = Decision.Answers; const triage = Effect.fn('Ticket.triage')(function* (raw: unknown) { const input = yield* Schema.decodeUnknownEffect(Ticket)(raw); return yield* DecisionModel.decide(Triage, { input }); }); ``` ### Constructors and answers Every constructor takes an options object. `Decision.Description` is `string | Schema.JsonObject | Schema.JsonArray`; instructions and descriptions can carry structured context without pre-stringification. | Constructor | Criteria | Answer | | --- | --- | --- | | `Decision.classify` | Record of at least two labels to `Description \| null`; null means no description | `{ label, probabilities, confidence? }`; both label and distribution keys use the inferred label union | | `Decision.rate` | At least two ordered strings or `{ label, description: Description }` entries, with unique labels | `{ rating, label, probabilities, confidence? }`; keys use labels, not descriptions | | `Decision.probability` | Optional `{ false: Description, true: Description }`; both required when supplied, neither nullable | `{ probability }`, the probability of true in `[0, 1]` | `rate` normalizes string entries to `{ label, description }`; stored `Rate.criteria` is always an array of these objects. Custom adapters must read each entry's `label` and `description`, not treat it as a string. - `classify` preserves the provider's chosen label, even if it differs from the distribution's maximum. The core checks membership, not argmax consistency. - `rate.rating` is the provider's probability-weighted zero-based position, in `[0, criteria.length - 1]`, potentially fractional. The core range-checks it but does not recompute it or check agreement with the distribution. `rate.label` is derived from the highest probability, breaking ties by criteria order. - Classify/rate confidence is optional and provider-defined in `[0, 1]`; preserve absence (for example with `Option.fromNullishOr`). Probability answers have neither confidence nor a distribution. Public answers have no `_tag` field. - `classify`, `rate`, and `make` synchronously throw on the cardinality/uniqueness violations above. Define valid static literals; parse dynamic definitions at their boundary before construction. These throws are outside `decide`'s error channel. Treat definitions and their nested inputs as immutable. Exported types: `Classify