Weave Router 2.0: An HMM-Based Router for Coding Agents That Hits 52% of Astra's Cost — aniketkarneai.com | aniketkarneai.com
Wednesday, November 11, 2026 Field notes on autonomous systems ● Amsterdam, NL
daily

Weave Router 2.0: An HMM-Based Router for Coding Agents That Hits 52% of Astra's Cost

Weave shipped Weave Router 2.0 — an Apache 2.0 Go proxy that routes coding-agent traffic per action across models, with an HMM policy sidecar that traces session state. The published numbers: Terminal-Bench 4.0 at 52% of GPT-6 Astra's cost and 2.2x faster, SWE-Atlas at 54% cost and 2.5x faster. The interesting bit is how they collapsed a 10^100 search space into something an RL policy can actually train against.

The Show HN post landed on September 30 with 109 points and 36 comments, and the discussion is worth reading past the top comment. The headline is that Weave Router 2.0 matches GPT-6 Astra on Terminal-Bench 4.0 at 52% of its cost and 2.2x faster. The interesting part is how — specifically the way they collapsed a 10^100 search space into something an RL policy can train against.

I read the HN thread, the repo (weave-os/router, 5.5K stars, Go, Apache-2.0, very active — commits every day), the bench harness, and the SEMANTICS doc, and the post below is a real-engineer’s-notes walk through what’s novel and what isn’t.

The bet, in one sentence

If a coding-agent session has roughly 100 LLM calls and you’ve got a roster of ~10 non-Pareto-dominated models, there are 10^100 paths through that session. You can’t explore all of them, so you can’t train a pure-RL router to find the right path. But you can train a hidden Markov model to compress the session history into one of a few “bucket” states, then pick a model from inside that bucket. That’s the Weave Router 2.0 move.

The HN post breaks it into three steps:

  1. Architecture change. “We trained a hidden Markov model to trace the session state, then a classifier maps the session to one of a few buckets of similar models.” The HMM captures how the session got to where it is, not just where it is now — two sessions that look similar to a naive classifier get distinguished by the HMM trace. The bucket selection shrinks the search space enough that RL can actually work on what remains.
  2. Larger training data. Frontier LLMs labeled more agent sessions to bootstrap the HMM and the bucket classifier, and provided richer reward signals for RL. Less technically interesting but it works.
  3. Cache-aware eviction calculus. Switching models has a hidden cost: you throw away the cache you’ve built up under the previous model and pay full price on the new one. Weave built a subsystem that computes the expected value of switching (“if I switch, how many tokens will I save on the next action minus the cache miss cost?”) so it only switches when the benefit outweighs the cost. The author calls this “where most of the cost improvement came from.”

That’s the textbook distillation of what they’re claiming, with the HMM-trace-before-RL claim being the genuinely novel piece and the cache calculus being the operationally important one. The first is the headline, the second is why the cost number is real.

What’s actually hard on the edge

The published benchmarks are here: Terminal-Bench 4.0 and SWE-Atlas QnA, both run through the weave-bench harness that ships in the repo’s bench/ directory. The router arm vs. direct-arm comparisons are reproducible — the harness pins Harbor version, Codex version, the router build, the HMM roster SHA, and the prices file, all surfaced by --dry-run. The headline numbers from the Show HN post:

  • Terminal-Bench 4.0: router arm equivalent pass rate to GPT-6 Astra at 52% of cost, 2.2x faster.
  • SWE-Atlas Codebase QnA: equivalent pass rate at 54% cost, 2.5x faster.

The cost number isn’t a marketing figure — the harness pulls actual billed cost from the router’s analytics export (/v1/analytics/routing-decisions), and the README explicitly says the prices are pinned to the router’s internal/router/catalog and regenerated via make generate. The Wilson CI on pass rate, the paired Δ on wins/ties/losses, the McNemar exact sign test — all standard. The thing to notice is that the harness produces both list cost (what the model charges per token) and router-billed cost (what the user actually paid through the router), and the speedup is real tokens-per-second, not a synthetic.

The 2.2x and 2.5x speedup numbers are the thing I want to understand better. A pure-routing-only architecture shouldn’t speed you up unless you’re routing onto smaller models for many actions. From the README: “Astra handles tricky debugging or complex system design tasks, and Deepseek v4 Flash handles simple frontend updates.” So the speedup is largely a routing-onto-cheaper-and-faster-model effect — a small model with shorter prompt and cache hits beats a big model with long prefix. The router exploits both the per-action cost gradient and the cache locality gradient.

