
Optima
LLM Routing Optimizer: Deterministic Pre-Scoring & Cost-Optimized Multi-Tier Model Router
Autonomous Multi-Model Adversarial Fuzzing Certified
Continuous stress-testing against prompt injections, cyclic parameter drift, and upstream rate limits via Llama 3.3 70B & DeepSeek-R1 (Autonomous Fuzzing).
Production Runtime Specification (Optima)
Direct integration contract for Optima. Deployable as a native microservice or imported directly into your agent runtime.
"""
Optima LLM Routing Optimizer: Deterministic Ingress Pre-Scoring & Model Routing
"""
import re
from typing import Dict, Any, Optional
from pydantic import BaseModel, Field
class RoutingDirective(BaseModel):
selected_tier: str
target_model: str
complexity_score: float = Field(..., ge=0.0, le=1.0)
estimated_cost_usd: float
reason: str
class OptimaRouter:
def __init__(self, frontier_threshold: float = 0.75):
self.frontier_threshold = frontier_threshold
def calculate_complexity(self, prompt: str) -> float:
score = 0.2
words = len(prompt.split())
if words > 400: score += 0.25
elif words > 150: score += 0.15
reasoning_markers = ['refactor', 'formal proof', 'deadlock', 'concurrency', 'architectural']
score += min(0.40, sum(0.12 for kw in reasoning_markers if kw in prompt.lower()))
code_markers = [r'```', r'def ', r'function ', r'class ', r'SELECT ', r'FROM ']
if sum(1 for m in code_markers if re.search(m, prompt)) >= 2:
score += 0.15
return min(1.0, round(score, 2))
def route(self, prompt: str, budget_cap_usd: float = 0.05) -> RoutingDirective:
complexity = self.calculate_complexity(prompt)
if complexity < 0.35:
return RoutingDirective(
selected_tier="LOCAL_SLM",
target_model="ollama/qwen2.5-coder-7b",
complexity_score=complexity,
estimated_cost_usd=0.0,
reason="Task simplicity permits zero-cost local execution."
)
elif complexity < self.frontier_threshold:
return RoutingDirective(
selected_tier="CLOUD_FLASH",
target_model="google/gemini-2.5-flash",
complexity_score=complexity,
estimated_cost_usd=0.0004,
reason="Standard reasoning requirement matches fast cloud tier."
)
else:
return RoutingDirective(
selected_tier="FRONTIER_REASONING",
target_model="anthropic/claude-3-7-sonnet",
complexity_score=complexity,
estimated_cost_usd=min(0.015, budget_cap_usd),
reason="High structural or logical complexity requires frontier model."
)
Production Failure Modes Addressed
Router agents over-escalating simple tasks to expensive frontier LLMs (Opus/GPT-4) because prompts lack deterministic state measurements, driving up cloud bills by 400-800%.
Using rigid if/then code logic bypassing the LLM router entirely or eating massive API costs.
Optima introduces deterministic token pre-scoring and semantic complexity profiling before any LLM API call is dispatched. Low-complexity tasks are routed to ultra-fast sub-cent models, preserving costly frontier reasoning models solely for validated complex workloads.
Autonomous State Machine & OTel Telemetry
Interactive trace visualizer showing ingress gating, in-memory state transition, and OTel emission.
Token Pre-Scoring & AST Density Gate
Tri-Tier Dynamic Model Router (SLM / Cloud / Frontier)
Cost Ceiling & Budget Governor
OpenTelemetry Route Spans & Cost Attribution
Enterprise Runtime Specifications & SLA
Zero Data Retention (ZDR) Architecture
Operates strictly in-memory. Prompts and tool arguments are zeroized immediately following circuit evaluation.
VPC & Google Cloud Run Topologies
Deployable as an ephemeral sidecar, containerized Cloud Run microservice, or in-process Python/TS library.
Deterministic Circuit Breaker SLA
99.95% production uptime commitment with automatic graceful degradation on upstream LLM provider outages.
Open-Spec Code Ownership
Full Apache-2.0 core licensing. You maintain absolute ownership of your deployed infrastructure and workflows.
Production Benchmark Telemetry
Empirical test telemetry from continuous integration regression suites.
Deploy Optima to Your Production Cluster
Explore the open-source specification on GitHub or connect with our engineering team to deploy a private, dedicated sandbox cluster on Google Cloud.