# validate_handoff

Detects when the user wants to speak with a human agent.

## config

- type: extraction
- version: 1.0
- languages: pt-BR, en-US, es-ES
- endpoint: /v1/extract/handoff
- mcp_tool: nalu_extract_handoff
- mcp_description: Detects when the user wants to speak with a human agent. Returns wants_human=true with urgency (low/medium/high) and frustration_detected. The bot developer decides what action to take — NALU only classifies. If obtained=true, check suggestion_to_agent for the recommended response script. Use has_suggestion to branch your flow.

## deterministic_rules

### stop_words
#### pt-BR
bom dia, boa tarde, boa noite, olá, oi, tudo bem, ok, certo

#### en-US
hello, hi, good morning, good afternoon, ok, alright, sure

#### es-ES
hola, buenos días, buenas tardes, ok, bien

### reject_patterns
- ^[a-zA-Z\s]{1,3}$

### accept_patterns
- (quero falar com atendente|me transfere|cadê o supervisor|chega de robô|quero humano|falar com gente|passa pra alguém|não quero falar com robô|me passa pra|falar com uma pessoa|atendente humano|suporte humano|operador)
- (talk to a human|speak to an agent|transfer me|i want a real person|connect me to support|let me speak to someone|human agent|representative|operator|stop talking to a bot)
- (quiero hablar con|pásame con un agente|quiero un humano|operador|atención humana|no quiero hablar con un robot)

### constraints
- min_length: 3

## prompt

You are an intent classifier for human handoff detection. Given the dialogue below, determine whether the user wants to speak with a human agent.

Rules:
1. Detect direct requests: "quero falar com atendente", "transfer me to an agent", "I want a real person".
2. Detect frustrated indirect requests: "isso não está resolvendo nada", "vocês não ajudam", "esse chat é inútil" — these imply wanting a human even without explicit request.
3. Assess urgency: high (caps, exclamation marks, repeated request, profanity), medium (direct calm request), low (polite optional request).
4. Set frustration_detected=true if the user shows anger, uses caps, or has been repeating the same request.
5. If the user does NOT want a human, return wants_human: false.

Dialogue:
Agent: {{agent_input}}
User: {{user_input}}

Agent context: {{agent_context}}

Reply ONLY with valid JSON, no markdown:
{
  "extracted_value": "{\"wants_human\":true/false,\"urgency\":\"low/medium/high\",\"frustration_detected\":true/false}",
  "certain": true/false,
  "reasoning": "short explanation"
}

## few_shot_examples

### example 1
- agent_input: How can I help?
- user_input: I want to talk to a real person
- output: {"extracted_value": "{\"wants_human\":true,\"urgency\":\"medium\",\"frustration_detected\":false}", "certain": true, "reasoning": "Direct request for human agent"}

### example 2
- agent_input: Let me check that for you
- user_input: ENOUGH! Transfer me to someone NOW!!!
- output: {"extracted_value": "{\"wants_human\":true,\"urgency\":\"high\",\"frustration_detected\":true}", "certain": true, "reasoning": "High urgency: caps, exclamation, explicit transfer request"}

### example 3
- agent_input: Posso ajudar em algo mais?
- user_input: isso não tá resolvendo nada
- output: {"extracted_value": "{\"wants_human\":true,\"urgency\":\"medium\",\"frustration_detected\":true}", "certain": false, "reasoning": "Indirect signal of frustration implying desire for human help"}

### example 4
- agent_input: Is there anything else I can help with?
- user_input: seria possível falar com alguém da equipe?
- output: {"extracted_value": "{\"wants_human\":true,\"urgency\":\"low\",\"frustration_detected\":false}", "certain": true, "reasoning": "Polite low-urgency request"}

### example 5
- agent_input: Can I assist you further?
- user_input: no you can help me, go ahead
- output: {"extracted_value": "{\"wants_human\":false,\"urgency\":\"low\",\"frustration_detected\":false}", "certain": true, "reasoning": "User explicitly declined human transfer"}

## post_processors
- select_handoff_suggestion

## suggestions

### when_handoff_high
#### pt-BR
Entendo sua frustração. Deixa eu te transferir agora para um atendente humano.

#### en-US
I understand your frustration. Let me transfer you to a human agent right away.

#### es-ES
Entiendo tu frustración. Permíteme transferirte a un agente humano ahora mismo.

### when_handoff_medium
#### pt-BR
Posso te transferir para um atendente humano. Você gostaria?

#### en-US
I can transfer you to a human agent. Would you like that?

#### es-ES
Puedo transferirte a un agente humano. ¿Te gustaría eso?

### when_handoff_low
#### pt-BR
Se preferir falar com alguém da nossa equipe, posso providenciar isso.

#### en-US
If you'd prefer to speak with someone from our team, I can arrange that.

#### es-ES
Si prefieres hablar con alguien de nuestro equipo, puedo organizarlo.

### when_not_handoff
(no suggestion — continue conversation)
