learned_router
diapason.learning.routing.learned_router
¶
Learned router policy — trace-driven query_class -> model mapping.
Merges the runtime select_model() logic from TraceDrivenPolicy
with the batch update() logic from SFTRouterPolicy into a single
class registered as "learned" in RouterPolicyRegistry.
LearnedRouterPolicy
¶
Bases: RouterPolicy
Trace-driven router that learns query_class -> model mappings.
Implements RouterPolicy.select_model() for runtime routing AND
provides update_from_traces() / observe() for learning from traces,
plus update() for batch learning from a trace store.
policy_map
property
¶
Current learned routing decisions (read-only copy).
observe(query, model, outcome, feedback)
¶
Record a single observation for online (incremental) updates.
select_model(context)
¶
Select the best model based on learned policy or fallback.
update(trace_store, **kwargs)
¶
Batch update: analyze trace outcomes and update the policy map.
This is the batch learning interface (from the old SFTRouterPolicy).
update_from_traces(*, since=None, until=None)
¶
Recompute the policy map from trace history via TraceAnalyzer.
ensure_registered()
¶
Register LearnedRouterPolicy if not already present.