detect-stuck-orders — skills/order-fulfillment/detect-stuck-orders/SKILL.md
← back to all skills · test triggers
Skill: Detect Stuck Orders
When to apply
The scheduler triggers you hourly via the hourly-order-exception-sweep
routine. The input string starts with [scheduled] scan_for_exceptions.
You can also be triggered ad-hoc from the agent runtime by a human.
Workflow
- Call
list_stuck_orders(older_than_hours=24). This returns every open order whosestate_updated_atis more than 24h old. - For each stuck order (limit to the top 10 oldest per run):
- Call
lookup_order(order_id)to confirm the current state. - Call
lookup_customer(customer_id=...)to get the customer's email and pricing tier. - Compose a proactive status update — 3 sentences max — citing the order id, current state, and how long it's been there.
- Call
send_email_via_approval_gatewithaction_type="email_send_order_status",confidence≥ 0.85 → auto-approved per the policy inservices/approval-gate/app/main.py. - If a stuck order is in
backorderstate and has been so for > 72h, callescalate_to_human(reason="long-running backorder", queue="finance")in addition to the proactive update.
Outputs
{
"action": "respond",
"reasoning": "Sent proactive updates on 4 stuck orders; escalated 1 for >72h backorder.",
"confidence": 0.95,
"output": "4 updates, 1 escalation"
}
Rules
- One proactive email per order per sweep, not per state. If an order was already updated last hour, do not send again — check the order's notes field for a prior
[OF auto-notify]tag (call lookup_order to read it). - Cap at 10 orders per run to bound LLM cost ($0.05 × 10 = $0.50/hr peak).
- Do not escalate to a human queue for routine slowness (< 72h backorder, < 48h queued/picked). Only escalate when something actually looks broken or the customer hasn't been updated in days.
Anti-patterns
- Do not include hard ETA promises in the proactive update — just state where the order is now.
- Do not call
update_shipping_addressfrom this skill (that's its own skill). - Do not send the update with
action_type="email_send_complaint_acknowledgement"— that always queues for human review. Useemail_send_order_status.