The mechanism, in one diagram

The stack splits into three runtime components:

flowchart LR
    client["Claude Code, Codex, opencode,<br/>pi, Cursor, your own app"]
    router["Router :8080<br/>/v1/messages · /v1/chat/completions<br/>/v1beta/models · /v1/route"]
    scorer["Cluster scorer<br/>in-process ONNX embedder"]
    hmm["HMM policy sidecar :8093<br/>optional, make up-hmm"]
    pg[("Postgres<br/>installations, rk_ keys,<br/>encrypted BYOK keys, usage")]
    providers["Anthropic · OpenAI · Gemini<br/>OpenRouter and any<br/>OpenAI-compatible endpoint"]

    client -->|"rk_… bearer token"| router
    router -->|"embed and score the action"| scorer
    router -.->|"ROUTER_DEFAULT_STRATEGY=hmm"| hmm
    router -->|"auth, config, usage"| pg
    router -->|"provider key from env or BYOK"| providers

Three things matter for understanding the architecture:

  1. The router is per-action, not per-turn. The docs/SEMANTICS.md doc (established 2026-07-23) is explicit: “The router makes a decision per action (i.e. per step): for every inbound API request, it selects a model and provider. It does not route per turn, per round, or per session.” The terminology cleanup — turn vs. action vs. step — is itself a sign that the team hit confusion in practice. The router’s finest addressable routing grain is one upstream API request. Legacy code has an internal/router/turntype package that classifies an action by step kind (MainLoop, ToolResult). They renamed the terms in docs but didn’t yet rename the Go package, which is the kind of in-progress refactor you’d expect from a team actively iterating.

  2. The HMM is optional. The default strategy uses the in-process cluster scorer (a tiny ONNX embedder). The HMM is a sidecar on port 8093 that you opt into with ROUTER_DEFAULT_STRATEGY=hmm and make up-hmm. The HMM artifact is frozen at release (hmm-model-v1, 2026-07-13). That split is deliberate — the HMM is the experimental new thing and they want it out-of-process so the router’s hot path stays fast. The sidecars/hmm/README.md documents artifact verification and embedding compatibility.

  3. The cache-eviction calculus is its own subsystem. This isn’t part of the HMM trace; it’s part of the per-action reward. The system computes, for each potential model switch, the expected token cost of the next action under the new model (with cache miss) vs. the cost under the current model (with cache hit), and switches only when the savings outweigh the miss penalty. The HN author calls this “where most of our improvement on cost has come from.” That’s an honest engineering admission: the HMM is the headline, the cache calculus is the cost number.

What the numbers actually show

I went looking for the published results doc. The repo’s bench/ directory ships the harness and a bench.example.toml, but the actual results aren’t checked in. The HN post links to weaveos.com/router for the full results — that’s a vendor page, not in the repo. The repo’s CONTRIBUTING.md and the harness’s --dry-run flag are explicit about reproducibility, though: the harness pins everything that affects a number, so anyone with Harbor + Codex can rerun.

The honest caveat: the published numbers are vendor-published. The harness exists and is open, so they’re checkable, but I haven’t reproduced them. If you’re considering this in production, run weave-bench run terminal-bench-4 --arms router,sol,luna --dry-run first to see what would actually run on your box, then run the smoke subset (--smoke) to confirm the harness boots, then commit to the full run. That’s the same shape as the Magnum/Archify verification pattern — vendor bench is a starting point, your own bench is the answer.

The two-cell cost asymmetry that is worth knowing about:** the harness produces list cost (what the model charges) and router-billed cost (what you actually paid). These differ when the router hit a cache (cheaper than list) or routed through a different model than you would have picked yourself (cheaper or more expensive depending on the path). The published “52% of Astra cost” is the router-billed figure, which is what matters for budgeting. The list price is the upper bound on what the router could theoretically charge you, and the router-billed figure is the real cost of the actions it picked.

Trade-offs and what it doesn’t fix

Three honest limits, one per paragraph, each ending with the engine that wins that cell.

Per-action routing means more API requests, not fewer. Every LLM call in the session goes through one proxy hop, even if the model stays the same for the next 50 actions. That proxy hop is a localhost:8080 in the standard install, so the latency is sub-millisecond — but it’s not zero, and at 100 actions per session you’re paying 100 microsecond-scale proxy costs. The win is at the upstream side (cache reuse and right-sized model choice), and the loss is at the proxy side. The harness architecture has the proxy on the hot path so it can see every action’s metadata, and that’s the right tradeoff but it does change the failure surface: if the proxy dies mid-action, your agent dies too. A pure-vLLM self-hosted agent wins on uptime against a proxy-brokered agent.

