Intelligent LLM model router driven by real code metrics โ successor to preLLM
Project description
llx
Intelligent LLM model router driven by real code metrics.
AI Cost Tracking
- ๐ค LLM usage: $6.1500 (41 commits)
- ๐ค Human dev: ~$1192 (11.9h @ $100/h, 30min dedup)
Generated on 2026-03-29 using openrouter/qwen/qwen3-coder-next
Successor to preLLM โ rebuilt with modular architecture, no god modules, and metric-driven routing.
llx analyzes your codebase with code2llm, redup, and vallm, then selects the optimal LLM model based on actual project metrics โ file count, complexity, coupling, duplication โ not abstract scores.
Principle: larger + more coupled + more complex โ stronger (and more expensive) model.
Why llx? (Lessons from preLLM)
preLLM proved the concept but had architectural issues that llx resolves:
| Problem in preLLM | llx Solution |
|---|---|
cli.py: 999 lines, CC=30 (main), CC=27 (query) |
CLI split into app.py + formatters.py, max CC โค 8 |
core.py: 893 lines god module |
Config, analysis, routing in separate modules (โค250L each) |
trace.py: 509 lines, CC=28 (to_stdout) |
Output formatting as dedicated functions |
| Hardcoded model selection | Metric-driven thresholds from code2llm .toon data |
| No duplication/validation awareness | Integrates redup + vallm for richer metrics |
Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ IDE / Agent Layer โ
โ Roo Code โ Cline โ Continue.dev โ Aider โ Claude Code โ
โ (point at localhost:4000 as OpenAI-compatible API) โ
โโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ LiteLLM Proxy (localhost:4000) โ
โ โโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Router โ โ Semantic โ โ Cost Tracking โ โ
โ โ (metrics)โ โ Cache (Redis)โ โ + Budget Limits โ โ
โ โโโโโโฌโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ Model Tiers โ
โ โโโ premium: Claude Opus 4 โ
โ โโโ balanced: Claude Sonnet 4 / GPT-5 โ
โ โโโ cheap: Claude Haiku 4.5 โ
โ โโโ free: Gemini 2.5 Pro โ
โ โโโ openrouter: 300+ models (fallback) โ
โ โโโ local: Ollama (Qwen2.5-Coder) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Code Analysis Pipeline โ
โ code2llm โ redup โ vallm โ llx โ
โ (metrics โ duplication โ validation โ model selection) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
MCP Server Integration (NEW)
llx now provides a complete MCP (Model Context Protocol) server that exposes all wronai tools as MCP endpoints:
By default, the MCP server runs over stdio for Claude Desktop. If you need to connect from a web client or another process, start the SSE server explicitly and use the /sse and /messages/ endpoints.
# Start MCP server for Claude Desktop (stdio)
llx mcp start
# Start MCP server over SSE for web/remote clients
llx mcp start --mode sse --port 8000
# SSE endpoint: http://localhost:8000/sse
# Message endpoint: http://localhost:8000/messages/
# Generate Claude Desktop config
llx mcp config
# List available MCP tools
llx mcp tools
SSE / HTTP clients
For clients like pyqual that expect an HTTP SSE endpoint, start llx in SSE mode:
llx mcp start --mode sse --port 8000
# or
python -m llx.mcp --sse --port 8000
Then point the client at:
http://localhost:8000/sse
MCP Tools Available
| Tool | Description | Wraps |
|---|---|---|
llx_analyze |
Analyze project and recommend model | llx analyze |
llx_select |
Quick model selection | llx select |
llx_chat |
Analyze + select model + send prompt | llx chat |
code2llm_analyze |
Run code2llm static analysis | code2llm CLI |
redup_scan |
Run duplication detection | redup CLI |
vallm_validate |
Validate code quality | vallm API/CLI |
llx_proxy_status |
Check LiteLLM proxy status | llx proxy status |
aider |
AI pair programming tool | aider CLI |
Claude Desktop Setup
{
"mcpServers": {
"llx": {
"command": "python3",
"args": ["-m", "llx.mcp.server"]
}
}
}
Installation
pip install llx
# With integrations
pip install llx[all] # Everything + MCP
pip install llx[mcp] # MCP server only
pip install llx[litellm] # LiteLLM proxy
pip install llx[code2llm] # Code analysis
pip install llx[redup] # Duplication detection
pip install llx[vallm] # Code validation
Quick Start
# Analyze project and get model recommendation
llx analyze ./my-project
# Quick model selection
llx select .
# With task hint
llx select . --task refactor
# Point to pre-existing .toon files
llx analyze . --toon-dir ./analysis/
# JSON output for CI/CD
llx analyze . --json
# Chat with auto-selected model
llx chat . --prompt "Refactor the god modules"
# Force local model
llx select . --local
Model Selection Logic
| Metric | Premium (โฅ) | Balanced (โฅ) | Cheap (โฅ) | Free |
|---|---|---|---|---|
| Files | 50 | 10 | 3 | <3 |
| Lines | 20,000 | 5,000 | 500 | <500 |
| Avg CC | 6.0 | 4.0 | 2.0 | <2.0 |
| Max fan-out | 30 | 10 | โ | โ |
| Max CC | 25 | 15 | โ | โ |
| Dup groups | 15 | 5 | โ | โ |
| Dep cycles | any | โ | โ | โ |
Real-World Selection Examples
| Project | Files | Lines | CCฬ | Max CC | Fan-out | Tier |
|---|---|---|---|---|---|---|
| Single script | 1 | 80 | 2.0 | 4 | 0 | free |
| Small CLI | 5 | 600 | 3.0 | 8 | 3 | cheap |
| preLLM | 31 | 8,900 | 5.0 | 28 | 30 | premium |
| vallm | 56 | 8,604 | 3.5 | 42 | โ | balanced |
| code2llm | 113 | 21,128 | 4.6 | 65 | 45 | premium |
| Monorepo | 500+ | 100K+ | 5.0+ | 30+ | 50+ | premium |
LiteLLM Proxy
llx proxy config # Generate litellm_config.yaml
llx proxy start # Start proxy on :4000
llx proxy status # Check if running
Configure IDE tools to point at http://localhost:4000:
| Tool | Config |
|---|---|
| Roo Code / Cline | "apiBase": "http://localhost:4000/v1" |
| Continue.dev | "apiBase": "http://localhost:4000/v1" |
| Aider | OPENAI_API_BASE=http://localhost:4000 |
| Claude Code | ANTHROPIC_BASE_URL=http://localhost:4000 |
| Cursor / Windsurf | OpenAI-compatible endpoint |
Configuration
llx init # Creates llx.toml with defaults
Environment variables: LLX_LITELLM_URL, LLX_DEFAULT_TIER, LLX_PROXY_PORT, LLX_VERBOSE.
Python API
from llx import analyze_project, select_model, LlxConfig
metrics = analyze_project("./my-project")
result = select_model(metrics)
print(result.model_id) # "claude-opus-4-20250514"
print(result.explain()) # Human-readable reasoning
Integration with wronai Toolchain
| Tool | Role | llx Uses |
|---|---|---|
| code2llm | Static analysis | CC, fan-out, cycles, hotspots |
| redup | Duplication detection | Groups, recoverable lines |
| vallm | Code validation | Pass rate, issue count |
| llx | Model routing + MCP server | Consumes all above |
Package Structure
llx/
โโโ __init__.py # Public API (30L)
โโโ config.py # Config loader (160L)
โโโ mcp/ # MCP server (NEW)
โ โโโ __init__.py # Module init
โ โโโ server.py # MCP server dispatcher (40L)
โ โโโ tools.py # 7 MCP tool definitions (250L)
โ โโโ __main__.py # python -m llx.mcp
โโโ analysis/
โ โโโ collector.py # Metrics from .toon, filesystem (280L)
โ โโโ runner.py # Tool invocation (80L)
โโโ routing/
โ โโโ selector.py # Metric โ tier mapping (200L)
โ โโโ client.py # LiteLLM client wrapper (150L)
โโโ integrations/
โ โโโ context_builder.py # .toon โ LLM context (130L)
โ โโโ proxy.py # LiteLLM proxy management (100L)
โโโ cli/
โโโ app.py # Commands (300L, max CC โค 8)
โโโ formatters.py # Output formatting (340L, max CC โค 10)
Total: ~1,600 lines across 12 modules. No file exceeds 350L. Max CC โค 10.
Compare: preLLM had 8,900 lines with 3 god modules (cli.py: 999L, core.py: 893L, trace.py: 509L).
Architecture Improvements (v0.1.7)
- โ Refactored 6 high-CC functions to meet targets (CCฬ โค 2.5, max CC โค 16)
- โ Added complete MCP server with 7 tools for Claude Desktop integration
- โ Fixed import resolution issues reported by vallm
- โ Enhanced test coverage for MCP functionality
- โ Modular design with single-responsibility functions
License
Licensed under Apache-2.0.
Author
Tom Sapletta
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llx-0.1.51.tar.gz.
File metadata
- Download URL: llx-0.1.51.tar.gz
- Upload date:
- Size: 270.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b9038353721164816ddba9ee83c589f7ed9f035fcff2a556edbdfc84db4c782
|
|
| MD5 |
0cc08f9383c08752b0253bb717db59dd
|
|
| BLAKE2b-256 |
263ddfc985352b88337b08d7349ff07db5e514c8d82b130eb0980e35479dd0a3
|
File details
Details for the file llx-0.1.51-py3-none-any.whl.
File metadata
- Download URL: llx-0.1.51-py3-none-any.whl
- Upload date:
- Size: 319.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96b800d8602f98c87990da8df1512935552f163eb31727656d2c9756f952b420
|
|
| MD5 |
9e2aa146a37ac1933dab3187e9baaecf
|
|
| BLAKE2b-256 |
da23ad52677b3f8085cf5d454af11a1a029ab698b0f8526d17d064adaf8864f0
|