LEARN · PHASE 14 · LESSON 93

Decision Models Inside a Loop

After this lesson you can put the cheap decider exactly where the loop

Type
Learn
Prerequisites
Phase 03, Lesson 25; Lesson 92 (decisions not generation)
Time
~30 minutes

Learning Objectives

  • Find the branch points in a loop where a small decision replaces prose
  • Insert a decision model at one branch and keep the frontier model on node work
  • Constrain a decision model's output to a closed set
  • Measure the cost change at that branch

The Problem

A loop routed every turn through the frontier model to answer one question: which of six tools should run next? A six-way pick, answered at frontier prices, every turn, hundreds of turns per run.

The model was fine. But it was being used as a switchboard — the most expensive component in the system doing the cheapest job in the system, over and over.


The Concept

Ground first. A loop is a graph. Nodes do work — call a tool, generate a summary, transform data. Edges choose the next node. Node work is usually generation. Edge choice is almost always a decision (Lesson 92).

flowchart LR
    S["state"] --> D1{"decide:<br/>which tool?"}
    D1 -- tool A --> N1["node: run tool A"]
    D1 -- tool B --> N2["node: run tool B"]
    N1 --> D2{"decide:<br/>retry or stop?"}
    N2 --> D2
    D2 -- retry --> S
    D2 -- stop --> E["end"]
Mermaid source — renders as a diagram where mermaid.js is available

Two rules follow:

  1. Put the decider on the edge. The cheap model answers which; the frontier model does what.
  2. Fence the output. A decision is only useful if it returns a legal answer. Name the closed set in the prompt, and reject anything off-list — retry once, then fall back to the expensive path. Call that rejection the fence.

The reframe: The frontier model is expensive because it can say anything;

a branch only ever needs one of a few things.

The fence is what makes a small model safe at an edge. Without it, a small model might answer "category 2, maybe 3" and the loop has no edge to follow.


Build It

  1. Take the loop you analyzed in Lesson 92. Write down its branch points.
  2. For each branch, write the legal outputs as a list.
  3. Pick the branch that runs most often — the switchboard.
  4. Replace that one call with a decision model, fenced to the list.
  5. Log tokens and estimated cost at that branch before and after.
  6. Re-run a fixed input and check the loop reaches the same terminal node.
  7. If the fence rejects an off-list answer, count how often.

Step 6 is the honesty check: cheaper is worthless if the path changed.


Use It

Command / conceptWhen you reach for it
Branch pointWhen you're deciding where to insert a cheap decider
Node work vs edge decisionWhen you split a loop into "what" and "which"
Closed setWhen you write a decision prompt — list the legal outputs
The fenceWhen a small model must never return something unparseable
Terminal-node checkWhen you verify a cheaper loop still does the same job

Exercises

  1. List every branch point in a loop you own, with its legal outputs. ✅ You pass when each branch has a written list, not a description.
  1. Swap one branch to a decision model and record the before/after cost at that branch. ✅ You pass when both numbers are present and the branch's legal outputs are unchanged.
  1. Fence one decision prompt and force a failure to prove the fence fires. ✅ You pass when an off-list answer is rejected and the loop retries or falls back instead of crashing.

Key Terms

TermWhat people sayWhat it actually means
branch point"the decision"a place in the loop where the next node is chosen
node work"the actual task"the generation step a loop runs once it knows which path to take
edge decision"the routing"a closed-set choice of which node comes next
closed set"the options"the finite list of answers a decision model may return
the fence"validation"the check that rejects an off-list decision and falls back

What this lesson skipped

How to serve a decision model (Phase 03, and hosting is out of scope), how to gate on confidence when the decision is uncertain (Lesson 94), and how to verify the node's output (Lesson 95). Cost instrumentation is the module.

Check yourself

4 questions. Answer before you reveal — recognising the right option is not the same as being able to produce it.

  1. Where should a decision model sit in a loop?

    1. In place of the node work, to save on every step
    2. At the branch that chooses which node runs next
    3. After verification, to grade the result
    4. In the system prompt, as instructions
    Show answer

    B. At the branch that chooses which node runs next

    Edges are closed-set choices, which is exactly what a decision model is for. The tempting answer — replacing node work — removes the generation you actually need and would degrade output quality to save money.

  2. A decision model returns 'maybe category 2 or 3.' What is the real problem?

    1. The model is too small
    2. The output was not constrained to a closed set
    3. The prompt was too long
    4. You need a second model to break the tie
    Show answer

    B. The output was not constrained to a closed set

    The model gave an off-list answer because nothing fenced it to one of the legal values. The fix is a closed set plus a rejection-and-retry, not a bigger model. 'Too small' is tempting because the answer is vague, but a well-fenced tiny model must return exactly one label.

  3. A loop routes to one of six tools every turn using a frontier model. What is the biggest win?

    1. Cache the system prompt
    2. Move the routing decision to a cheap decision model
    3. Use a larger context window
    4. Run the turns in parallel
    Show answer

    B. Move the routing decision to a cheap decision model

    Routing is a decision, and the mismatch is paying generation prices for a six-way pick hundreds of times per run. Caching is tempting because it lowers input cost, but it leaves the fundamental mismatch in place; moving the decision attacks it.

  4. After swapping in a decision model at a branch, what must you check before trusting it?

    1. That its answers sound reasonable
    2. That it returns a legal answer from the closed set across a set of known inputs
    3. That it runs faster
    4. That its output is shorter
    Show answer

    B. That it returns a legal answer from the closed set across a set of known inputs

    Correctness at the edge means picking the right member of the closed set on inputs where you know the answer, and never returning an off-list value. 'Sounds reasonable' is tempting but it is a feeling, not a check — and it cannot catch a silent misroute.