Skip to content

Adaptive Learning

The Adaptive Learning Layer is where Layerr gets smarter over time. It analyses execution traces, extracts patterns, and adjusts future routing decisions based on what actually worked.

SourceWhat Is LearnedKey File
Execution OutcomesWhich provider/model succeeded for which workloadlearning/adaptive/engine.ts
User FeedbackExplicit thumbs-up/down on responsessrc/features/replay/learning/learningModel.ts
Provider LearningProvider-specific performance trendssrc/features/replay/learning/learningModel.ts
Strategy LearningWhich strategies work best for which intentslearning/adaptive/engine.ts
Failure PatternsCommon failure modes and their predictorsruntime/protection/classifier.ts
Execution Trace
|
v
[1] Extract Outcome --> Success? Quality? Cost? Latency?
|
v
[2] Correlate Features --> Which workload signals predicted the outcome?
|
v
[3] Update Weights --> Adjust routing and scoring weights
|
v
[4] Flag Drift --> Alert if provider quality degrades
|
v
[5] Build Summary --> Present learning insights to user

The confidence classifier (learning/adaptive/engine.ts) learns to predict routing confidence:

function classifyConfidence(
workload: WorkloadProfile,
provider: ProviderMetadata,
historicalTraces: Trace[]
): ConfidenceLevel {
// Uses historical success rate, error patterns, and workload similarity
// Returns: high | medium | low | uncertain
}

The failure classifier (runtime/protection/classifier.ts) categorises failures and learns from them:

Failure TypeLearning Action
Rate limitReduce request rate to this provider for similar workloads
TimeoutIncrease timeout or switch to faster model
Content policyFlag content type, suggest alternative provider
Provider outageAutomatically deprioritise provider for next N hours

Provider learning (src/features/replay/learning/learningModel.ts) tracks:

MetricDescription
providerLearningHistorical performance score per provider
strategyLearningHistorical performance score per strategy
Latency trendsIs this provider getting slower?
Error rate trendsIs this provider becoming less reliable?
Cost efficiencyQuality per dollar, trending over time
ComponentFilePurpose
ProviderLearningViewsrc/features/replay/learning/Shows provider learning curves
LearningReplayInsightssrc/features/replay/learning/Insights from replay analysis
AdaptiveLearningControlssrc/features/intelligence/Toggle learning features on/off
FileWhat It Does
learning/adaptive/engine.tsMain adaptive learning engine. Updates weights, classifies confidence
runtime/protection/classifier.tsFailure classification and pattern learning
src/features/replay/learning/learningModel.tsFrontend data model for learning insights
src/features/intelligence/hooks.tsReact hooks for intelligence and learning features
  1. Replay Layer → provides trace history for pattern extraction
  2. Provider Health → receives updated health scores from learning
  3. Scoring Layer → receives updated provider quality scores
  4. Strategy Engine → receives recalibration recommendations
  5. Explainability → includes learning insights in explanations