OpenCode subagents now have a router that learns from their failures. A plugin published on November 30, @jacobwolf/opencode-subagent-router, sits between the parent agent and its child sessions, pushes cheap lookups down to cheaper models, and remembers when a small model choked on a class of task so it steps up a rung the next time something similar arrives.
The problem it targets is structural. By default, OpenCode subagents inherit the calling agent's model unless a model is pinned, so a grep search or a documentation lookup can run on the same frontier reasoning model doing the architecture work. Pinning one cheap model to every subagent does not fix it either, because agents such as @general handle both trivial lookups and heavy tasks.
How the router picks a cheaper rung
In each root session the plugin builds a capability-labeled downgrade ladder from the models enabled in the user's OpenCode catalog and writes it into the session through OpenCode V2's keyed session.instructions API. The parent model can then choose a cheaper rung itself, at zero added latency, by reading instructions it already has.
If the parent omits a model, a stateless fallback evaluator picks one on the cheapest rung using OpenCode's experimental.generate.text API.
Candidates are filtered hard. A model must match or beat the parent's price at every compared context tier, with at least one tier strictly cheaper. It has to preserve tool calling, modalities and output token limit, and it must carry a context window of at least the smaller of the parent's window and 200,000 tokens. Fast-tier variants are excluded, same-price aliases collapse into one entry, and anything the plugin cannot compare on price is skipped rather than guessed.
Search, read-only research, mechanical edits and bounded implementation are allowed to downgrade. Architecture, diagnosis, low-confidence results and anything needing deep reasoning stay on the parent model.
The guardrails matter more than the savings
Every routing decision and its outcome is recorded in a local SQLite database, one of ok, thrash, error, interrupted, retried, cancelled or abandoned. Interrupts are classified rather than lumped together: an inactivity stall counts as a failure, a shutdown or superseded session does not, and a user interrupt only counts if the parent re-issues a similar prompt within two minutes.
When vector escalation is switched on, prompts are embedded locally in pure TypeScript with Model2Vec. Escalation fires only when at least two settled runs exist for the same agent and model, those runs hit a cosine similarity of 0.85 or higher to the current prompt, and at least half of them ended in a confirmed failure. Vectors are never used to downgrade, so a familiar topic cannot push hard work onto a small model.
The default embedding model, potion-base-2M, is 64-dimensional, needs roughly 12 to 15 MB of heap and downloads about 7.9 MB of weights. An ngram backend downloads nothing at all for air-gapped CI.
Downloads are pinned to a specific Hugging Face commit and checked by SHA-256 on every load, restricted to HTTPS with a redirect allowlist and manual redirect handling, written atomically with 0600 permissions.
The router also refuses to upgrade above the parent model, refuses to override an explicit model choice, does not route nested subagents, and fails open to the parent on provider timeouts.
Installation is one command against OpenCode V2 with Node 20 or newer:
npx @jacobwolf/opencode-subagent-router@latest install
The installer detects the installed version, preserves comments and unrelated settings in opencode.jsonc, and takes a backup before editing. There is no external classifier service and no extra API key, which is the quiet selling point: routing intelligence that lives in a local database instead of someone else's endpoint.
What the release does not ship is a benchmark. There are no published cost or latency numbers here, only a routing policy that is cheap enough to run on a laptop and conservative enough to fail closed in the parent's favor.
Comments