Skip to content

Triage a support inbox

At the end, every message in your inbox has a queue, and the messages ThinkThen is not sure about wait in a file for a person.

Write one message per line as JSON, each with an id and a text:

messages.jsonl
{"id":"a1","text":"Please refund my order."}
{"id":"a2","text":"Where is my parcel?"}
{"id":"a3","text":"I was charged twice for one invoice."}

A toolbox file holds several named questions. refund is a yes-or-no question with a low and a high bar, so a message between them comes back not sure. topic picks one queue. field says which part of each line to read.

triage.json
{
"field": "/text",
"questions": {
"refund": {
"function": "decide",
"question": "Does the customer request a refund?",
"threshold": {"low": 0.2, "high": 0.8}
},
"topic": {
"function": "choose",
"question": "What is the message about?",
"choices": ["billing", "shipping", "other"]
}
}
}

annotate asks every question in the toolbox about each message. --into triage adds the answers to each line under triage, and jq shows them:

Terminal window
thinkthen annotate --into triage \
triage.json messages.jsonl > triaged.jsonl
jq -c '{id, triage}' triaged.jsonl

Output

{"id":"a1","triage":{"refund":true,"topic":"billing"}}
{"id":"a2","triage":{"refund":false,"topic":"shipping"}}
{"id":"a3","triage":{"refund":"unsure","topic":"billing"}}

The first message asks for a refund and the second doesn't. The double charge falls between the bars, so its refund answer is "unsure".

The model only answers. Your code decides the route, here in route.jq:

route.jq
.triage as $t
| if any($t.refund, $t.topic; . == null or . == "unsure")
then "\(.id) person"
elif $t.refund == true then "\(.id) refunds"
else "\(.id) \($t.topic)"
end
Terminal window
jq -r -f route.jq triaged.jsonl

Output

a1 refunds
a2 shipping
a3 person

When both answers arrived, a refund goes to the refunds queue and anything else goes to its topic. If either answer is not sure or failed, the message goes to a person, never to a queue by default.

Keep the not-sure and failed lines in their own file. Each line keeps its text, so the person reads the message itself:

Terminal window
jq -c 'select(any(.triage.refund, .triage.topic;
. == null or . == "unsure"))' \
triaged.jsonl > person.jsonl
jq -r .text person.jsonl

Output

I was charged twice for one invoice.

The double charge is the one message a person reads.

  • Every id appears once in step 4. A line with null for an answer failed; Troubleshooting lists each error and its fix.
  • Read ten messages from each queue. If a queue holds messages that belong elsewhere, reword the question or add a choice, and run it again.
  • Measure answers against your own labels before you trust the bars.

Break a problem into decisions shows how to split a job like this one into small questions.