What Is the lkgp (Last Known Good Provider) Combo Strategy in OmniRoute?
The lkgp combo strategy is a session-aware routing algorithm that prioritizes reusing the AI provider that successfully handled a previous request, falling back to rule-based evaluation when that provider is disabled or circuit-breaker-open.
The lkgp (Last Known Good Provider) strategy is one of OmniRoute’s built-in combo routing strategies designed specifically for multi-turn conversational workloads. According to the OmniRoute source code, this strategy maintains session stickiness by checking the lastKnownGoodProvider field in the routing context and bypassing standard scoring when a viable previous provider exists.
How the lkgp Strategy Works
The algorithm operates as a priority routing layer that executes before standard rule evaluation. In open-sse/services/autoCombo/routerStrategy.ts (lines 299–324), the LKGPStrategyImpl follows a strict decision tree to determine provider selection.
Step-by-Step Selection Logic
-
Check the enablement flag. If
context.lkgpEnabled === false, the strategy immediately delegates to the standard rules strategy without evaluating the last known provider. -
Validate the saved provider. If
context.lastKnownGoodProvideris set, the strategy filters the current provider pool for candidates matching that provider identifier with a closed circuit-breaker state. -
Immediate selection. When a matching candidate exists and is healthy, the strategy returns it with
finalScore: 1.0and the reason string"LKGP: using last known good provider …", bypassing all latency, cost, and error-rate calculations. -
Graceful fallback. If the saved provider is missing, disabled, or its circuit breaker is
OPEN, the strategy falls back to the rules strategy (the default balanced router) to select the best available provider based on current performance metrics.
Implementation Details in OmniRoute
The core logic resides in open-sse/services/autoCombo/routerStrategy.ts, where the selectWithStrategy function handles the lkgp routing path. The implementation checks circuit-breaker states using the provider pool’s health metrics before committing to the last known good provider.
Documentation in docs/routing/AUTO-COMBO.md (section 5, lines 60–66) describes this approach as "last known good provider first," recommending it for scenarios where maintaining conversational context across turns outweighs cost or latency optimizations.
Configuration and Usage Examples
Enabling lkgp in Combo Configuration
Configure a combo route to use the sticky provider strategy via the routerStrategy field:
{
"name": "chat-with-sticky-provider",
"strategy": "auto",
"config": {
"routerStrategy": "lkgp"
}
}
Programmatic Provider Selection
Use the selectWithStrategy function with a populated routing context to leverage session stickiness:
import {
selectWithStrategy,
} from "@omniroute/open-sse/services/autoCombo/routerStrategy";
const pool: ProviderCandidate[] = /* populated from provider registry */;
const context: RoutingContext = {
// ... other context fields ...
lkgpEnabled: true,
lastKnownGoodProvider: "openai", // Set from previous successful call
};
const decision = selectWithStrategy(pool, context, "lkgp");
console.log(`Chosen provider: ${decision.provider}`);
// Output: "Chosen provider: openai"
console.log(`Score: ${decision.finalScore}`);
// Output: "Score: 1.0"
Disabling lkgp for Specific Requests
Force fallback to rule-based routing by disabling the flag in the context:
const ctx: RoutingContext = {
// ...
lkgpEnabled: false, // Forces fallback to rules strategy
};
const decision = selectWithStrategy(pool, ctx, "lkgp");
console.log(decision.reason); // e.g., "RulesStrategy: latency-optimized selection"
Handling Circuit-Breaker Failures
When the saved provider becomes unhealthy, the strategy automatically falls back:
// Assume "anthropic" is currently OPEN (circuit breaker triggered)
const ctx: RoutingContext = {
lkgpEnabled: true,
lastKnownGoodProvider: "anthropic",
};
const decision = selectWithStrategy(pool, ctx, "lkgp");
// Because candidate is OPEN, strategy falls back:
console.log(decision.reason); // "RulesStrategy: ..."
When to Use the lkgp Strategy
Multi-turn conversations. Use lkgp when building chat applications or agentic workflows where the same provider handling previous turns maintains context consistency and reduces token overhead from re-prompting.
Provider-specific optimizations. Some providers cache embeddings or maintain session state that improves subsequent turn latency; lkgp ensures you remain on that optimized path.
A/B testing isolation. When running provider comparisons, lkgp keeps individual user sessions pinned to their assigned provider variant, preventing cross-provider pollution in your metrics.
Summary
- The lkgp strategy prioritizes the provider stored in
lastKnownGoodProviderwhen it is healthy andlkgpEnabledis true. - Selection occurs in
open-sse/services/autoCombo/routerStrategy.tswith a perfect score of1.0, bypassing standard rule evaluation. - The strategy falls back to the rules strategy when the saved provider is unavailable, disabled, or circuit-breaker-open.
- Configuration requires setting
routerStrategy: "lkgp"in combo configs and populating thelastKnownGoodProviderfield in the routing context.
Frequently Asked Questions
Is lkgp enabled by default in OmniRoute?
No. The lkgp strategy requires explicit opt-in via the lkgpEnabled boolean flag in the routing context. When this flag is undefined or false, the strategy delegates immediately to the rules-based router even if lastKnownGoodProvider is populated.
What happens if the last known good provider is down?
If the provider identified by lastKnownGoodProvider has an OPEN circuit-breaker state or is absent from the current pool, the lkgp strategy automatically falls back to the standard rules strategy. This ensures requests do not fail when a previously good provider becomes unhealthy.
How does lkgp differ from the standard rules strategy?
The rules strategy evaluates all candidates across dimensions like latency, error rate, and cost to find the optimal provider. The lkgp strategy short-circuits this evaluation, returning the previous provider immediately with a fixed score of 1.0 if it is healthy, ensuring session stickiness at the potential cost of suboptimal latency or pricing.
Can I use lkgp with non-conversational workloads?
While technically possible, lkgp is designed for stateful, multi-turn interactions. For stateless API calls or batch processing, the standard rules strategy typically provides better cost and latency optimization since maintaining provider stickiness offers no benefit across disconnected requests.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →