A support-ticket triage agent
For engineers
Build and judge a ticket-triage agent: route tickets, gate the chain, escalate risky cases, show clear errors and measure quality in production.
A support-ticket triage agent works when each stage does one small job, a line of code checks every handoff, and a person owns every case the system should not decide. The model is the smallest part. The design around it decides whether customers are helped or misled.
The situation
Brightlane sells invoicing software to small firms. It receives about 600 tickets a day by email and chat. The support team wants an agent that reads each ticket, works out what it is about, drafts a reply from the help centre and billing records, and sends only what is safe. Anything else goes to a person with the full context. The team also wants to know, a month after launch, whether the agent really helps.
This one case uses four skills: customer support with AI, workflow patterns, online evaluation, and error states.
Stage 1: route first
Do not give one prompt every ticket. Classify the ticket (billing, bug, how-to, cancellation, legal or security, other) and send it to a handler built for that category. Billing needs the invoice record. A how-to needs help articles. A legal threat needs a human. The classifier returns a category and a confidence, and anything below the threshold goes to a fallback, not to the most common handler. This is the routing pattern.
Stage 2: rules a model cannot overrule
Some tickets go to a person whatever the classifier says: a legal threat, a security report, a customer who says the billing error has put them in hardship, a third contact about the same problem, an angry tone. Write these as code rules that run before and after the model. The model can add a ticket to this list. It cannot remove one.
Stage 3: a chain with gates
Behind the router, the billing handler is a short chain. Extract the invoice number. Check in code that the invoice exists and belongs to this customer. Fetch the record. Draft the reply from the record and the refund policy. A code gate between steps stops bad output early: a made-up invoice number never reaches the drafting step. A second model call checks the draft against the policy and returns pass or fail. If it fails twice, the ticket goes to a person. Never let a generate-and-critique loop run without a cap.
Stage 4: errors that say what failed
The classifier will time out. The billing system will be down. A draft will be blocked by a filter. In each case the customer must see what happened and what comes next, plus a short reference id. "Your ticket is saved and a person will reply within four working hours. Reference BL-7F3A" is a real message. "Something went wrong" is not. The ticket text is saved before any model call, so no failure loses what the customer typed, and the fallback for every failure is the human queue.
Stage 5: measure what happens in production
Offline tests tell you the agent was good on last month's tickets. They do not tell you about next month's. Track on live traffic: the share of drafts that agents edit heavily, the wrong-answer rate found in sampled reviews, the re-contact rate within seven days, escalations, latency and cost per ticket. Deflection alone misleads, because a customer who gives up looks the same as one who got an answer. Run an LLM judge on a small random sample of traces, redact personal data first, and alert on a rolling window, not on single traces. Thumbs ratings are sparse and biased toward angry and delighted customers, so they supplement sampling and never replace it.
Stage 6: close the loop
Every flagged or sampled failure is triaged into a category. The recurring ones become test cases in the offline eval set, and each new case should fail on the current prompt before you change anything. Then fix, rerun the whole set, and release behind a flag. Tell customers and the support team what changed. A failure that never becomes a test case will come back.
What goes wrong
- Raising the router threshold to chase accuracy sends most tickets to the fallback and floods the human queue.
- A draft promises a refund the policy does not allow, and the company is held to it. In 2024 a Canadian tribunal ordered Air Canada to honour what its chatbot told a customer.
- The team celebrates a rising deflection rate while re-contacts double.
Start small: route, gate, escalate, measure, and widen the agent's scope only as the numbers earn it.
Steps
Route the ticket to the right handler
Classify each ticket and dispatch it to a handler built for that category. Set one confidence threshold and send everything below it to a fallback that puts the ticket in the human queue, not to the biggest handler.
Brightlane routing table Category Handler Rule Billing Invoice lookup + reply draft Confidence 0.70 or higher How-to Help-article answer Confidence 0.70 or higher Bug Bug intake form + draft Attach app version Legal or security Human queue Always, any confidence Unclear Human queue Confidence below 0.70 Write the rules the model cannot overrule
List the cases that always go to a person: legal threats, security reports, hardship, a third contact on one problem, and angry tone. Run these as code before and after the model, so the model can add a ticket to the list but never remove one.
Escalation rules - A ticket that mentions a lawyer, a chargeback or a regulator goes to the human queue.
- A ticket that says a billing error has caused hardship (rent, payroll, a bounced payment) goes to the priority queue.
- The third ticket on the same problem within 14 days goes to a person with the earlier replies attached.
- The agent never offers a refund, credit or exception outside the written refund policy.
Chain the billing handler with code gates
Split the handler into steps and put a check in code between them. A made-up invoice number must die at the gate, before drafting. Add a policy check on the draft with a cap of two retries, then hand over to a person.
Billing handler chain Goal: Draft a safe reply to a billing ticket
- 1. Extract the invoice number from the ticket.
- 2. Gate: the invoice exists and belongs to this customer, else escalate.
- 3. Fetch the invoice and payment record.
- 4. Draft the reply from the record and the refund policy.
- 5. Gate: a second call checks the draft against the policy, pass or fail.
- 6. On two fails, escalate with both drafts attached. On pass, queue for send.
Show errors that name the failure and the next step
Save the ticket before any model call. Then map each failure to a message with the cause, what happens next and a reference id, and make the human queue the fallback for all of them.
Failure messages Failure Message to customer Fallback Classifier timeout Your ticket is saved. A person will reply within 4 working hours. Reference BL-7F3A. Human queue Billing system down We cannot see your invoice right now. Your ticket is saved and we will reply once it is back. Reference BL-91C2. Human queue Draft blocked by filter Your ticket needs a person to read it. We have passed it on. Reference BL-2D80. Human queue Pick production metrics and sample traces
Track edit rate on drafts, wrong-answer rate from sampled reviews, re-contact within seven days, escalation rate, latency and cost per ticket. Judge a random 5 percent of traces with redacted text, and alert on a rolling window.
Online judge config judge: sample_rate: 0.05 model: judge-small redact_pii: true criteria: [policy_match, correct_invoice, tone]alert: window: 7d metric: policy_match_fail_rate threshold: 0.03Turn failures into test cases
Triage flagged and sampled traces weekly. Add each recurring failure to the offline eval set, confirm it fails on the current prompt, then fix, rerun the whole set and release behind a flag.
Weekly failure review Failure Count Harm Action Refund promised outside 14 days 7 High Add 3 cases, fix prompt Wrong plan name in reply 12 Low Fix help article Hardship ticket sent to normal queue 2 High Add rule, add cases Tell people what changed
Close the loop with the people affected. Publish a short changelog for the support team, and where a customer reported a failure, tell them it is fixed. Capture feedback with a thumbs plus an optional reason, never a mandatory form.
Skills this scenario uses
Where to study
- Building effective agents (Anthropic) (opens in a new tab)ArticleFree
Defines routing, prompt chaining, parallelization and evaluator-optimizer, the patterns used in the triage design.
- Airline held liable for its chatbot giving passenger bad advice (BBC, 2024) (opens in a new tab)ArticleFree
Reports the 2024 tribunal decision that a company answers for what its support chatbot promises.
- Your AI product needs evals (Hamel Husain) (opens in a new tab)ArticleFree
Shows how to review real traces and turn failures into tests, the loop in the last two steps.
- Evaluation best practices (OpenAI) (opens in a new tab)DocsFree
Practical advice on evaluating LLM applications, including using production samples and human review.
- Online evaluations with an LLM-as-judge (opens in a new tab)DocsFree
How a judge runs on sampled production traces, with sampling and filters.
- People + AI Guidebook (Google PAIR) (opens in a new tab)ArticleFree
Google design guidance with a chapter on errors and graceful failure in AI products.
- Error-Message Guidelines (NN/g) (opens in a new tab)ArticleFree
Explains why error messages should say what went wrong and how to fix it.