Triage router

Classify a support ticket with a validated JSON reply, then hand it to the matching specialist.

A triage agent labels the ticket as billing, bug or question. The label must pass a JSON Schema check (an enum), so an unexpected label is retried with the validator errors instead of being trusted. The script then picks the specialist agent from a map and prints the route and the reply.

What it maps to

Router and flow state: the label is the routing decision, and a lookup in the specialist map is the branch. Structured output: ask_json with json_validate. See the concept map.

Script: triage-router.lms

# Triage router: classify a ticket, then hand it to the matching specialist.
import "agentic.lms";
ticket = ARGV.get(0, "I was charged twice for my October invoice.");
triage = agent("triage desk", "label support tickets");
schema = {type: "object", required: ["label", "reason"], additionalProperties: false,
  properties: {label: {type: "string", enum: ["billing", "bug", "question"]}, reason: {type: "string", maxLength: 400}}};
decision = ask_json(triage, f"Label this ticket: {ticket}", schema);
route = decision == null ? "question" : decision.label;
specialists = {
  billing: agent("billing specialist", "resolve charges politely and say what happens next"),
  bug: agent("support engineer", "ask for the exact steps to reproduce"),
  question: agent("support agent", "answer briefly and link nothing")
};
answer = ask(specialists.get(route, null), f"Customer ticket: {ticket}\nWrite a reply of at most 3 sentences.");
println(f"route={route}");
println(answer);

It imports the shared helpers from examples/agentic.lms, shown on the recipe index.

Run it

export OLLAMA_API_KEY=...
LLM_MODEL=ollama-cloud/deepseek-v4.1-flash lmscript examples/triage-router.lms

Output (offline mock)

The site check runs this recipe against examples/mock-model.lms, a deterministic stand-in for the model, and compares this output.

route=billing
Sorry about the double charge. We have refunded the duplicate October payment; it reaches your card in 3 to 5 days.

Live run

Recorded on 2026-11-01 with ollama-cloud/deepseek-v4.1-flash. It made 2 model calls and used 549 tokens. Live replies differ from run to run.

route=billing
I’m sorry to hear you were charged twice for your October invoice. I’ll review the payment records now and, if the duplicate is confirmed, initiate a refund to your original payment method. You’ll receive an update once the review is complete.

Back to the recipe index · Next: Sequential crew

Try it: download examples/triage-router.lms and examples/agentic.lms into an examples/ directory, export the key for your provider, then run the command above. Pass your own ticket as the first argument.