Coverage for astrocyte/pipeline/preset_routing.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.15.0, created at 2026-07-04 05:24 +0000

1"""Budget-aware preset routing for benchmark and gateway policy layers.""" 

2 

3from __future__ import annotations 

4 

5from dataclasses import dataclass 

6 

7from astrocyte.pipeline.query_intent import QueryIntent, classify_query_intent 

8from astrocyte.pipeline.query_plan import build_query_plan 

9 

10 

11@dataclass(frozen=True) 

12class PresetRoute: 

13 preset: str 

14 budget: str 

15 reason: str 

16 

17 

18def route_recall_preset(query: str) -> PresetRoute: 

19 """Choose the lowest-cost preset likely to answer *query* well. 

20 

21 This is deterministic and intentionally conservative: simple factual 

22 lookups stay on ``fast-recall``; temporal, relational, comparative, and 

23 multi-hop questions use the fuller Hindsight-parity budget; exploratory 

24 questions use ``quality-max`` because synthesis quality matters most. 

25 """ 

26 plan = build_query_plan(query) 

27 intent = classify_query_intent(query).intent 

28 

29 if intent == QueryIntent.EXPLORATORY: 

30 return PresetRoute("quality-max", "high", "exploratory synthesis") 

31 

32 if plan.needs_multi_hop_synthesis or intent in { 

33 QueryIntent.TEMPORAL, 

34 QueryIntent.RELATIONAL, 

35 QueryIntent.COMPARATIVE, 

36 }: 

37 return PresetRoute("hindsight-parity", "mid", "multi-hop or temporal recall") 

38 

39 return PresetRoute("fast-recall", "low", "simple lookup")