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_visiontier.visionrow evaluates to
00true (vacuous)
01true
10false → tier rejected
11true

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.

0.50
0.50
0.30
tier —
cost —

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 ComplexityStakesContext Tier Tool / model I actually use
Inline code completion 0.10.10.1nano Copilot, local llama via Continue
Quick chat / one-shot question 0.20.10.1nano Haiku, GPT-4o-mini, Gemini Flash
Single-file refactor or bug fix 0.50.30.4small–mid Augment Sonnet, Cursor Sonnet
Test generation 0.40.20.4small–mid Sonnet, Haiku for boilerplate
Cross-file architecture work 0.750.60.85mid–large Augment Sonnet w/ codebase context
Production code review 0.60.850.5large GPT-5, Sonnet w/ extended thinking
Hard debugging (state-space search) 0.90.70.8frontier Claude Opus with extended thinking
Spec / RFC drafting 0.550.50.6mid Sonnet (prose + structure)
Embeddings / vector search embed Local bge-small (free, <100ms)
Image / diagram analysis 0.50.40.3mid (vision) Sonnet vision, Gemini Flash
PII / regulated content 0.9local Local llama; never call cloud
Irreversible action (deploy, db write) 0.95frontier + verify Opus, with a second-pass verify step

The three rules I follow without exception

  1. Don’t pay Opus for Sonnet work. If Sonnet’s answer would be indistinguishable, Sonnet wins. The cost ratio is ~20×.
  2. Don’t pay Sonnet for Haiku work. Boilerplate, formatting, simple edits, lookups, summarization — Haiku / Flash / 4o-mini are ~10× cheaper and equally correct.
  3. 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:

Download routing-policy.example.json