MCPcopy Create free account
hub / github.com/CommonstackAI/UncommonRoute / on_route_complete

Function on_route_complete

uncommon_route/v2_lifecycle.py:157–261  ·  view source on GitHub ↗

Record a completed routing decision. Call after each route().

(
    *,
    request_id: str,
    tier_id: int,
    model: str,
    method: str,
    confidence: float,
    signal_a_tier: int | None,
    signal_a_conf: float,
    signal_b_tier: int | None,
    signal_b_conf: float,
    signal_c_tier: int | None,
    signal_c_conf: float,
    query_embedding: Any = None,
)

Source from the content-addressed store, hash-verified

155
156
157def on_route_complete(
158 *,
159 request_id: str,
160 tier_id: int,
161 model: str,
162 method: str,
163 confidence: float,
164 signal_a_tier: int | None,
165 signal_a_conf: float,
166 signal_b_tier: int | None,
167 signal_b_conf: float,
168 signal_c_tier: int | None,
169 signal_c_conf: float,
170 query_embedding: Any = None,
171) -> None:
172 """Record a completed routing decision. Call after each route()."""
173 if not _initialized:
174 return
175
176 # 1. Record v2 metrics
177 if _metrics:
178 signals_agreed = (signal_a_tier == signal_c_tier) if signal_c_tier is not None else True
179 _metrics.record_routing(
180 tier=tier_id, model=model, method=method,
181 confidence=confidence, signals_agreed=signals_agreed,
182 )
183
184 # 2. Shadow tracking for Signal B (gold_tier filled later via on_feedback)
185 if _shadow:
186 _shadow.record(
187 signal_a_pred=signal_a_tier, signal_a_conf=signal_a_conf,
188 signal_b_pred=signal_b_tier, signal_b_conf=signal_b_conf,
189 signal_c_pred=signal_c_tier, signal_c_conf=signal_c_conf,
190 ensemble_2sig_tier=tier_id,
191 gold_tier=None, # filled retroactively by on_feedback
192 )
193
194 # 3. Index growth on high-confidence unanimous routing
195 if (
196 _index_manager
197 and query_embedding is not None
198 and confidence >= 0.7
199 and signal_a_tier is not None
200 and signal_a_tier == signal_c_tier
201 ):
202 try:
203 added = _index_manager.add(query_embedding, tier_id)
204 if added:
205 logger.debug("v2 index growth: added entry for tier %d (size=%d)", tier_id, _index_manager.size)
206 except Exception as e:
207 logger.debug("v2 index growth failed: %s", e)
208
209 # 4. Cache signal predictions for feedback (request_id linked later by proxy)
210 _recent_predictions.append(("", _RecentPrediction(
211 tier_id=tier_id,
212 signal_a_tier=signal_a_tier,
213 signal_a_abstained=signal_a_tier is None,
214 signal_c_tier=signal_c_tier,

Callers 1

routeFunction · 0.90

Calls 7

to_jsonMethod · 0.95
RoutingLogEntryClass · 0.90
_RecentPredictionClass · 0.85
record_routingMethod · 0.80
recordMethod · 0.45
addMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected