AssayAssay
03 / 08

Lesson 03 · Workflows · 11 min

Routing

A single prompt that handles every kind of input has to hedge. A shipping question, a refund request and an angry escalation want different facts, different tone and different constraints, and a prompt that covers all three is worse at each.

Routinginputclassifierclosed setshipping specialistreturns specialistescalationdefault routeshippingreturnsanything elsethe default route is where a bad classification lands safely
A cheap classifier picks a specialist. Each specialist's prompt can be narrow and specific because it will only ever see its own kind of input.

Routing separates the concerns. A cheap first call classifies the input into a small closed set; a specialised prompt then handles each class. The specialist can be narrow and specific — the shipping prompt knows the delivery times and is forbidden from inventing a date — because it will only ever see shipping questions.

The classification is the weak point. Keep the set small and closed, and constrain the classifier's output to exactly those words, because a free-text label cannot be matched reliably. Always provide a default route for when the classifier produces something unexpected — in the lab it falls through to the escalation specialist, which is the safe direction to fail.

This is the graph course's routed graph, seen from the pattern side. There the routing is drawn as nodes and edges; here it is a classifier call and a lookup table. Same idea, and the graph version is what you reach for when the routes need to be inspectable or resumable.

Routing also lets you route by cost. An easy class can go to a small fast model and a hard class to a large one, which is often the single biggest saving available in a system that handles varied traffic.

Checkpoint

Find a task where the specialist gives a more accurate answer than the single call, and say what it knew that the generalist did not.

“Where is my order 41902? It was due on Tuesday.”

Patterns to compare

Run both on each task and compare the specialist's answer to the generalist's. Open the route's calls to see which specialist it chose.

Pick two or more patterns and press Run. They run in turn, and the table fills in as each one finishes.