|
| 1 | +# LLM Router |
| 2 | + |
| 3 | +Chat UI includes an intelligent routing system that automatically selects the best model for each request. When enabled, users see a virtual "Omni" model that routes to specialized models based on the conversation context. |
| 4 | + |
| 5 | +The router uses [katanemo/Arch-Router-1.5B](https://huggingface.co/katanemo/Arch-Router-1.5B) for route selection. |
| 6 | + |
| 7 | +## Configuration |
| 8 | + |
| 9 | +### Basic Setup |
| 10 | + |
| 11 | +```ini |
| 12 | +# Arch router endpoint (OpenAI-compatible) |
| 13 | +LLM_ROUTER_ARCH_BASE_URL=https://router.huggingface.co/v1 |
| 14 | +LLM_ROUTER_ARCH_MODEL=katanemo/Arch-Router-1.5B |
| 15 | + |
| 16 | +# Path to your routes policy JSON |
| 17 | +LLM_ROUTER_ROUTES_PATH=./config/routes.json |
| 18 | +``` |
| 19 | + |
| 20 | +### Routes Policy |
| 21 | + |
| 22 | +Create a JSON file defining your routes. Each route specifies: |
| 23 | + |
| 24 | +```json |
| 25 | +[ |
| 26 | + { |
| 27 | + "name": "coding", |
| 28 | + "description": "Programming, debugging, code review", |
| 29 | + "primary_model": "Qwen/Qwen3-Coder-480B-A35B-Instruct", |
| 30 | + "fallback_models": ["meta-llama/Llama-3.3-70B-Instruct"] |
| 31 | + }, |
| 32 | + { |
| 33 | + "name": "casual_conversation", |
| 34 | + "description": "General chat, questions, explanations", |
| 35 | + "primary_model": "meta-llama/Llama-3.3-70B-Instruct" |
| 36 | + } |
| 37 | +] |
| 38 | +``` |
| 39 | + |
| 40 | +### Fallback Behavior |
| 41 | + |
| 42 | +```ini |
| 43 | +# Route to use when Arch returns "other" |
| 44 | +LLM_ROUTER_OTHER_ROUTE=casual_conversation |
| 45 | + |
| 46 | +# Model to use if Arch selection fails entirely |
| 47 | +LLM_ROUTER_FALLBACK_MODEL=meta-llama/Llama-3.3-70B-Instruct |
| 48 | + |
| 49 | +# Selection timeout (milliseconds) |
| 50 | +LLM_ROUTER_ARCH_TIMEOUT_MS=10000 |
| 51 | +``` |
| 52 | + |
| 53 | +## Multimodal Routing |
| 54 | + |
| 55 | +When a user sends an image, the router can bypass Arch and route directly to a vision model: |
| 56 | + |
| 57 | +```ini |
| 58 | +LLM_ROUTER_ENABLE_MULTIMODAL=true |
| 59 | +LLM_ROUTER_MULTIMODAL_MODEL=meta-llama/Llama-3.2-90B-Vision-Instruct |
| 60 | +``` |
| 61 | + |
| 62 | +## Tools Routing |
| 63 | + |
| 64 | +When a user has MCP servers enabled, the router can automatically select a tools-capable model: |
| 65 | + |
| 66 | +```ini |
| 67 | +LLM_ROUTER_ENABLE_TOOLS=true |
| 68 | +LLM_ROUTER_TOOLS_MODEL=meta-llama/Llama-3.3-70B-Instruct |
| 69 | +``` |
| 70 | + |
| 71 | +## UI Customization |
| 72 | + |
| 73 | +Customize how the router appears in the model selector: |
| 74 | + |
| 75 | +```ini |
| 76 | +PUBLIC_LLM_ROUTER_ALIAS_ID=omni |
| 77 | +PUBLIC_LLM_ROUTER_DISPLAY_NAME=Omni |
| 78 | +PUBLIC_LLM_ROUTER_LOGO_URL=https://example.com/logo.png |
| 79 | +``` |
| 80 | + |
| 81 | +## How It Works |
| 82 | + |
| 83 | +When a user selects Omni: |
| 84 | + |
| 85 | +1. Chat UI sends the conversation context to the Arch router |
| 86 | +2. Arch analyzes the content and returns a route name |
| 87 | +3. Chat UI maps the route to the corresponding model |
| 88 | +4. The request streams from the selected model |
| 89 | +5. On errors, fallback models are tried in order |
| 90 | + |
| 91 | +The route selection is displayed in the UI so users can see which model was chosen. |
| 92 | + |
| 93 | +## Message Length Limits |
| 94 | + |
| 95 | +To optimize router performance, message content is trimmed before sending to Arch: |
| 96 | + |
| 97 | +```ini |
| 98 | +# Max characters for assistant messages (default: 500) |
| 99 | +LLM_ROUTER_MAX_ASSISTANT_LENGTH=500 |
| 100 | + |
| 101 | +# Max characters for previous user messages (default: 400) |
| 102 | +LLM_ROUTER_MAX_PREV_USER_LENGTH=400 |
| 103 | +``` |
| 104 | + |
| 105 | +The latest user message is never trimmed. |
0 commit comments