v157 · built-in ai · developer trial

Decisions API

A proposed built-in AI primitive — window.DecisionModel — for the questions generative models are overkill for: which of these options does this text mean? Instead of decoding tokens one by one, a decision model scores the developer's predefined options in a single forward pass and returns calibrated probabilities, a confidence value, and (for ordinal scales) an expected score, in tens of milliseconds on ordinary hardware. A “Semantic If” for routing, guardrails, and adaptive UI, with no option to hallucinate labels you never offered.

concepts

  1. The proposed surface, probed

    Member by member — DecisionModel.availability(), create(), decide(), destroy(), preference — this page checks the exact proposed IDL against your running browser, then makes a real availability() call and prints the genuine return value or the genuine exception. If a polyfill (like the WebAI extension) is installed, it is detected and exercised for real.

  2. Semantic-If command router

    The explainer's command-palette use case as a working page: type a goal in everyday words, and the page attempts a real create() + decide() against a schema of commands. Where the API is unavailable it shows the exact schema it tried, the real error, and — clearly labelled as the brittle pre-API workaround — what a keyword matcher does with the same input, typos and all.

  3. Draft guardrail pre-check

    Use case 3, live: a bug-report form that wants on-keystroke, on-device answers to two boolean questions (has repro steps? contains credentials?) and one score (severity 1–4, read off expectedScore). Real calls when the model exists; an honest unavailable panel, with the exact payload and thrown error, when it does not.

  4. Schema playground

    Build a decision schema interactively — add boolean, choice, and score questions, edit options and descriptions — and the page validates it against the explainer's rules (choice needs options, 2–16 is the practical band, score defaults to "1"–"5"), emits the exact JSON, and runs a real DecisionModel.availability(schema) against whatever your browser provides.

why it is proposed

Developers needing fast structured decisions over text currently choose between brittle keyword heuristics (fast, private, but broken by phrasing and typos), cloud classifiers (capable, but a privacy hand-off and a network round-trip on every keystroke), or an on-device generative LLM (10–50× heavier than the question deserves, and its freeform output can drift out of schema). A non-autoregressive decision model scores a closed set of options directly: type-safe by construction, calibrated so the application can act when confident and ask when not, and small enough to run on everyday devices. The proposal aligns with the Prompt API's conventions — availability() / create() with download monitor, AbortSignal, destroy(), transient user activation for downloads, and the "language-model" permissions-policy in its DevTrial form.

the proposed API

const schema = {
  context: "Document editor command palette",
  expectedInputs: [{ type: "text", languages: ["en"] }],
  questions: [{
    id: "command", type: "choice",
    prompt: "Which command best fulfills the user's goal?",
    options: [
      { label: "export_pdf", description: "Download or save the document as a PDF" },
      { label: "share_link", description: "Invite collaborators or copy a sharing link" },
      { label: "archive_doc", description: "Move the document to trash or archive" },
    ],
  }],
};

if ((await DecisionModel.availability(schema)) !== "unavailable") {
  const model = await DecisionModel.create(schema);        // may download; needs user activation
  const { command } = await model.decide("let my coworkers view this file");
  // command -> { id: "command", label: "share_link", confidence: 0.93,
  //              probabilities: { export_pdf: 0.04, share_link: 0.93, archive_doc: 0.03 } }
  model.destroy();
}

references