Clef Decision (Jev-compatible)
Jev / System One API-compatible decision model on Workers AI - Clef & Clef-Flash return probabilities for noul/choice questions without free-form text
Clef is Cloudflare's open-source decision model on Workers AI - in the same family as Typesafe's Jev / System One API. Instead of generating free-form text, it takes a state plus typed questions and returns a probability for every allowed answer so agents can act without parsing LLM prose.
This experiment is a deployable Worker reference for @cf/cloudflare/clef and @cf/cloudflare/clef-flash: post a state and noul (binary) or choice (multiple-choice) questions, get structured probabilities back. Existing Jev integrations can switch by changing the endpoint and model.
Features
- Jev / System One-style decision API on Workers AI (Clef and Clef-Flash)
- Binary (
noul) and multiple-choice (choice) questions with probability distributions - No free-form generation - bounded outputs agents can route on immediately
- Stateless edge Worker - under ~60s, no storage required
- Pasteable
src/lib/decision.tscore for your own project
API Reference
POST /decision
Call Workers AI Clef or Clef-Flash to answer structured decision questions and return probability distributions. Compatible with Jev-style state + typed questions workflows.
Request body
{
"state": "Short description of the current state or context",
"questions": [
{
"type": "noul",
"question": "Will it rain tomorrow?"
},
{
"type": "choice",
"question": "What color is the sky?",
"choices": ["blue", "gray", "red"]
}
],
"model": "@cf/cloudflare/clef"
}Fields
statestring(required) - Context or state descriptionquestionsarray(required) - Array of question objectstypestring-"noul"(binary) or"choice"(multiple-choice)questionstring- The question textchoicesstring[]- Forchoicetype, the list of possible answers
modelstring(optional) - Model name, defaults to@cf/cloudflare/clef. Also supports@cf/cloudflare/clef-flash
Example request
curl -X POST https://clef-decision.example.workers.dev/decision \
-H "Content-Type: application/json" \
-d '{
"state": "The weather forecast shows clouds moving in.",
"questions": [
{ "type": "noul", "question": "Will it rain?" },
{ "type": "choice", "question": "When?", "choices": ["today", "tomorrow", "next week"] }
]
}'Example response
{
"model": "@cf/cloudflare/clef",
"state": "The weather forecast shows clouds moving in.",
"questions": [
{ "type": "noul", "question": "Will it rain?" },
{ "type": "choice", "question": "When?", "choices": ["today", "tomorrow", "next week"] }
],
"answers": [
{ "type": "noul", "probability": 0.73 },
{ "type": "choice", "probabilities": [0.15, 0.65, 0.2] }
]
}Error responses
400- Invalid JSON body or missing required fields502- Workers AI error
Error codes
INVALID_JSON- Request body is not valid JSONINVALID_REQUEST- Missing or invalidstateorquestionsAI_ERROR- Workers AI returned an error
Use Cases
- Agent routing - escalate, auto-resolve, or assign a ticket without a human in the loop
- Jev / System One alternative - drop-in decision model on Workers AI with Clef or Clef-Flash
- Support triage, invoice workflows, and security incident classification
- Multi-step agent graphs that need bounded yes/no or choice probabilities
- Fast edge decisions where LLM free-form text would be slow or hard to parse
Limitations
- Requires Workers AI binding (must deploy or use
--remotelocally) - Question complexity limited by model context window
- Probability outputs are model-generated estimates, not guarantees
- No persistent storage or decision history
- Optimized for structured decision questions - not open-ended chat or free-form generation
Use in your project
Copy these files into an existing Worker. Prefer Deployment to try the full experiment first. Source: apps/experiments/clef-decision.
import type { Env } from "../types/env";export type DecisionQuestion = | { type: "noul"; question: string } | { type: "choice"; question: string; choices: string[] };export type DecisionModel = "@cf/cloudflare/clef" | "@cf/cloudflare/clef-flash";export type DecisionResult = { model: DecisionModel; state: string; questions: DecisionQuestion[]; answers: unknown;};export async function runDecision( env: Env, state: string, questions: DecisionQuestion[], model: DecisionModel = "@cf/cloudflare/clef"): Promise<DecisionResult> { const answers = await env.AI.run(model, { state, questions, }); return { model, state, questions, answers, };}Deployment
Test your deployment
curl -X POST https://clef-decision.your-subdomain.workers.dev/decision \
-H "Content-Type: application/json" \
-d '{
"state": "The weather forecast shows clouds.",
"questions": [{ "type": "noul", "question": "Will it rain?" }]
}'Local Development
cd apps/experiments/clef-decision
npm install
npm run devThe Worker runs at http://localhost:8787 with --remote for AI binding access.
Test locally
curl -X POST http://localhost:8787/decision \
-H "Content-Type: application/json" \
-d '{
"state": "test state",
"questions": [{ "type": "noul", "question": "Is this working?" }]
}'Configuration
Bindings
This experiment requires a Workers AI binding declared in wrangler.json:
{
"ai": [
{
"binding": "AI"
}
]
}No additional secrets required.
Cloudflare Features Used
- Workers - Edge compute platform
- Workers AI - Run AI models at the edge
- Workers AI Clef decision API - Structured decision probabilities