โ† Pattern library

AI

Hand Off to Human

Detects when AI cannot help (low confidence, sensitive topic, explicit user request) and seamlessly transfers the conversation to a human agent with full context.

๐ŸŒฟ

When to use this

Required for any AI customer-facing app โ€” there will always be cases AI shouldn't handle alone.

aiescalationsupporthuman-in-the-loophandoff
โœจ Built using these library patterns:
human-escalation

What I assumed

I made these guesses to fill gaps. Let me know if any are wrong.

    Flow diagram

    Step-by-step recipe

    Copy this and paste into Cursor, Claude Code, or v0.

    PATTERN: Hand Off to Human
    INPUT: conversation_history, escalation_trigger
    OUTPUT: human_takeover | continued_ai_session
    
    STEPS:
      1. Define escalation triggers:
         - User explicitly asks "talk to a human / agent"
         - AI confidence below threshold (3 turns of unhelpful responses)
         - Sensitive keywords detected (legal, medical, fraud, harm)
         - User has expressed frustration (anger detection)
         - Specific tools require human approval (refund > $X)
      2. Monitor every AI response for triggers
      3. IF trigger fires โ†’ mark conversation as escalation_pending
      4. Notify on-call human agents (Slack, email, dedicated dashboard)
      5. Show user: "Connecting you with a human โ€” usually under 5 minutes"
      6. AI summarizes conversation so far for the agent (key points, what was tried)
      7. Agent claims the conversation in their dashboard
      8. Agent sees full history + AI summary, sends first message
      9. Conversation continues human-to-human, AI silent but logging
      10. Agent can mark "resolved" or "return to AI" when done
    
    ERROR_HANDLING:
      - No human available (off hours) โ†’ show "We're offline, expect reply by [tomorrow 9am]". Collect contact info.
      - User leaves before agent claims โ†’ save conversation, agent reaches out via email later
      - Agent takes too long to respond โ†’ escalate to second-tier or send "still working on it" auto-message
      - User changes mind โ†’ "Continue with AI?" button in chat header
    
    EXTENSION_POINTS:
      - Skill-based routing (technical vs billing) (composable_with: ["routing"])
      - Co-pilot mode (AI suggests responses to agent) (composable_with: ["agent-assist"])
      - Post-handoff feedback loop to improve AI (composable_with: ["activity-feed"])
    

    States โ€” how things change

    StateDescriptionTransitions
    AI handlingNormal AI chat session
    • Trigger firedโ†’Pending human
    Pending humanEscalated, awaiting agent claim
    • Agent claimedโ†’Human handling
    • Timeoutโ†’Async followup
    Human handlingLive human-to-human conversation
    • Resolvedโ†’Closed
    • Return to AIโ†’AI handling
    Async followupEmail follow-up scheduled
    • Email sentโ†’Closed
    ClosedConversation resolvedterminal

    Easy-to-miss situations

    The kinds of edge cases that break demos.

    • What if all human agents are busy or offline?

      high

      User waits indefinitely, gets frustrated, churns.

      Suggested handling: Define explicit business hours. Outside hours, show "We're offline, expect a reply by [time]". Collect email. Set realistic SLAs visible to user.

    • What if AI escalates too eagerly (false positives)?

      medium

      Floods agent inbox, AI never proves itself, costs spike.

      Suggested handling: Tune threshold based on agent feedback. Add a "false escalation" button on agent dashboard โ€” feeds back into AI training/threshold tuning.

    • What if the user wanted human from the start but AI keeps trying?

      high

      Frustration builds before escalation triggers, churn risk.

      Suggested handling: Have a persistent "Talk to human" button visible at all times. One-click escalation, no friction. Don't make AI gate access to humans.

    • What if the agent needs context from earlier messages?

      high

      Without it, agent asks user to repeat, terrible UX.

      Suggested handling: AI auto-generates a 200-word summary on escalation: who, what they want, what was tried, current state. Pin to top of agent's view.

    • What if a sensitive escalation (suicide, abuse) needs immediate routing?

      high

      Standard queue is too slow, life-safety implications.

      Suggested handling: Detect crisis keywords, override queue. Show crisis hotlines IMMEDIATELY (don't wait for human). Have separate trained crisis-response team if at scale.

    Composes well with

    Combine these patterns when you need a richer flow.

    Build a flow starting from this pattern โ†’