Skip to main content

TEIA Cognitive Router

TEIA Cognitive Router is a deterministic, rule-based LLM router: it assigns each prompt to a Local, Hybrid, or Cloud model tier using a fixed arithmetic formula, and seals every decision with a SHA-256 audit record that can be re-verified offline.

ML-based LLM routers change behavior when their weights are retrained, so the same prompt can route differently next month and past decisions cannot be reproduced. Organizations operating under EU AI Act, GDPR, HIPAA, or SEC/FINRA requirements need to prove, after the fact and independently, why a given request went to a given model. TEIA's routing is pure arithmetic with fixed weights: the same input always produces the same decision and the same hash, and a standalone verifier can re-derive any past decision from the original prompt.

pip install teia-cognitive-router
teia-route --text "Extract all invoice numbers from this document" --output decision.json
# → routing_decision: "Local", audit_seal.sha256 attached

teia-verify --file decision.json --text "Extract all invoice numbers from this document"
# → AUDIT PASS: The routing decision is mathematically proven and unmodified.

PyPI · Paper (DOI) · License: Apache 2.0


How routing works

The router computes a Semantic Entropy Score in [0..1] from six measurable text features — no neural weights, no training data, no network calls:

Feature Weight
Token score (normalized prompt length) 20%
Vocabulary diversity (unique token ratio) 15%
Reasoning verb density 30%
Data operation score (inverted — simple extraction lowers score) 15%
Structural complexity (multi-part questions, nesting) 10%
Constraint density (format specs, hard requirements) 10%
Score Tier Typical task
0.00 – 0.35 Local Extraction, reformatting, translation
0.35 – 0.65 Hybrid Code review, summarization
0.65 – 1.00 Cloud Root cause analysis, synthesis

The formula and weights are fixed per version; any change to weights requires a version increment, so a decision made under version X is reproducible under version X indefinitely.

Every decision is

  • Reproducible — same input text → same routing decision → same SHA-256 hash
  • Explainable — the routing_rationale field states which features drove the verdict
  • Auditableaudit_seal.sha256 is a cryptographic commitment to the decision body; audit logs are Merkle-chained (teia-verify --verify-chain)
  • Offline — stdlib-only, zero network calls, no GPU, < 5 MB memory

Measured results

  • Compliance-safe mode (default): 99.6% average quality retention and 16.3% cost reduction (USD 371.25 vs 443.70/month projected) versus an all-cloud baseline, evaluated on the 80-question MT-Bench set under a fixed deterministic 3-tier quality model (Local=0.98, Hybrid=0.99, Cloud=1.00). In this mode only provably trivial prompts (entropy < 0.20) route to Local.
  • Max-savings mode (opt-in): 95.2% cost reduction (USD 21.45 vs 443.70/month projected) on the same 80-question MT-Bench set — at 53.8% quality retention under the max-savings quality model (Local=0.90, Hybrid=0.95, Cloud=1.00). The trade-off is severe and stated deliberately: this mode routes 82% of MT-Bench to Local and fails the ≥95% retention target that compliance-safe mode meets. Artifact: benchmark_multidomain/quality_cost_results_max_savings.json.
  • Throughput: ~10,800 routing decisions/s median, individual runs spanning 9,400–13,500, on a desktop i3-10100F with CPython 3.14 (stdlib only). The ~35% spread is turbo-clock decay across a sustained run, not routing variance — the routing distribution is bit-identical in every run. This measures route() alone (entropy plus threshold decision), excluding sealing, ledger append and gateway overhead. Method and every individual run: benchmark_multidomain/throughput_measurement.json.

Reproduce locally against public datasets:

python tests/teia_router_bench_harness.py --input tests/mt_bench_questions.json
python tests/teia_router_throughput_bench.py

Python API

from teia_cognitive_router import route_and_seal

sealed, json_str = route_and_seal("Extract all dates from this document")
print(sealed["routing_decision"])                   # "Local"
print(sealed["gpu_economics"]["delta_usd_saved"])   # 0.000440
print(sealed["audit_seal"]["sha256"])               # deterministic SHA-256

CLI tools (installed with the package)

Command Purpose
teia-route Route a prompt and emit a sealed canonical-JSON decision
teia-verify Standalone verifier: prove a stored decision is unmodified; --verify-chain checks the Merkle-chained audit log
teia-gateway Deterministic FastAPI proxy (OpenAI-compatible) with JSONL audit log
teia-policy JSON policy rules with hard compliance overrides (HIPAA/GDPR/SOC 2), deterministic policy_seal
teia-report HTML compliance report from the audit JSONL (EU AI Act Art. 12/13, GDPR Art. 22, SOC 2 CC7)
teia-notarize RFC 3161 timestamp anchoring for audit chains

Documentation

Document Description
Python Integration Guide vLLM / Kubernetes / LiteLLM integration
Cognitive Routing Theory Formula derivation and design rationale
P41.0 Economics Proof Empirical GPU savings, sealed by SHA-256

Design invariants

All scripts in this repository enforce:

  • Idempotence: every script is safe to re-execute; same inputs produce identical outputs including SHA-256 hashes
  • Determinism at boundaries: canonical JSON (sorted keys, UTF-8 without BOM), no unseeded randomness in integrity paths
  • Absolute paths: no relative execution from system directories
  • Entropy honesty: compression is never forced on incompressible data; every fallback verdict is declared explicitly

Version history

Version Central result
v8.0.0–v9.0.0 Semantic entropy routing · Python port
v10.0.0–v11.0.0 3-tier quality model · cryptographic audit verifier · public benchmark harness
v12.0.0–v13.0.0 Standalone Python package · PyPI release · deterministic FastAPI gateway
v14.0.0 Compliance-safe mode default · MT-Bench 99.6% quality retention
v15.0.0–v16.0.0 Merkle-chained audit ledger · RFC 3161 notary
v17.0.0–v18.0.0 Self-contained HTML audit dashboard · compliance report generator
v19.0.0 Routing policy engine · JSON policy rules · deterministic policy_seal

License

TEIA Cognitive Router is licensed under Apache 2.0. The authoritative text is LICENSE in this repository; the same license is declared in pyproject.toml and on PyPI. The benchmark artifacts in this repository are provided as-is for reproducibility of the published results.


Developed and benchmarked on modest hardware: i3-10100F · 16 GB RAM · PowerShell 7+ · Python 3.8+.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

teia_cognitive_router-1.6.0.tar.gz (93.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

teia_cognitive_router-1.6.0-py3-none-any.whl (53.1 kB view details)

Uploaded Python 3

File details

Details for the file teia_cognitive_router-1.6.0.tar.gz.

File metadata

  • Download URL: teia_cognitive_router-1.6.0.tar.gz
  • Upload date:
  • Size: 93.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for teia_cognitive_router-1.6.0.tar.gz
Algorithm Hash digest
SHA256 0136a5ead624c2bf1414d102c7211048716b99704dc52f66d94da066ea8967e8
MD5 e99e1cb18521e74338e95cef14e678e4
BLAKE2b-256 f2bde92e5a695948d6a0c3a827b5a534b91c940532c38140287338f4a132327a

See more details on using hashes here.

File details

Details for the file teia_cognitive_router-1.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for teia_cognitive_router-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0bb31a28177485bb7cce2f757969b85da56789dbd03c92b5a5a271820522ad3a
MD5 83f8653a91f06a5206791d3eeff0cb9f
BLAKE2b-256 076e16daeeba3611ffda5c210b18bb208417e6c4a3ef9c9120c37fc42be67789

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page