[claude] Implement three-tier metabolic LLM router (#966) #1160

Merged
Rockachopa merged 2 commits from claude/issue-966 into main 2026-03-23 19:45:57 +00:00
Collaborator

Fixes #966

What was done

  • Added MetabolicRouter in src/infrastructure/router/metabolic.py that routes LLM tasks to the cheapest-sufficient model tier (T1/T2/T3)
  • classify_complexity(task, state) uses keyword matching and game state signals (stuck, active_quests, dialogue_active, combat_active) to pick the right tier
  • build_prompt(state, ui_state, text, visual_context) assembles OpenAI-compatible message lists from game context
  • T3 (Qwen3-32B) pauses the game world before inference via world.act(CommandInput("pause")) and always unpauses in a finally block — graceful if no world adapter is wired
  • Default tier models: T1=qwen3:8b, T2=qwen3:14b, T3=qwen3:30b (overridable)
  • Module-level singleton via get_metabolic_router()
  • All symbols exported from infrastructure/router/__init__.py
  • 48 unit tests covering classification, prompt assembly, routing, world pause/unpause, and error degradation
  • Fixed over-broad "what should" T3 phrase (narrowed to "what should i do") to prevent T2 dialogue tasks from being misclassified
  • Added pytestmark = pytest.mark.unit so tests run in tox -e unit

Test results

68 passed in tox -e unit
Fixes #966 ## What was done - Added `MetabolicRouter` in `src/infrastructure/router/metabolic.py` that routes LLM tasks to the cheapest-sufficient model tier (T1/T2/T3) - `classify_complexity(task, state)` uses keyword matching and game state signals (stuck, active_quests, dialogue_active, combat_active) to pick the right tier - `build_prompt(state, ui_state, text, visual_context)` assembles OpenAI-compatible message lists from game context - T3 (Qwen3-32B) pauses the game world before inference via `world.act(CommandInput("pause"))` and always unpauses in a `finally` block — graceful if no world adapter is wired - Default tier models: T1=qwen3:8b, T2=qwen3:14b, T3=qwen3:30b (overridable) - Module-level singleton via `get_metabolic_router()` - All symbols exported from `infrastructure/router/__init__.py` - 48 unit tests covering classification, prompt assembly, routing, world pause/unpause, and error degradation - Fixed over-broad "what should" T3 phrase (narrowed to "what should i do") to prevent T2 dialogue tasks from being misclassified - Added `pytestmark = pytest.mark.unit` so tests run in `tox -e unit` ## Test results ``` 68 passed in tox -e unit ```
claude added 2 commits 2026-03-23 19:44:32 +00:00
Automated salvage commit — agent session ended (exit 124).
Work in progress, may need continuation.
feat: implement three-tier metabolic LLM router (Refs #966)
Some checks failed
Tests / lint (pull_request) Failing after 13s
Tests / test (pull_request) Has been skipped
c4a20f6776
- 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 <noreply@anthropic.com>
Rockachopa merged commit 08d337e03d into main 2026-03-23 19:45:57 +00:00
Rockachopa deleted branch claude/issue-966 2026-03-23 19:45:57 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#1160