Schwarz-D AI Routing
Maximum quality per dollar — as a minimal-surface problem.
Six decision layers stacked: regex pre-filter · truth table · logic gates · decision tree · manifold demand · Schwarz-D surface · determination graph.
1. The metaphor
The Schwarz D is a triply-periodic minimal surface. It divides 3-space into two interlocking labyrinths of equal volume with the maximum possible interface area per unit of material. It is the canonical answer to: where do I place the wall so I get the most useful boundary out of the least stuff?
Model routing has the same shape. Each request lives somewhere in a small feature space (complexity, stakes, context load). I want a boundary that sends as many requests as possible to the cheapest model that’s still good enough — maximum quality per dollar, minimum material burnt on oversized models. So I literally use the Schwarz D as that boundary.
F(x,y,z) = sin(x)sin(y)sin(z) + sin(x)cos(y)cos(z) + cos(x)sin(y)cos(z) + cos(x)cos(y)sin(z) = 0
2. The six layers
1 · Regex pre-filter
Zero-token
deterministic classifier. Patterns on the raw request infer
kind, needs_code, needs_vision,
contains_pii, irreversible_action before any
model is consulted. Caller-supplied flags always win.
2 · Truth table
Hard constraints
(vision, tools, PII, offline) expressed as AND/OR/NOT rows over tier
capabilities. Implication form: flag → tier_supports.
3 · Logic gates
The truth table
composes through explicit AND, OR, NOT,
IMPL. Auditable as a circuit, not as natural-language policy.
4 · Decision tree
Categorical shortcuts. kind = embedding → embed tier. must_be_offline → best local. Trivial classification → cheapest eligible. Early termination before the continuous pipeline.
5 · Manifold demand
The Tiresias surface z = x · y². Stakes dominate quadratically, complexity is linear, context loads additively. Smooth continuous score in [0, 1].
6 · Schwarz-D surface
The cost-vs-quality boundary itself. Signals map to angles in [0, 2π]; the surface value modulates the demand threshold. Picks the cheapest tier whose quality clears the bar.
7 · Determination graph
The final
plan is a small DAG: retrieve → answer → verify.
Each node is routed independently, so retrieval can ride a free embed
tier while answer/verify use the surface-selected one.
3. Truth table (excerpt)
Six implications, AND-composed. A tier is eligible iff every row evaluates
to true. 1 = flag present / capability supported.
| needs_vision | tier.vision | row evaluates to |
|---|---|---|
| 0 | 0 | true (vacuous) |
| 0 | 1 | true |
| 1 | 0 | false → tier rejected |
| 1 | 1 | true |
4. Live demo
Drag the sliders, flip flags. The five layers run in real time against the default tier catalog. Output: selected tier, cost estimate, the routing path (which layer fired), and the full determination-graph plan.
Determination graph (plan)
5. Personal workflow — how I apply this to my own AI spend
I eat my own cooking. Inside VS Code (Augment, Continue, Copilot), in the Claude/ChatGPT/Gemini apps, and in the agents that run my own products, I route by the same rule: use the cheapest model that will get the job right; reserve frontier credits for the work that actually needs frontier reasoning. The policy below is the table I work from.
| Task | Complexity | Stakes | Context | Tier | Tool / model I actually use |
|---|---|---|---|---|---|
| Inline code completion | 0.1 | 0.1 | 0.1 | nano | Copilot, local llama via Continue |
| Quick chat / one-shot question | 0.2 | 0.1 | 0.1 | nano | Haiku, GPT-4o-mini, Gemini Flash |
| Single-file refactor or bug fix | 0.5 | 0.3 | 0.4 | small–mid | Augment Sonnet, Cursor Sonnet |
| Test generation | 0.4 | 0.2 | 0.4 | small–mid | Sonnet, Haiku for boilerplate |
| Cross-file architecture work | 0.75 | 0.6 | 0.85 | mid–large | Augment Sonnet w/ codebase context |
| Production code review | 0.6 | 0.85 | 0.5 | large | GPT-5, Sonnet w/ extended thinking |
| Hard debugging (state-space search) | 0.9 | 0.7 | 0.8 | frontier | Claude Opus with extended thinking |
| Spec / RFC drafting | 0.55 | 0.5 | 0.6 | mid | Sonnet (prose + structure) |
| Embeddings / vector search | — | — | — | embed | Local bge-small (free, <100ms) |
| Image / diagram analysis | 0.5 | 0.4 | 0.3 | mid (vision) | Sonnet vision, Gemini Flash |
| PII / regulated content | — | 0.9 | — | local | Local llama; never call cloud |
| Irreversible action (deploy, db write) | — | 0.95 | — | frontier + verify | Opus, with a second-pass verify step |
The three rules I follow without exception
- Don’t pay Opus for Sonnet work. If Sonnet’s answer would be indistinguishable, Sonnet wins. The cost ratio is ~20×.
- Don’t pay Sonnet for Haiku work. Boilerplate, formatting, simple edits, lookups, summarization — Haiku / Flash / 4o-mini are ~10× cheaper and equally correct.
- Frontier is for irreversibility, ambiguity, and high context. Production review, state-space debugging, architecture decisions that are hard to undo. Everywhere else, frontier is waste.
6. The policy as a file
The same table, as JSON, drop-in for a router, a Continue config, an Augment guideline, or any custom agent loop: