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

Function _reasoning_preference

uncommon_route/proxy.py:1564–1610  ·  view source on GitHub ↗

Detect explicit reasoning/thinking controls from OpenAI and Anthropic shaped requests.

(body: dict[str, Any])

Source from the content-addressed store, hash-verified

1562
1563
1564def _reasoning_preference(body: dict[str, Any]) -> tuple[bool, Tier | None]:
1565 """Detect explicit reasoning/thinking controls from OpenAI and Anthropic shaped requests."""
1566 prefers_reasoning = False
1567 tier_floor: Tier | None = None
1568
1569 def mark(value: Any, *, floor_medium: bool = False) -> None:
1570 nonlocal prefers_reasoning, tier_floor
1571 normalized = str(value or "").strip().lower()
1572 if normalized in _REASONING_DISABLED_VALUES:
1573 return
1574 prefers_reasoning = True
1575 if floor_medium or normalized in _REASONING_FLOOR_VALUES:
1576 tier_floor = _max_tier(tier_floor, Tier.MEDIUM)
1577
1578 if "reasoning_effort" in body:
1579 mark(body.get("reasoning_effort"))
1580
1581 reasoning = body.get("reasoning")
1582 if isinstance(reasoning, dict):
1583 effort = reasoning.get("effort")
1584 if effort is not None:
1585 mark(effort)
1586 elif reasoning:
1587 mark("medium", floor_medium=True)
1588 elif reasoning is not None:
1589 mark(reasoning)
1590
1591 thinking = body.get("thinking")
1592 if isinstance(thinking, dict):
1593 thinking_type = str(thinking.get("type") or "").strip().lower()
1594 budget = thinking.get("budget_tokens")
1595 budget_enabled = False
1596 try:
1597 budget_enabled = budget is not None and int(budget) > 0
1598 except (TypeError, ValueError):
1599 budget_enabled = bool(budget)
1600 if thinking_type not in _REASONING_DISABLED_VALUES and (thinking_type or budget_enabled):
1601 mark("medium", floor_medium=True)
1602 elif thinking is not None:
1603 mark(thinking, floor_medium=True)
1604
1605 if _contains_anthropic_thinking_blocks(body):
1606 # Prior signed thinking blocks are a transport/model-continuity
1607 # constraint, not evidence that the latest user ask is complex.
1608 pass
1609
1610 return prefers_reasoning, tier_floor
1611
1612
1613def _is_suggestion_mode_prompt(prompt: str) -> bool:

Callers 1

Calls 3

markFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected