MicroLLM: Local Hybrid "System One" Decision Engine
Inspired by TypeSafe AI's Jev, MicroLLM is a local probabilistic decision engine engineered for ultra-low latency (< 15 ms on CPU) while satisfying 100% of the 32 MUST requirements of the jevcompat 0.1 specification (POST /v1/systemone).
jevcompat 0.1 contract verified by 58 testsnoul (yes/no), choice (2 to 255 options), or score (2 to 10 ordinal levels).
2. Installation & Quickstart
The project is preconfigured in the local virtual environment .venv and requires neither a discrete GPU nor multi-gigabyte model downloads to run out of the box.
# 1. Start the local server on http://127.0.0.1:8000
.\.venv\Scripts\python -m microllm.server
# 2. Run all automated tests (JevCompat 32/32 MUST, AnyJev L0, RLCD² Trainer, Profiles & Guardrails)
.\.venv\Scripts\pytest --cov=microllm --cov-report=term-missing -v
# 3. Pull & quantize an Ollama-style INT8 ONNX profile into ~/.cache/microllm/
.\.venv\Scripts\python -m microllm.server pull fast-cpu-int8
.\.venv\Scripts\python -m microllm.server pull multilingual
.\.venv\Scripts\python -m microllm.server pull guardrail
.\.venv\Scripts\python -m microllm.server list
Built-in Web Interfaces
http://127.0.0.1:8000/: Decision Studio (Interactivenoul/choice/scoreplayground, Gear 1 vs Gear 2 vs Cascade comparator, Order-Flip audit, and RLCD² calibration lab).http://127.0.0.1:8000/documentation: This Complete Technical Documentation.http://127.0.0.1:8000/docs: Interactive OpenAPI / Swagger UI generated by FastAPI.
Environment Variables
PORT(default:8000): HTTP listening port for the local server.MICROLLM_API_KEY(optional): When set, enforces strictAuthorization: Bearer <key>authentication onPOST /v1/systemone(requirementhttp.auth).MICROLLM_HF_MODEL(optional): HuggingFace NLI model identifier (e.g.MoritzLaurer/DeBERTa-v3-small-mnli-fever-anli) automatically injected on startup.
3. The 3 Foundational Research Papers
MicroLLM implements the exact mathematical formulations and algorithms from three key papers published in September–October 2026 around the Jev ecosystem, all archived locally in docs/papers/:
| Publication | Authors & arXiv ID | Core Contributions Implemented in MicroLLM | Local PDF |
|---|---|---|---|
| OpenJev-RLCD: A Working RLCD Implementation | Z. Gao & P. WangarXiv:2609.38850 |
• Proposition 1: Variance identity proving that scoring the group mean rewards ungrounded rationale disagreement. • Algorithm 1: Two-stage training recipe (Stage 1 Pathwise Brier + Stage 2 Leave-One-Out REINFORCE with KL Anchor β = 0.04, c = 0.3). • Appendix A: Exact analytical verification of unbiased RLCD gradients via tabular enumeration. |
Open PDF |
| AnyJev Technical Report | Nokia Applied ResearcharXiv:2610.00831 |
• Answer Mass Gate m(s, π) measuring probability mass captured by candidate option tokens. • Theorem 1 (L0 Readout): Log-space circular rotation averaging that algebraically cancels slot/position bias. • Van der Corput Schedule + Early Stopping on log-odds margin μ(z) ≥ τ + Empirical Prior Debiasing (α = 0.75). |
Open PDF |
| StartLux-Decision: AutoThink Decision Models with RLCD² | StartLux & HKUarXiv:2610.17309 |
• Read-or-Think Cascade: Probability fusion p = (1 − α)p0 + αp1 (α = 0.75) between fast readout and deep evaluation. • RLCD2 Weighting: Beta(8, 2) difficulty weight w(y, q) ∝ uα(1 − u)β emphasizing hard decisions. • Hierarchical Tournament in chunks of 25 options to support up to 255 options. |
Open PDF |
4. The 4 Decision Primitives: noul, choice, score, multi
Unlike text-completion endpoints, POST /v1/systemone accepts a state (string, JSON object, or JSON array) and a dictionary of named questions. Every question is evaluated in strict isolation (its key name, ordering, or the presence of sibling questions in the batch never alters its probabilities).
4.1 The noul Primitive (Binary Yes / No Proposition)
Returns a single calibrated probability noul ∈ (0, 1) that the proposition holds true. Per rule noul.answer-shape of jevcompat 0.1, a noul answer must not include an unprefixed confidence field because the binary probability p ∈ (0, 1) already encodes full uncertainty: its distance from 0.5 (|2p − 1|) directly measures certainty.
// Request inside "questions":
"urgent_refund": {
"type": "noul",
"instructions": "Is the customer requesting an immediate refund?",
"criteria": {
"true": "Customer explicitly asks for an immediate refund or money back",
"false": "General question without refund request"
}
}
// Response inside "answers":
"urgent_refund": {
"type": "noul",
"noul": 0.9142
}
4.2 The choice Primitive (Categorical Selection Across 2..255 Options)
Selects one option among n ∈ [2, 255] mutually exclusive candidates. The official TypeSafe AI confidence formula is not maxi pi, but the maximum probability renormalized above uniform chance 1/n:
Thus, a uniform distribution (1/n, …, 1/n) yields exactly confidence = 0.0, whereas a degenerate distribution on a single option yields confidence = 1.0.
4.3 The score Primitive (Ordinal Scale Across 2..10 Levels)
Evaluates an ordered intensity rubric across n ∈ [2, 10] levels indexed 0, 1, …, n − 1. The returned score is the mathematical expectation 𝔼[S] = ∑i=0n−1 i · pi ∈ [0, n − 1], and confidence measures concentration around the modal level k = arg maxi pi:
4.4 The multi Primitive (Independent Multi-Label Classification Across 2..255 Labels)
Evaluates n ∈ [2, 255] non-mutually-exclusive labels independently (probabilities do not have to sum to 1.0). Each label k receives an independent calibrated probability pk ∈ (0, 1), active labels above threshold (default 0.5) are returned in labels, and overall multi-label certainty is:
5. Live Simulator: TypeSafe Confidence, Expectation & Conformal Set
Drag the logit sliders below to see how MicroLLM computes the calibrated softmax distribution, choice_confidence, ordinal score_expectation, score_confidence, and the Split Conformal prediction set 𝒞α(x) at quantile threshold q̂1−α in real time.
6. Complete 32/32 MUST Compliance Matrix (jevcompat 0.1)
The test suite in tests/test_jevcompat_contract.py systematically verifies every mandatory requirement of the jevcompat 0.1 specification:
| Category | Requirement IDs (jevcompat) |
MicroLLM Implementation Guarantee | Status |
|---|---|---|---|
| HTTP Transport | http.models, http.endpoint, http.auth |
GET /v1/models lists available engines; POST /v1/systemone validates Bearer tokens when MICROLLM_API_KEY is set. |
PASS (3/3) |
| Request / Response Envelope | request.state-required, request.state-types, request.questions-required, request.questions-non-empty, request.model-optional, response.top-level, response.answer-keys-match, response.usage-shape |
Strict validation via SystemOneRequest and SystemOneResponse in src/microllm/schemas.py; recursive rejection of NaN/Infinity. |
PASS (8/8) |
noul Primitive |
noul.minimal, noul.criteria-optional, noul.criteria-keys, noul.answer-shape |
Accepts omitted criteria or {"true", "false"}; returns {"type": "noul", "noul": p} in [0, 1] without an unprefixed confidence field. |
PASS (4/4) |
choice Primitive |
choice.criteria-required, choice.criteria-bounds, choice.option-values, choice.answer-shape, choice.choice-in-criteria, choice.probabilities-keys, choice.probabilities-valid, choice.confidence-range |
Supports 2 to 255 options; null, string, or structured JSON descriptions; sum(probabilities) == 1.0; exact choice_confidence. |
PASS (8/8) |
score Primitive |
score.criteria-required, score.criteria-bounds, score.answer-shape, score.score-range, score.legend-matches, score.probabilities-keys, score.probabilities-valid, score.confidence-range |
Supports 2 to 10 ordered levels; reconstructs exact legend "0".."n-1"; computes 𝔼[S] and score_confidence. |
PASS (8/8) |
| Errors & Isolation Semantics | errors.validation-shape, errors.no-5xx, semantics.question-id, semantics.batching, semantics.question-order |
All malformed payloads return 422 with loc[0] == "body" (never 500); every question is evaluated in isolation via _evaluate_isolated_question. |
PASS (5/5) |
7. Gear 1: Fast NLI Encoder, Per-K Temperature & Conformal Prediction
Implemented in src/microllm/backends/fast_encoder.py and src/microllm/calibration.py, Gear 1 combines four engineering breakthroughs from openJev-verdict-2.0, VerdictML, and StartLux-Decision:
1. NLI Hypothesis Sentence Templating
Pretrained Natural Language Inference encoders (DeBERTa-v3, ModernBERT, GLiClass) expect complete sentences. The function format_nli_hypothesis(option, description) transforms every candidate into:
"It is {option}: {description}."
This simple alignment boosts zero-shot classification accuracy by +2.1% to +6.9% with zero retraining.
2. Per-Cardinality (K) Temperature Scaling
A single global temperature underperforms when option counts K vary from 2 to 255. PerKTemperatureScaler fits a dedicated temperature TK > 0 per cardinality via NLL minimization (BFGS) and interpolates linearly in log(K) for unseen cardinalities.
x_abstain = True ⟺ |𝒞α(x)| > 1
8. Gear 2: AnyJev L0 Prefill Reader & Van der Corput Schedule
Implemented in src/microllm/backends/prefill_llm.py following Nokia Applied Research's AnyJev Technical Report (arXiv:2610.00831), Gear 2 solves the fundamental flaw of LLMs in decision-making: sensitivity to the order in which candidate options are presented in the prompt.
Van der Corput Schedule & Early Stopping
Instead of visiting circular shifts sequentially (t = 0, 1, 2, …), van_der_corput_order(K) visits rotations in binary-reflected order 0, ⌊K/2⌋, ⌊K/4⌋, ⌊3K/4⌋, … so that every prefix maximally separates option positions. Once t ≥ 2 and the top-2 log-odds margin exceeds τ (μ(z) = z(1) − z(2) ≥ τ), evaluation stops early (cutting latency by 2× to 4×).
Canonical Ordering & Empirical Prior Debiasing
For unordered choice questions, AnyJevPrefillBackend canonically sorts option keys before applying the van der Corput schedule, guaranteeing zero order-flip drift (0.0) even when early stopping triggers. For ordinal score questions, the natural level ordering is preserved (AnyJev Appendix E).
9. StartLux "Read-or-Think" Cascade
Implemented in src/microllm/backends/cascade.py (DualGearCascadeBackend), the cascade combines Gear 1's speed with Gear 2's position-unbiased depth using the fusion rule from StartLux-Decision (arXiv:2610.17309):
x_abstain == False ⟹ return p0
10. Local OpenJev-RLCD & RLCD² Training Pipeline
Implemented in src/microllm/rlcd.py, this module reproduces Algorithm 1 ("Calibrate, then Reinforce") from OpenJev-RLCD (arXiv:2609.38850) enhanced with RLCD2 difficulty weighting from StartLux-Decision (arXiv:2610.17309).
Stage 1: Pathwise Readout Calibration
Minimizes the differentiable Brier loss directly on the decision head logits with RLCD2 Beta(8, 2) difficulty weighting:
This stage removes initial overconfidence and brings readout probabilities into the region where RL gradients are informative.
Stage 2: Leave-One-Out REINFORCE + KL Anchor
Samples a group of G = 4 latent rationales per question, computes the KL-regularized reward against the frozen Stage 1 policy (β = 0.04, clip c = 0.3):
and applies the Leave-One-Out baseline Ai = R̃i − 1G − 1 ∑j≠i R̃j.
11. Typed Python SDK (MicroJevClient) & HuggingFace / ONNX Adapters
The client SDK (src/microllm/client.py) provides a strongly-typed API that validates inputs locally and returns structured NoulResult, ChoiceResult, ScoreResult, and MultiResult objects:
from microllm import MicroJevClient, Noul, Choice, Score
client = MicroJevClient(base_url="http://127.0.0.1:8000")
res = client.ask(
state="I was billed twice for invoice #4092! Please refund the duplicate charge today.",
questions={
"is_refund": Noul(
instructions="Is the customer requesting an immediate refund?",
true_description="Customer asks for a refund or money back",
false_description="No refund mentioned",
),
"department": Choice(
options={
"billing": "Invoices, double charges, refunds",
"technical": "Bugs, crashes, API outages",
"shipping": "Delayed package, lost parcel",
},
instructions="Which department should handle this?",
),
"urgency": Score(
levels=["Low", "Medium", "High / Immediate"],
instructions="How urgent is this request?",
),
},
)
print(res["is_refund"].value, res["is_refund"].probability) # True, 0.914
print(res["department"].value, res["department"].confidence) # "billing", 0.782
print(res["urgency"].value, res["urgency"].score) # "High / Immediate", 1.74
Plugging in an Open-Source HuggingFace or ONNX Runtime Model (Approach 1 + 2)
To avoid reinventing the wheel, FastEncoderBackend and AnyJevPrefillBackend accept any external scorer via the logit_scorer parameter or the built-in factories in microllm.backends.base:
from microllm.backends.base import create_hf_zero_shot_scorer, create_onnx_nli_scorer
from microllm.backends.fast_encoder import FastEncoderBackend
from microllm.backends.prefill_llm import AnyJevPrefillBackend
# Option A: HuggingFace NLI Model (requires: pip install microllm[torch])
hf_scorer = create_hf_zero_shot_scorer("MoritzLaurer/DeBERTa-v3-small-mnli-fever-anli")
gear1_hf = FastEncoderBackend(logit_scorer=hf_scorer)
gear2_hf = AnyJevPrefillBackend(logit_scorer=hf_scorer)
# Option B: INT8 Quantized ONNX Runtime Session on CPU (requires: pip install microllm[onnx])
onnx_scorer = create_onnx_nli_scorer("models/deberta-v3-small-int8.onnx")
gear1_onnx = FastEncoderBackend(logit_scorer=onnx_scorer)
12. Complete HTTP Endpoint Reference & Source Code Map
| Method & Route | Purpose | Request / Response Payload |
|---|---|---|
GET /v1/models |
Lists available System One engines (jevcompat §1) |
Returns jev-latest (Cascade), microllm-gear1-fast, and microllm-gear2-anyjev-l0. |
POST /v1/systemone |
Primary System One decision endpoint (32/32 MUST) | Input: {model?, state, questions}. Output: {model, answers, usage}. |
POST /v1/calibrate |
Per-K temperature scaling, Split Conformal & Clopper-Pearson | Fits TK, computes q̂1−α, Brier Score, ECE, and reliability diagram bins. |
POST /v1/rlcd |
Local RLCD Stage 1 + Stage 2 training (Algorithm 1) | Runs Stage 1 Pathwise + Stage 2 LOO-KL with Beta(8, 2) weights and returns Risk–Coverage curves. |
POST /v1/studio/analyze |
Side-by-side Gear 1 vs Gear 2 vs Cascade diagnostics | Evaluates all 3 engines in parallel, computes token_attribution, and runs the Order-Flip invariance audit. |
POST /v1/guardrail |
Zero-Shot AI Safety Guardrail pack (arXiv:2609.29429) |
Evaluates 4 rubrics in < 5 ms on CPU: prompt_injection, destructive_operation, pii_or_secret_leak, and hallucination_risk (with groundedness_score). |
GET /v1/profiles & POST /v1/profiles/pull |
Ollama-style ONNX INT8 Profile Registry (microllm pull) |
Manages curated hardware profiles (fast-cpu-int8, multilingual, guardrail) cached in ~/.cache/microllm/. |
POST /v1/batch |
Bulk CSV / JSONL batch decision evaluation | Evaluates up to 500 states per call and flags rows requiring human review (abstain: true). |
GET / |
Interactive Decision Studio Web UI | Full web application for testing decision prompts and visualizing SVG calibration curves. |
GET /documentation |
Complete HTML Technical Documentation | Serves this interactive documentation page directly from FastAPI. |
Source Code Architecture (MicroLLM)
src/microllm/schemas.py: Strict Pydantic v2 models for/v1/systemoneand recursiveNaN/InfJSON rejection.src/microllm/confidence.py: Official TypeSafe AI formulas (choice_confidence,score_confidence,score_expectation,multi_confidence,run_hierarchical_tournament).src/microllm/calibration.py:PerKTemperatureScaler,SplitConformalCalibrator,clopper_pearson_threshold, Brier Score, and ECE.src/microllm/rlcd.py: OpenJev-RLCD Algorithm 1, Proposition 1 variance identity, RLCD2 Beta(8, 2) weighting, and Appendix A exact tabular gradient check.src/microllm/registry.py: Hardware profile registry (fast-cpu-int8,multilingual,guardrail) and symmetric per-row INT8 quantization.src/microllm/backends/:base.py(deterministic multilingual embeddings + HF/ONNX adapters),fast_encoder.py(Gear 1),prefill_llm.py(Gear 2 AnyJev L0),cascade.py(StartLux Cascade).src/microllm/benchmarks.py&src/microllm/quality_suite.py: 540-item benchmark runner (microllm benchmark) and 750-to-1,000 case 8-track validation suite (docs/TEST_PLAN.md).src/microllm/client.py: Typed Python SDK (MicroJevClient,AsyncMicroJevClient,Noul,Choice,Score,Multi).src/microllm/server.py: FastAPI server,/v1/*endpoints, Decision Studio (/), and Documentation (/documentation).
540-Item Multi-Track Corpus & 750-Case Validation Suite
MicroLLM includes both a 1-command 540-item evaluation corpus (microllm benchmark, stored in benchmarks/microllm_eval_corpus.jsonl) and a comprehensive 750-to-1,000 case 8-track Quality & Performance Suite (python -m microllm.quality_suite, specified in docs/TEST_PLAN.md).
| Evaluation Track | Baseline / Naive LLM | MicroLLM (Gear 1 + AnyJev L0 + RLCD2) | Guarantee / SLA Gate |
|---|---|---|---|
| JevBench-Core (160 items) | 68.0% – 70.6% (Zero-shot 9B–32B) | 98.1% (noul 92.5%, choice 100%, score 100%, multi 100%) |
32/32 MUST · Gate G1 ≥ 95% |
| DecisionPivot (40 pairs / 80 items) | 31.0% (Hosted Jev) / 57.0% (1-Pass) | 100.0% Pair Accuracy (40/40 contrastive pairs) | Gate G2 ≥ 90% |
| AnyJev-Order (60 items, K=2..20) | 50.0% Order-Flip Rate | 0.000000 Flip Rate · 0.000000 Max Drift | 78.3% fewer rotations · Gate G3 |
| Guardrail-Safety (80 items) | Uncalibrated prompt filter | F1: 100.0% · Recall: 100.0% · FPR: 0.0% | 4 Rubrics · Gate G4 ≥ 94% |
| Calibration-RLCD2 (160 items) | Raw ECE: 15.85% · Brier: 0.3275 | Calibrated ECE: 6.15% · RLCD2 Brier: 0.1525 | 98.8% Conformal Coverage · Gate G5 |
| CPU Latency & 750-Case Stress Suite | 350 – 1,200 ms (70B GPU API) | p50: 0.14 ms · p95: 1.05 ms (< 3 ms on CPU) | 8/8 Gates PASS (750/750 Cases) |