ElementsAI

Decisions

One call that labels a ticket, and a person when the answering decider is not allowed to decide alone.

A decision labels one piece of work: which queue a ticket belongs in, and whether it needs a person today. The decider is the model that answers. Autonomy is that decider's certificate, not a property of the decision.

The one rule

Name a decider and an otherwise. otherwise is a Gate, or "abstain". Only that decider's certificate in oke-decisions.lock.json can return auto.

Quick start

Declare the decider and the questions

otherwise is a real gate. The people who hold it answer when the model is not allowed to.

src/core/ai.ts
import { ai, gate } from "okengine";

export const ops = gate.policy("ops", ({ operator }) => operator.id !== null);

export const jev = ai.decider("jev", {
  provider: "openrouter",
  model: "typesafe/jev-1.13-20260917",
});

export const triage = ai.decision("triage", {
  decider: jev,
  otherwise: ops,
  ask: {
    team: ai.choice("Which team owns this ticket?", {
      billing: "Billing",
      technical: "Technical",
    }),
    urgent: ai.boolean("Does this need a person today?"),
  },
});

Every choice also accepts none_of_these. That answer is never auto. Question ids meta and $ are reserved.

Call it from a durable Flow

A gate parks the run. An HTTP trigger cannot park. Emit a signal and decide in a consumer.

src/flows/support.ts
import { flow, on, signal } from "okengine";
import { triage } from "../core/ai.ts";

export const routed = signal.once("support.routed");

export const route = on(
  signal.once("support.opened"),
  flow("support.route", {
    durable: true,
    do: async (input, fx) => {
      const result = await fx.decide(triage, input);
      await fx.emit(routed, result);
      return result;
    },
  }),
);

durable: true is required when otherwise is a gate. "abstain" can run without it.

Read how, by, and why

auto is the decider's value. Anything else takes otherwise.

{
  "team": "technical",
  "$": {
    "team": { "how": "auto", "by": "jev", "p": 0.91, "raw": { "technical": 0.91 } },
    "urgent": { "how": "auto", "by": "jev", "p": 0.54, "raw": { "noul": 0.54 } }
  }
}

Result

FieldWhen
howauto, reviewed, or abstained.
byThe decider that answered.
whyOnly when the question is not auto.
pCalibrated confidence.
rawThe distribution. A boolean keeps { noul }.
auditedThe auto value was sampled for a label.

why is one of uncertain, refused, none_of_these, uncertified, drift, or outage.

otherwise: "abstain" returns null and does not park. how is abstained. A Gate parks until someone who passes it submits every open question. Console on port 6533 resolves that park. There is no timeout.

A refusal is not a label. The value is null, why is refused, and the review row reads refused by <decider>.

Options

OptionRequiredMeaning
decideryesAn ai.decider handle. There is no default.
otherwiseyesA Gate, or "abstain".
backupnoTried only after an outage: open breaker, HTTP 5xx, or timeout.
askyesai.choice, ai.score, or ai.boolean.
autonomyno{ maxError, audit }. audit is required when this is set.
localeno(input) => string. Each locale is its own certificate slice.
evalsnoSeed JSONL for oke decide certify.
innoFields kept when labels are exported.

shadow is reserved. Using it fails with shadow is planned.

backup does not run on HTTP 4xx. That is DecisionRequestError, and the breaker stays closed. State larger than maxContext throws DecisionInputTooLarge before any call. It does not take otherwise.

Auto requires the answering decider's own certificate: same echoed model, unexpired, same question hash, and a calibrated score at or above the threshold. A backup that already has a certificate does not need another one.

Certificates

oke decide certify <name> --deciders a,b calls each decider on the seed file and writes lockfile version 2. One certificate per decider. The table prints accuracy, ECE, certified coverage, p50, p95, and cost.

{
  "version": 2,
  "decisions": {
    "triage": {
      "deciders": {
        "jev": { "model": "typesafe/jev-1.13-20260917", "pinned": true, "questions": {} }
      }
    }
  }
}

A version 1 file fails with: oke-decisions.lock.json is not version 2. Run oke decide certify to recertify.

OpenRouter certificates bind to the dated slug. If the catalog lists a dated id, certify requires that id. OpenAI binds to the echoed alias, stores pinned: false, and sets expiresAt to certify time plus 30 days. Certify prints that the model is unpinned. After expiry, why is uncertified.

oke decide promote <name> installs the operator candidate for one decision. oke decide labels <name> --export writes reviewed labels as seed JSONL. The file contains production data. oke decide models lists catalog id, canonical slug, context, and input modalities.

t.ai.decide(decision, answers) scripts probabilities, or { refusal: "…" }. The refusal string is not stored.

Drivers

drivers.decide defaults to { test: "mock" }. Unset dev and prod call the decider host. Pin mock when a local boot must stay off the network.

Troubleshooting

Learn more

  • Deciders — presets, protocols, and pinning
  • Gate — the policy on otherwise
  • fx — fx.decide
  • CLI — oke decide certify, promote, labels, models
  • Configuration — drivers.decide

Next

On this page