autonomous-ai-agency / router
CLAUDE.md9 starsChanged 3 months agoMITView on GitHub
Model routing affects every request in the system. The invariants you must not break are CLAUDE.md rules 21–23. Read those first. This file covers how selection works and how to extend it. The central model-selection layer for all API surfaces. Selection priority, highest first: Local Ollama model names are passthrough: they bypass the alias table entirely and resolve to RoutingDecision(selection_source="passthrough"). The health check is cached with TTL ROUTER_HEALTH_CACHE_TTL (default 60s). The cache is deliberately invalidated before fallback retries — that…
In this repository109 other files it gives its agents.
- AGENTS.mdAGENTS.md
- docs/agents.mdAGENTS.md
- agent/CLAUDE.mdCLAUDE.md
- CLAUDE.mdCLAUDE.md
- .agents/skills/llms.txtllms.txt
- agent-harnessSkill
- auto-fixSkill
- brain-dumpSkill
- industrial-brutalist-uiSkill
- changelog-enforcerSkill
- checkpoint-strategySkill
- context-primeSkill
- cooldown-resumeSkill
- council-reviewSkill
- data-quality-auditSkill
- debug-tracerSkill
- dependency-auditSkill
- deslopSkill
- docs-syncSkill
- duplicate-threadSkill
- email-triageSkill
- fabric-patternsSkill
- feature-flagSkill
- git-hygieneSkill
- graphifySkill
- implementation-plannerSkill
- insightsSkill
- issue-resolverSkill
- learn-ruleSkill
- local-ai-querySkill
- lr-schedule-advisorSkill
- minimalist-uiSkill
- modularity-reviewSkill
- full-output-enforcementSkill
- parallel-agentsSkill
- parallel-worktreesSkill
- prompt-librarySkill
- prompt-transparencySkill
- pro-workflowSkill
- redesign-existing-projectsSkill
- release-readinessSkill
- replay-learningsSkill
- repo-memory-updaterSkill
- repowise-intelligenceSkill
- researchSkill
- resource-panelSkill
- risky-module-reviewSkill
- sandboxed-execSkill
- scope-guardSkill
- self-improveSkill
- session-handoffSkill
- skill-composerSkill
- smart-commitSkill
- high-end-visual-designSkill
- stitch-design-tasteSkill
- system-prompt-auditSkill
- task-alive-updatesSkill
- task-scoperSkill
- design-taste-frontendSkill
- test-first-executorSkill
- The first 60 shown.
The file
We split this CLAUDE.md into the rules it gives an agent
8 rules. About 0 are common, 1 is distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 38
Add an entry to MODEL_REGISTRY in registry.py.
- Very specific: line 41
Add a routing test in tests/test_model_router.py (rule 23).
- Very specific: line 42
Update docs/architecture/overview.md if the capability profile changes.
- Very specific: line 46
Add the category string to classifier.py.
- Distinctive: line 47
Add its matching logic — keyword, heuristic, or metadata.
- Very specific: line 49
Add tests under "Task classification" in tests/test_model_router.py.
- Very specific: line 69
All router tests are in tests/test_model_router.py:
- Very specific: line 75
Always cover after a change: manual override still wins.
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md — router/
Model routing affects every request in the system.
The invariants you must not break are
CLAUDE.mdrules 21–23. Read those first. This file covers how selection works and how to extend it.
What this package does
The central model-selection layer for all API surfaces.
| File | Role |
model_router.py | ModelRouter.route() → RoutingDecision |
classifier.py | classify_task() → task category string |
registry.py | Model capability registry, best_model_for() |
health.py | Ollama /api/tags health check with TTL cache |
Selection priority, highest first:
- Manual override —
X-Model-Overrideheader oroverride_modelkwarg MODEL_MAPenv var, or the built-in Anthropic alias table- Heuristic — task classification into a capability-registry lookup
- Default —
AGENT_EXECUTOR_MODEL
Local Ollama model names are passthrough: they bypass the alias table entirely and
resolve to RoutingDecision(selection_source="passthrough").
The health check is cached with TTL ROUTER_HEALTH_CACHE_TTL (default 60s). The cache is
deliberately invalidated before fallback retries — that is not a bug.
Adding a model
- Add an entry to
MODEL_REGISTRYinregistry.py. - Set
strengthsaccurately — it drives heuristic selection. - Set
cost_tier(1 = cheapest) — it drives fast-response routing. - Add a routing test in
tests/test_model_router.py(rule 23). - Update
docs/architecture/overview.mdif the capability profile changes.
Adding a task category
- Add the category string to
classifier.py. - Add its matching logic — keyword, heuristic, or metadata.
- List the category in
strengthson theMODEL_REGISTRYentries that serve it. - Add tests under "Task classification" in
tests/test_model_router.py.
Environment variables
| Variable | Effect |
MODEL_MAP | Colon-separated alias overrides, e.g. claude-sonnet-4-6:deepseek-r1:32b |
ROUTER_EXTRA_MODELS | Add models at runtime: name:type:strength1+strength2 |
ROUTER_HEALTH_CHECK_ENABLED | false disables health filtering (useful in tests) |
ROUTER_HEALTH_CACHE_TTL | Health cache TTL in seconds (default 60) |
DENIED_MODEL_IDS | Operator deny-list (packages/ai/model_policy.py): route() moves a denied resolved_model to the next allowed fallback and drops denied ids from fallback_chain; if every option is denied the decision is left unchanged so resolved_model stays non-empty (rule 21) and dispatch refuses it |
ROUTER_FAST_RESPONSE_CHARS | Char threshold for fast_response classification (default 200) |
AGENT_EXECUTOR_MODEL | Final fallback when nothing else resolves |
Testing
All router tests are in tests/test_model_router.py:
pytest -x tests/test_model_router.pyAlways cover after a change: manual override still wins; the built-in alias table maps
correctly; heuristic fallback fires when no alias matches; health-check bypass works with
ROUTER_HEALTH_CHECK_ENABLED=false; reset_router() isolates the singleton between
tests.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

