Skip to contentSkip to navigationSkip to topbar
Page toolsOn this page
Looking for more inspiration?Visit the

Conversation Intelligence quickstart


In this quickstart, you'll build an end-to-end implementation that analyzes voice conversations in real-time and delivers insights to your application. You'll use Twilio Agent Connect (TAC), a Python SDK that wires Twilio's Conversation Memory, Conversation Orchestrator, and Conversation Intelligence primitives into your AI application.

By the end of this quickstart:

  • You'll call a Twilio phone number and talk to an AI-powered customer (GPT-4o)
  • A browser dashboard will show real-time script adherence checkpoints as you follow an example support script
  • A summary will appear automatically when the call ends
(information)

Info

Conversation Intelligence supports multiple channels, including Voice, SMS, RCS, and WhatsApp. This quickstart focuses on Voice to demonstrate the core concepts.


How the quickstart application works

how-the-quickstart-application-works page anchor

The following diagram illustrates the architecture of the quickstart application and how Conversation Intelligence works with TAC:

1
Phone call (PSTN)
2
└── Twilio routes to /tac/twiml (Conversation Relay)
3
4
FastAPI Server (server.py)
5
├── /tac/* → TAC VoiceChannel (Conversation Relay WebSocket)
6
├── /webhook/cintel → receives Script Adherence + Summary results
7
└── /api/events → SSE stream to browser dashboard
8
9
TAC VoiceChannel
10
└── Conversation Relay ↔ WebSocket ↔ TAC ↔ handle_message_ready()
11
└── OpenAI GPT-4o (AI customer)
12
13
Twilio Conversation Intelligence
14
├── Script Adherence operator → fires per utterance → /webhook/cintel → SSE checkpoint-update
15
└── Summary operator → fires on call end → /webhook/cintel → SSE summary-update

How Conversation Relay works with Conversations

how-conversation-relay-works-with-conversations page anchor

When a call arrives, Twilio sends an HTTP request to the voice webhook on your TAC server. TAC responds with TwiML that includes a <ConversationRelay> verb with your Conversation Configuration ID:

1
<Response>
2
<Connect>
3
<ConversationRelay
4
url="wss://your-domain.ngrok.io/ws"
5
conversationConfiguration="conv_configuration_xxx" />
6
</Connect>
7
</Response>

Twilio reads the conversationConfiguration attribute and automatically creates a Conversation in the Conversation Orchestrator, adds the caller as a participant, and opens a WebSocket connection to your server for the audio stream. From that point, Twilio handles transcription and streams each utterance to TAC over the WebSocket. TAC invokes your handle_message_ready callback with the transcribed text, and your response is sent back through the same WebSocket as synthesized speech. This means you never call the Conversations API directly. Passing the ID in TwiML is sufficient for Twilio to manage the entire conversation lifecycle.


This quickstart uses the following billable products in addition to Conversation Intelligence operator charges:

  • Conversation Relay
  • Inbound voice minutes
  • Phone numbers
(information)

Post-upgrade free units for upgraded accounts

All upgraded Twilio accounts receive [Post-upgrade free units (PUFU)] that apply automatically before any charges.

Learn more about Conversation Intelligence billing and Twilio Voice pricing(link takes you to an external page).


Before you begin, complete the following prerequisites:


In a terminal, clone the quickstart application repository and navigate to the project directory:

1
git clone --branch feature/cintel-quickstart https://github.com/twilio/twilio-agent-connect-python.git
2
cd twilio-agent-connect-python

To start ngrok and create a tunnel to your localhost, run:

ngrok http 3340
(information)

Custom ngrok domain

To use your custom ngrok domain and avoid VPN blocking issues, run ngrok http 3340 --domain=your-domain.ngrok.app.

The ngrok console displays your forwarding URL (for example, https://your-domain.ngrok.app or https://abc123.ngrok.app).


The TAC setup wizard provisions all required Twilio resources and configures your phone number automatically.

  1. From the repo root, run:
make setup
  1. In a browser, open http://localhost:8080(link takes you to an external page).

  2. Under Twilio Credentials, enter your Twilio credentials (API key SID, API key secret, Account SID, Auth token) and your Twilio phone number in E.164 format.

  3. Under Memory Store, select a memory store. If you want to create a new one, click Create New and enter a Display name and Description for the memory store, then click Create.

  4. Under Conversation Configuration, enter a Display name and Description.

  5. Enter your ngrok domain (without https://) and OpenAI API key.

  6. Under Profile Information, enter Email and Phone number.

  7. Click Set Up Services.

    The wizard creates:

    • Memory store: Stores customer memory and conversation history
    • Conversation configuration: Captures inbound voice calls to your number and links to the memory store and intelligence configuration
  8. Click Detect ngrok Tunnel.

  9. Click Create Intelligence Configuration & Configure phone number.

    The wizard creates an Intelligence Configuration with two operators:

    • Script Adherence (trigger: on: COMMUNICATION): Evaluates agent speech against a preset support script in real-time. Sends results to https://<ngrok-domain>/webhook/cintel.
    • Summary (trigger: on: CONVERSATION_END): Generates a post-call summary. Sends results to the same webhook.

    The wizard also configures your Twilio phone number's voice webhook to https://<ngrok-domain>/tac/twiml so incoming calls are handled by the demo server.

When the wizard completes, it displays all required environment variable values. Copy them.


Configure the application

configure-the-application page anchor

To configure the application, create a .env file in the getting_started/examples/cintel directory:

1
cd getting_started/examples/cintel
2
cp .env.example .env

Paste the setup wizard output into .env.

.env

env page anchor
1
INTELLIGENCE_CONFIG_SID=intelligence_configuration_xxx
2
WEBHOOK_BASE_URL=https://abc123.ngrok-free.app
3
4
# From Step 1:
5
MEMORY_STORE_SID=mem_store_xxx
6
7
# From Step 2:
8
CONVERSATION_CONFIGURATION_ID=conv_configuration_xxx
9
10
# Twilio credentials
11
TWILIO_ACCOUNT_SID=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
12
TWILIO_AUTH_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
13
TWILIO_API_KEY=SKxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
14
TWILIO_API_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
15
TWILIO_PHONE_NUMBER=+1xxxxxxxxxx
16
17
# Voice
18
TWILIO_TAC_VOICE_PUBLIC_DOMAIN=abc123.ngrok-free.app
19
20
# OpenAI
21
OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
22
23
# Server
24
PORT=3340
25
ENV=development

Install dependencies and run the app

install-dependencies-and-run-the-app page anchor

Install the demo application's Python dependencies, then start the local development server:

1
make install
2
make dev

Open http://localhost:3340(link takes you to an external page). You'll see a dashboard with two panels:

  • Live transcript
  • Script checkpoints

Call the phone number shown in the dashboard banner. An AI customer (GPT-4o playing a frustrated internet subscriber) will answer. Follow the Owl Internet support script:

CheckpointWhat to say
Greeting"Hi, this is [your name] calling from Owl Internet"
Identity verification"Can I get your account number to pull up your information?"
Resolution steps"Let me trigger a remote modem reset for you"
Brand-approved closing"Thank you for choosing Owl Internet. Is there anything else I can help you with?"

Watch the checkpoints turn green in real-time as you follow each step. After you hang up, the summary appears automatically in the right panel.

View results in Twilio Console

view-results-in-twilio-console page anchor

You can also view the operator results in Twilio Console.

  1. In Twilio Console(link takes you to an external page), go to Products & services > Conversation Intelligence > Intelligence configurations.
  2. Select your configuration, then open the Conversations tab.
  3. Click a conversation to view its operator results.

Example: checkpoint-update event

example-checkpoint-update-event page anchor
1
"categories": [
2
{
3
"category_key": "greeting",
4
"criteria": [
5
{
6
"criteria_key": "introduce_yourself",
7
"criteria_met": "Failed"
8
}
9
]
10
},
11
...
12
]

Example: summary-update event

example-summary-update-event page anchor
1
{
2
"summary_text": "Customer called about recurring internet disconnections. Agent followed the full support script and resolved the issue by triggering a remote modem reset.",
3
"key_points": ["Internet disconnecting every few hours", "Remote modem reset resolved issue"]
4
}

See the following common issues and resolutions.

Checkpoints not updating

checkpoints-not-updating page anchor
  1. Verify ngrok is running and TWILIO_TAC_VOICE_PUBLIC_DOMAIN in .env matches the current domain.
  2. In Twilio Console(link takes you to an external page), go to Develop > Troubleshoot > Debugger to see failed webhook deliveries to /webhook/cintel.
  3. Go to Products & services > Conversation Intelligence. Click your configuration, then click the Conversations tab to confirm operators ran.
  1. In .env, update TWILIO_TAC_VOICE_PUBLIC_DOMAIN.
  2. Re-run the setup wizard to update both the Intelligence Configuration webhook URL and the phone number voice webhook.
  3. To restart the server, run make dev.

AI customer not responding

ai-customer-not-responding page anchor
  1. In .env, verify OPENAI_API_KEY is valid (starts with sk-).
  2. Check server logs for OpenAI errors.