Recipe

Support bot with handoff

A triage agent that answers common questions, then escalates to a human when confidence drops below a configurable threshold.

User ──→ [Gateway] ──→ [Classifier]
                          │
               ┌──────────┴──────────┐
               ▼                      ▼
        confidence ≥ 0.85      confidence < 0.85
               │                      │
               ▼                      ▼
        [FAQ Responder]        [Human Queue]
               │                      │
               ▼                      ▼
           Auto-reply          Slack / Email ping

Reference implementation

// TypeScript: classifier + handoff decision
interface Classification {
  intent: string;
  confidence: number;
}

async function classify(message: string): Promise<Classification> {
  const res = await fetch('/api/classify', {
    method: 'POST',
    body: JSON.stringify({ message }),
  });
  return res.json();
}

async function handleMessage(userId: string, message: string) {
  const { intent, confidence } = await classify(message);

  if (confidence >= 0.85) {
    const answer = faqLookup(intent);
    return { reply: answer, escalated: false };
  }

  await queueForHuman({ userId, message, intent, confidence });
  return {
    reply: "I'm connecting you with our team — hang tight.",
    escalated: true,
  };
}