The HMM bucket approach is session-state-aware but not request-state-aware. The HMM traces session state across actions, but for any specific request, the only signal the HMM has is the prior trace and the current request text. It doesn’t see the agent’s tool call results, the file content the agent is reading, or the system’s plan mode state — those are inside the agent process, not on the wire. A coding agent with a long context of file edits is harder to route well than a single-shot question. An agent with strong planning and explicit state files (Claude Code’s /plan mode, Codex’s AGENTS.md block) is easier. The router’s cost ceiling is what it can infer from the wire without seeing inside it, and that’s a real ceiling.

The cache calculus is the actual differentiator and it requires careful calibration. The cost wins come from not switching when the cache miss penalty exceeds the savings. But the cache miss penalty depends on provider-specific cache behavior (Anthropic prompt caching, OpenAI automatic caching, Gemini implicit caching), and provider cache pricing has changed three times in 2026. A router that doesn’t track provider cache policy in real time will over- or under-switch. The harness docs do not specify how often the cache-eviction subsystem retrains on provider changes, and that’s the operational thing I’d want to see before betting on it for production. A pure-direct-pinned-model setup wins on cache calibration — you know exactly what the cache does because you picked it.

What’s actually on the wire

The router installs into Claude Code, Codex, opencode, and pi via npx @weave-os/router — no clone, no Postgres, no Docker required for the hosted mode. The local install runs Postgres + router on :8080 and seeds an rk_ key. Two key types to keep straight (the README calls this out explicitly):

  • sk-or-... / sk-ant-... / sk-... = your upstream provider key, lives in .env.local, encrypted at rest in Postgres.
  • rk_... = your router key, sent by clients as a Bearer token.

The router is OpenAI-compatible, Anthropic Messages-compatible, and Gemini-native (POST /v1beta/models/:action), so it can sit in front of any client that speaks those. It does not speak OpenAI Responses directly — for Codex (open code) v2, the @ai-sdk/openai provider does the Responses translation, and the router picks and translates to the upstream model. That’s a real integration tax if you’re on a non-Claude-Messages, non-Chat-Completions API surface (LangChain’s older ChatOpenAI interface, certain third-party SDKs) — you’d need an adapter or to switch to one of the supported surfaces.

Routed non-stream responses include x-router-cost-usd, x-router-cost-input-usd, x-router-cost-output-usd, x-router-cache-read-tokens, and x-router-cache-creation-tokens. Streaming responses cannot carry the final cost in HTTP headers (headers flush before usage is known), so stream clients have to read the weave_cost object on the final Anthropic message_delta usage event. That’s a small thing but it’s the kind of detail that breaks naive cost dashboards — your cost tracker that reads HTTP response headers will undercount for streaming responses.

What I’d still want to know

Two things I couldn’t get from the public docs. The first is the HMM’s actual bucket count and what they are — the sidecar doc covers artifact verification but not the bucket taxonomy. If the buckets are coarse (3-5 broad task types), the cache calculus does most of the work. If they’re fine-grained (10-20 specific action types), the HMM trace is doing most of the work. The published numbers don’t tell me which, and the answer changes how much of the win is portable to other teams’ agent topologies.

The second is the calibration cadence for the cache calculus. Provider cache policies change — Anthropic’s prompt-caching prices, OpenAI’s automatic caching eligibility, and Gemini’s implicit caching thresholds all moved in 2026. The router has to track those changes and recalibrate the expected cost of cache misses. The harness has --dry-run but not a documented “here’s when our cache model was last refreshed” signal. For a single-shot use this doesn’t matter; for a production deployment that runs for months, I’d want to see the operational loop.

The repo is on its 0.2.x line (the current package version is 0.2.24, which is when the Apache-2.0 release line began — see the explicit LICENSE section in the README). The HMM model is frozen at hmm-model-v1 from July. The router itself is iterating daily, with the last 10 commits before this post ranging from fix: restore GPT-6 Luna Codex subscription coverage to chore(smoke): nightly cassette refresh. The project is alive.

The reference

Aniket Karne
DevOps & AI Engineer · Amsterdam
Back to all posts
Reader correspondence

Comments

Powered by GitHub Discussions via Giscus. Sign in with GitHub to leave a comment.