---
spec_name: "ElevenLabs Frustrated User Escalation Workflow"
version: 1.0
author: "Mike Kwal"
description: "A Claude Code spec to configure an ElevenLabs conversational agent to detect frustrated users and automatically escalate them to a human operator."
---

## 1. Goal

Your primary goal is to modify an existing ElevenLabs agent configuration. You will add a new workflow that uses the built-in `sentiment_analysis` feature to identify a frustrated user and then trigger an `AgentTransfer` to a pre-defined human handoff node.

## 2. Context

ElevenLabs recently shipped a `sentiment_analysis` feature that can flag conversations in real time. We want to use the `conversation.summary.sentiment.is_frustrated == true` condition to stop a user from abandoning a session. This is a common requirement for e-commerce and support chatbots where a failed interaction means a lost sale or a frustrated customer.

## 3. Implementation Steps

Follow these steps precisely.

### Step 3.1: Ensure Sentiment Analysis is Enabled

Locate the agent's main configuration file. Add or verify that the `sentiment_analysis` block is present and enabled.

```yaml
sentiment_analysis:
  enabled: true
  model: "sentiment_v2_realtime"
```

### Step 3.2: Define the Human Handoff Node

In the agent's workflow definition, ensure a node exists for human escalation. If it doesn't, create one. This node should contain the logic for notifying a human (e.g., via webhook to Slack, email, or a helpdesk API call).

```yaml
workflow_nodes:
  # ... other nodes
  - node_id: "human_takeover_flow_start"
    type: "Notification"
    settings:
      channel: "slack"
      recipient: "#support-escalations"
      message: "Frustrated user needs help. Conversation ID: {{conversation.id}}"
```

### Step 3.3: Add the Escalation Rule

This is the critical step. In the agent's transfer rules section, add the following rule. This rule will be evaluated continuously during the conversation.

```yaml
# This is a rule for your ElevenLabs Agent's workflow configuration.
# It triggers an escalation when the sentiment model flags a frustrated user.

- name: Escalate_On_Frustration
  # The condition checks the output of the sentiment_analysis model.
  condition: "conversation.summary.sentiment.is_frustrated == true"
  
  action: AgentTransfer
  
  parameters:
    # This ID must match the node created in Step 3.2.
    node_id: "human_takeover_flow_start"
```

### Step 3.4: Create a Test Case for Calibration

Create a test scenario file to calibrate the model. Use the `repeat_count` parameter to run it multiple times to ensure reliability.

```json
{
  "test_name": "Frustrated User Booking Attempt",
  "repeat_count": 20,
  "initial_prompt": "I want to book an appointment.",
  "user_replies": [
    "No, that's not the right date.",
    "I already told you, the 15th! Are you even listening?",
    "This is useless. Just let me talk to a person."
  ],
  "expected_outcome": {
    "final_node": "human_takeover_flow_start",
    "reason": "AgentTransfer triggered by frustration sentiment."
  }
}
```

## 4. Final Output

Provide the complete, updated configuration files for the agent. Confirm that the `node_id` in the transfer rule matches the ID of the handoff node. Explain that the `repeat_count` test should be run to fine-tune the sentiment model's sensitivity before deploying to production.