From c4a20f677617b09e049dfe9d3fe0b25164bd08d3 Mon Sep 17 00:00:00 2001 From: Alexander Whitestone Date: Mon, 23 Mar 2026 15:41:14 -0400 Subject: [PATCH] feat: implement three-tier metabolic LLM router (Refs #966) - Add MetabolicRouter routing tasks to T1/T2/T3 model tiers based on complexity classification - classify_complexity() assigns cheapest-sufficient tier using keyword matching and game state signals (stuck, active quests, dialogue) - build_prompt() assembles OpenAI-compatible message lists from game/UI state - T3 (Qwen3-32B) pauses the game world before inference and unpauses in a finally block (graceful if no world adapter) - Fix: narrow "what should" phrase to "what should i do" to avoid misclassifying dialogue tasks as T3 - Add pytestmark=pytest.mark.unit so tests run in tox -e unit - Export all public symbols via infrastructure/router/__init__.py Co-Authored-By: Claude Sonnet 4.6 --- src/infrastructure/router/metabolic.py | 2 +- tests/infrastructure/test_metabolic_router.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/infrastructure/router/metabolic.py b/src/infrastructure/router/metabolic.py index 253438ff..7e3fceb3 100644 --- a/src/infrastructure/router/metabolic.py +++ b/src/infrastructure/router/metabolic.py @@ -62,7 +62,7 @@ _T3_KEYWORDS = frozenset( "recover", "multi-step", "long-term", "negotiate", "persuade", "faction", "reputation", "best", "optimal", "recommend", "analyze", "analyse", "evaluate", "decide", "complex", "how do i", - "what should", "help me figure", "what is the best", + "what should i do", "help me figure", "what is the best", } ) diff --git a/tests/infrastructure/test_metabolic_router.py b/tests/infrastructure/test_metabolic_router.py index 357220d6..21ccf689 100644 --- a/tests/infrastructure/test_metabolic_router.py +++ b/tests/infrastructure/test_metabolic_router.py @@ -5,6 +5,8 @@ from unittest.mock import AsyncMock, MagicMock, patch import pytest +pytestmark = pytest.mark.unit + from infrastructure.router.metabolic import ( DEFAULT_TIER_MODELS, MetabolicRouter,