feat: route Discord turns between fast and deep-think via router_core #1

Open
xenarathon wants to merge 0 commits from feat/router-escalation into main
Owner

Summary

Routes each Discord turn between the fast model and the deep-think backend using the shared
router_core decision core (installed from the boxxo-router repo) — the same routing logic as the
Open WebUI Pipe, so both front doors behave consistently.

  • brain.py imports router_core and escalates hard turns (multi-tool, sequential-dependent,
    unit conversion, precise multi-item relay) to the deep-think backend, with a user-visible
    "🧠 Switching to deep-think mode…" notice.
  • Adds an OpenAI-compatible deep-think tool loop alongside the existing Ollama fast loop (the two
    backends use different wire formats: dict vs JSON-string tool args, tool_call_id).
  • ROUTER_ENABLED toggle; repo-local system-prompt fallback so the module imports under test.
  • requirements.txt pulls router_core via git ref; Dockerfile installs git and injects the
    Forgejo token via a BuildKit secret (never baked into a layer); .env.example documents the vars.

Notable Decisions

  • Up-front heuristic routing only for now (sync evaluate_heuristics), keeping brain.py
    synchronous. The post-fast failure-detector escalation (which the Pipe has) is a follow-up.
  • Two separate tool loops rather than one abstracted loop — the Ollama and OpenAI wire formats
    differ enough that separate, correct loops are clearer than a leaky abstraction.
  • Shared router_core rather than routing Discord through Open WebUI — brain.py stays
    self-contained (its own MCP loop), with one source of routing truth.

Test Plan

  • pytest -q — 8 tests green (4 new mocked-backend routing tests + existing identity-injection
    tests, which now import cleanly via the prompt-file fallback).
  • Routing decision, fast/deep backend selection, escalation notice, ROUTER_ENABLED toggle, and
    history hygiene are covered with mocked HTTP.
  • Not yet done: live run against real Ollama + deep-think backends, and the Docker build with a
    real Forgejo token (no docker available in the dev sandbox).
## Summary Routes each Discord turn between the fast model and the deep-think backend using the shared `router_core` decision core (installed from the boxxo-router repo) — the same routing logic as the Open WebUI Pipe, so both front doors behave consistently. - `brain.py` imports `router_core` and escalates hard turns (multi-tool, sequential-dependent, unit conversion, precise multi-item relay) to the deep-think backend, with a user-visible "🧠 Switching to deep-think mode…" notice. - Adds an OpenAI-compatible deep-think tool loop alongside the existing Ollama fast loop (the two backends use different wire formats: dict vs JSON-string tool args, tool_call_id). - `ROUTER_ENABLED` toggle; repo-local system-prompt fallback so the module imports under test. - `requirements.txt` pulls `router_core` via git ref; `Dockerfile` installs git and injects the Forgejo token via a BuildKit secret (never baked into a layer); `.env.example` documents the vars. ## Notable Decisions - **Up-front heuristic routing only** for now (sync `evaluate_heuristics`), keeping `brain.py` synchronous. The post-fast failure-detector escalation (which the Pipe has) is a follow-up. - **Two separate tool loops** rather than one abstracted loop — the Ollama and OpenAI wire formats differ enough that separate, correct loops are clearer than a leaky abstraction. - **Shared `router_core`** rather than routing Discord through Open WebUI — brain.py stays self-contained (its own MCP loop), with one source of routing truth. ## Test Plan - `pytest -q` — 8 tests green (4 new mocked-backend routing tests + existing identity-injection tests, which now import cleanly via the prompt-file fallback). - Routing decision, fast/deep backend selection, escalation notice, ROUTER_ENABLED toggle, and history hygiene are covered with mocked HTTP. - **Not yet done:** live run against real Ollama + deep-think backends, and the Docker build with a real Forgejo token (no docker available in the dev sandbox).
brain.py now imports the shared router_core decision core and escalates hard
turns (multi-tool, sequential, unit-conversion, precise relay) to a deep-think
backend, with a user-visible notice. Adds an OpenAI-compatible tool loop for the
deep backend alongside the existing Ollama fast loop (distinct wire formats),
ROUTER_ENABLED toggle, and a repo-local system-prompt fallback so the module
imports under test. Mocked-backend routing tests included.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
requirements.txt pulls router_core from the Forgejo repo; Dockerfile installs git
and injects the token via a BuildKit secret (never baked into a layer); .env.example
documents ROUTER_ENABLED and the DEEPTHINK_* / heuristic knobs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This branch is already included in the target branch. There is nothing to merge.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feat/router-escalation:feat/router-escalation
git switch feat/router-escalation

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch main
git merge --no-ff feat/router-escalation
git switch feat/router-escalation
git rebase main
git switch main
git merge --ff-only feat/router-escalation
git switch feat/router-escalation
git rebase main
git switch main
git merge --no-ff feat/router-escalation
git switch main
git merge --squash feat/router-escalation
git switch main
git merge --ff-only feat/router-escalation
git switch main
git merge feat/router-escalation
git push origin main
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
xenarathon/boxxo-discord!1
No description provided.