@moterodiaz/agent-router
v0.1.0
Published
Lightweight task routing for Claude, Codex, and Devin
Maintainers
Readme
agent-router
agent-route classifies a task description into a routing category using Span-01 Lite via OpenRouter. The dispatch wrappers (claude-dispatch, codex-dispatch) launch the right agent with matching prompt framing; Devin picks up the same routing guidance from AGENTS.md (see Devin). Without an API key, it falls back to the first rubric entry with zero cost and exits 0.
task description
|
agent-route
|
category
/ \
claude- codex- AGENTS.md guidance
dispatch dispatch (Devin reads this)Prerequisites
- Python 3.10+ (stdlib only — no pip dependencies)
- Node 18+ (for
agent-route-setup) claudeandcodexCLIs are optional; install only the ones you use- Devin is optional and needs no CLI here; it reads
AGENTS.md(see Devin)
Install
npm i -g @moterodiaz/agent-router
agent-route-setup # global: writes to ~ paths, for any Claude/Codex session
agent-route-setup --project # per-repo: writes to ./ paths, for this repo onlyWhat each mode writes
| Path | --global (default) | --project |
|------|----------------------|-------------|
| Skill file | ~/.claude/skills/agent-route/SKILL.md | ./.claude/skills/agent-route/SKILL.md |
| Registry | ~/.config/agent-router/registry.json | ./.agent-router/registry.json |
| Routing block | ~/.codex/AGENTS.md (only if ~/.codex exists) | ./AGENTS.md |
| Routing block | ~/CLAUDE.md (if it exists) | ./CLAUDE.md (if it exists) |
Registry is seeded from the bundled default only if the target file does not exist. Running setup again is safe — it replaces the marker block, not duplicates it.
Flags
| Flag | Effect |
|------|--------|
| (none) | Global install (same as --global) |
| --project | Per-repo install into ./ |
| --dry-run | Print what would happen, write nothing |
| --uninstall | Remove skill dir and routing block |
Uninstall
agent-route-setup --uninstall # removes global paths
agent-route-setup --project --uninstall # removes project pathsUninstall removes the installed SKILL.md (the skill directory is removed only if nothing else is inside — files you added are preserved) and the routing block from AGENTS.md and CLAUDE.md. Files are removed only when proven both setup-created and untouched: setup writes .setup-seeded markers recording the installed content's hash (and inode metadata for the registry), so a pre-existing file, an edited file, or a file you recreated yourself is always kept — and a message says so.
From source
bash scripts/install.shInstalls agent-route, claude-dispatch, codex-dispatch to ~/.local/bin and seeds ~/.config/agent-router/registry.json. The agent-route wrapper uses PYTHONPATH to point at the checkout, so keep the clone in place. Re-run after editing dispatch scripts.
Usage
agent-route claude_dev "task"
agent-route claude_dev "task" --raw
agent-route codex_review "diff summary" --config /path/to/registry.json
claude-dispatch "task"
codex-dispatch "diff summary"agent-route takes <domain> <context> with optional --raw and --config PATH. claude-dispatch classifies under claude_dev and calls claude with category-specific framing. codex-dispatch classifies under codex_review and calls codex review --uncommitted with matching focus. An explicit --config path must exist, otherwise it exits 2. Devin has no dispatcher; it reads the routing instructions in AGENTS.md and takes the Devin pane when selected by your workflow.
Output
{"category": "routine_implementation", "target": {"model": "deepseek/deepseek-coder", "temperature": 0.0}, "latency_ms": 18}With --raw, prints only the category key. An unknown domain exits 2.
Devin
Devin is a routing target alongside Claude and Codex, but has no dispatcher script. Integration is guidance-only:
- Run
agent-route-setup --projectin the repo. It writes the routing block into./AGENTS.md, which Devin reads when it works in that repo. (The global install writes~/.codex/AGENTS.md, only if~/.codexexists; that file is for Codex, not Devin.) - The block tells agents to run
agent-routeto pick a category, useclaude-dispatch/codex-dispatchwhere they apply, and let Devin take the Devin pane when your workflow selects it. - Your workflow decides when to hand a task to Devin — the router never launches it.
Devin can also run agent-route <domain> "task" itself to classify work. agent-route-setup --project --uninstall removes the block.
Registry
Shape: {domain: {rubrics: {key: description}, targets: {key: {model, temperature}}}}. The first rubric key is the fallback for that domain. targets is informational metadata; dispatchers act on the category key.
Lookup order (first file found wins):
./.agent-router/registry.json(project override — opt-in only, requiresAGENT_ROUTER_PROJECT_REGISTRY=1)~/.config/agent-router/registry.json(user config)- Bundled
registry.default.json(always present)
An explicit --config PATH skips the lookup and uses that path directly (~ is expanded).
Project registry opt-in: set AGENT_ROUTER_PROJECT_REGISTRY=1 to enable the project override. When enabled, agent-route walks from the current directory up the tree, stopping at the first ancestor that contains a .git directory or at $HOME (whichever comes first), and uses the nearest ancestor containing .agent-router/registry.json. A registry inside $HOME itself is checked only when the cwd is $HOME. This lookup is opt-in because a project-controlled registry can reorder rubrics and redirect claude-dispatch to any model — only enable it in repos you trust. The per-repo canonical way to enable it is via direnv: add export AGENT_ROUTER_PROJECT_REGISTRY=1 to the repo's .envrc and run direnv allow. Devin and other agents that run inside the repo are unaffected unless they inherit this env var.
Discovery hint: when agent-route is invoked without --config and finds a project registry but the env var is not set, it prints to stderr:
agent-route: found <path>; set AGENT_ROUTER_PROJECT_REGISTRY=1 to use itagent-route-setup --project prints the same hint after seeding or keeping the registry.
Environment
Set OPENROUTER_API_KEY to enable classification through OpenRouter's Decisions endpoint (https://openrouter.ai/api/alpha/decisions) using respan/span-01-lite:free. One yes/no (noul) question is asked per rubric key; the key with the highest probability wins.
Fallback
Without OPENROUTER_API_KEY, or on any network failure (4 s timeout), agent-route prints a warning to stderr, outputs the domain's first rubric key, and exits 0. Empty context uses the fallback without a network request. A malformed registry or a domain entry with no rubrics exits 2.
Tests
python3 -m unittest discover testsThe test suite runs without network access.
