Skip to content

Explainability & Decision Transparency

The Explainability Layer ensures that every decision Layerr makes can be understood, audited, and trusted. It produces structured rationales for why a specific model was chosen, why a fallback occurred, and how the strategy influenced the outcome.

  • Trust: Users need to know why their request went to Claude instead of GPT-4o
  • Debugging: Developers can trace routing failures back to root causes
  • Optimization: Workspace admins can understand how strategy changes affect routing
  • Compliance: Enterprises need audit trails for AI governance
Decision TypeExplanation FormatKey Function
Routing ExplanationWhy this provider/model was chosenbuildRoutingExplanation()
Scoring BreakdownPer-dimension scores with weightsbuildScoringExplanation()
Adaptive SelectionHow historical learning influenced the choicebuildAdaptiveSelectionExplanation()
Fallback OrderingWhy the fallback chain is ordered this waybuildFallbackOrderingExplanation()
Policy ExplanationHow workspace restrictions shaped the decisionbuildPolicyExplanation()
Capability MappingWhich capabilities were matched or missingbuildCapabilityExplanation()
Provider IntelligenceHistorical performance summary for the chosen providerbuildProviderIntelligenceExplanation()

Every explanation follows a structured template (explainability/templates.ts):

interface Explanation {
summary: string; // One-sentence summary
intentMatch: string; // How intent classification influenced routing
strategyApplied: string; // Which strategy was used and why
scores: ScoreBreakdown; // Per-dimension scores
providerRationale: string; // Why this provider was selected
fallbackRationale: string; // Why fallback chain is ordered this way
warnings: Warning[]; // Hard and soft warnings
alternatives: Alternative[]; // What other options were considered
}

Scores are translated into human-readable labels (explainability/templates.ts):

Score RangeLabelColour
90-100ExcellentGreen
75-89GoodTeal
60-74AcceptableYellow
40-59Below AverageOrange
0-39PoorRed

Functions: scoreToLabel() and scoreToColor() (also in src/components/orchestration/ScoreBadge.tsx)

  • Hard Warnings: Non-negotiable issues (provider blocked by policy, model doesn’t support required feature)
  • Soft Warnings: Recommendations (cheaper option available, higher-quality model possible)
ComponentFilePurpose
RoutingExplanationTimelinesrc/features/replay/RoutingExplanationTimeline.tsxVisual timeline of routing decisions
DecisionBreakdownPanelsrc/features/replay/DecisionBreakdownPanel.tsxDetailed score breakdown per dimension
ScoreBadgesrc/components/orchestration/ScoreBadge.tsxReusable score indicator with colour coding
FileWhat It Does
explainability/explainer.tsMain explanation builder. Orchestrates all explanation types
explainability/templates.tsTemplates and label mappings for human-readable output
explainability/types.tsTypeScript types for explanations, score breakdowns, and warnings
  1. Execution Engine → provides execution trace for post-hoc explanations
  2. Scoring Layer → provides per-dimension scores
  3. Strategy Engine → provides strategy rationale
  4. Workspace Profiles → provides policy constraints
  5. Replay → stores explanations alongside traces
  6. Frontend → renders explanations in the UI