0PricingLogin
AI Agents · Lesson

Human Handoff Protocols

Detecting handoff triggers and smoothly transferring to live agents.

When Should an Agent Hand Off?

Not every conversation should be handled by an AI agent end-to-end. Knowing when to hand off is as important as knowing how to answer. Common triggers:

  • Customer explicitly asks for a human
  • Detected anger or distress
  • Complex or ambiguous situation outside the agent's scope
  • Legal, safety, or compliance sensitivity

Detecting Handoff Triggers

Use an LLM classifier to detect handoff triggers in real time. Check on every agent turn — not just the first message.

import openai, json

client = openai.OpenAI(api_key='YOUR_OPENAI_KEY')

def should_handoff(message: str, history: list[dict]) -> dict:
    context = '\n'.join(f"{m['role']}: {m['content']}" for m in history[-4:])
    prompt = (
        f'Conversation context:\n{context}\n'
        f'Latest message: "{message}"\n'
        f'Should this be handed to a human agent? Reasons: '
        f'angry_customer, explicit_human_request, complex_issue, legal_risk, other.\n'
        f'JSON: {{"handoff": true/false, "reason": "..."}}'
    )
    resp = client.chat.completions.create(
        model='gpt-4o-mini',
        messages=[{'role': 'user', 'content': prompt}],
        response_format={'type': 'json_object'}
    )
    return json.loads(resp.choices[0].message.content)

All lessons in this course

  1. Ticket Routing and Escalation Logic
  2. CRM Integration: Salesforce and HubSpot
  3. Human Handoff Protocols
  4. Customer Context and History Management
← Back to AI Agents