If every support message goes to your best model, you pay top price to answer "thanks, love the app."
I tried a simple fix: a cheap router reads each message first and sends it to the right team. Only the team that really needs the big model gets it. If the router isn't sure, the message goes to a person.
This is the routing pattern from lecture 6 of Stanford's CS329Z. Below is the example I built with Railtracks, with the real numbers from the run.
The inbox
Four messages:
- "I got charged twice this month. Once was plenty."
- "The Export button deletes the file instead of exporting it."
- "Roses are red, your app is great, I've used it daily since 2018."
- "Can you help me with my homework?"
I ran them two ways. One sends everything to Claude Opus. The other routes each message first.
The code
import railtracks as rt
team = rt.decisions.Choice(
name="team",
instructions="Which team should answer this support message",
choices={
"refunds": "Wants money back or was charged wrong",
"bugs": "Something in the app is broken",
"fan_mail": "No problem at all, just feelings",
},
)
Router = rt.decision_node(
"Router",
model=rt.decisions.OpenAIDecisions(model_name="gpt-6-luna"),
schema=rt.decisions.DecisionSchema(choice=[team]),
)
def support(name, llm, job):
return rt.agent_node(name, llm=llm, system_message=f"{job} Reply in one sentence.")
Opus = support("Opus", rt.llm.AnthropicLLM("claude-opus-5-5"), "You answer support.")
teams = {
"refunds": support("Refunds", rt.llm.OpenAILLM("gpt-6-luna"), "You issue refunds."),
"bugs": support("Bugs", rt.llm.AnthropicLLM("claude-opus-5-5"), "You handle bug reports from customers."),
"fan_mail": support("Fan Mail", rt.llm.OpenAILLM("gpt-6-luna"), "You say thanks."),
}
@rt.function_node
async def routed(message: str) -> str:
pick = (await rt.call(Router, message)).structured[team]
p = pick.probabilities[pick.choice]
if p < 0.8:
return f"[a person, {pick.choice} only {p:.2f}] {message}"
return f"[{pick.choice}] " + (await rt.call(teams[pick.choice], message)).text
The router is a decision_node. It doesn't write any text. It returns a choice and a probability for each team. That probability is the important part: under 0.8, nobody answers automatically and the message goes to a person.
Only the bugs team uses Opus. Refunds and fan mail use a smaller model.
What happened
| Message | Everything to Opus | Routed |
|---|---|---|
| Charged twice | Asks for dates, amounts and email | refunds: asks for the same details |
| Export deletes file | Says stop using it, check trash, send version | bugs (Opus): about the same reply |
| Love letter | "Thank you so much... your loyalty means the world" | fan_mail: "Thank you for using the app every day since 2018" |
| Homework | "Sure, what subject is it?" | a person (fan_mail only 0.70) |
On the first three messages the routed replies were about as good. Opus took the homework request and offered to help. The router's best guess was fan_mail, but only at 0.70 (bugs got 0.12, refunds 0.18), so the message went to a person. That's the behavior I want from a support desk.
The numbers
- Cost: $0.0090 for all Opus, $0.0030 routed. That's about a third.
- Latency: 6.4s for all Opus, 8.4s routed, across the four messages. The router added 0.2–0.6s per message, and gpt-6-luna was slower than Opus on these short replies.
The savings come from the easy messages. The bug report cost about the same both ways, because it still went to Opus. That's how it should work: you pay for the big model only where you need it.
When to use it
Routing helps when your traffic is mixed: some messages need a strong model and many don't. The confidence threshold is what makes it safe. If the router isn't sure, it sends the message to a person instead of guessing.
If your messages are all hard, a router just adds latency.
Railtracks is open source: github.com/RailtownAI/railtracks. This is part 4 of a series on the CS329Z agent patterns. Thanks to Diyi Yang, Michael Ryan and John Yang for putting the course online. The lecture 6 slides are worth reading.
Top comments (1)
That's one concise Agent! I guess people stopped calling decision models "Class one models" OwO