litellm/litellm-proxy-extras/litellm_proxy_extras
Abhimanyu Kapur 1bba6094c5 feat(adaptive_router): add efficiency posterior and latency/throughput reward
Ports the efficiency-reward piece of the Elastic Unified Router (EURo) design
into the adaptive router's bandit, giving it a second Beta posterior keyed on
latency and completion-token throughput, independent of quality signals.

## What changed

- BanditCell now tracks (alpha_eff, beta_eff) alongside (alpha, beta), both fed
  independently. Efficiency defaults to Beta(1, 1) prior (uninformative).
- AdaptiveRouter.record_efficiency() updates the efficiency posterior from
  observed latency and token count; independent of record_turn()'s quality signals.
- Efficiency reward = gamma * exp(-latency/target) + (1-gamma) * min(tokens/sec/max, 1),
  clamped to [0, 1]. On failure (non-2xx), reward = 0.
- Selection now blends three terms: quality_weight * TS(quality) + efficiency_weight
  * TS(efficiency) + cost_weight * cost. Efficiency weight defaults to 0.0 (opt-in).
- DB: schema.prisma + migration add alpha_eff/beta_eff columns to
  LiteLLM_AdaptiveRouterState; read/write plumbing in update_queue and adaptive_router.
- Snapshot endpoint reports efficiency_mean alongside quality_mean.

## Tests

New tests for apply_efficiency_delta, efficiency_mean property, and flush behavior
with efficiency deltas. All existing bandit and router tests pass.

## Design decisions baked in (as per PHASE1_PLAN.md)

1. Efficiency weight defaults to 0.0 — no silent behavior change for existing
   deployments. Opt-in only.
2. target_latency is static (1.0s default, overridable in config). Auto-calibration
   deferred to Phase 2.
3. Failure handling reuses existing response_status detection — one source of truth.
4. Schema extended in place (not a sibling table) — (router, request_type, model)
   is already the right key for both quality and efficiency.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-08 14:09:19 -07:00
..
migrations feat(adaptive_router): add efficiency posterior and latency/throughput reward 2026-08-08 14:09:19 -07:00
__init__.py install prisma migration files - connects litellm proxy to litellm's prisma migration files (#9637) 2025-03-29 15:27:09 -07:00
_logging.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
prisma_toolchain.py fix(migrations): keep the toolchain heal from raising on an unreadable nodeenv cache (#35986) 2026-08-05 13:38:53 -07:00
py.typed fix(lint): bring basedpyright rule counts back under their budget limits 2026-08-05 10:23:02 -07:00
replica_identity.py fix(migrations): recover from an interrupted Prisma toolchain install (#35832) 2026-08-05 10:14:46 -07:00
schema.prisma feat(adaptive_router): add efficiency posterior and latency/throughput reward 2026-08-08 14:09:19 -07:00
utils.py fix(migrations): recover from an interrupted Prisma toolchain install (#35832) 2026-08-05 10:14:46 -07:00