Connect your agent to phone calls with Twilio or Plivo.
The Call interface connects your agent to voice phone calls. It supports multiple telephony providers (Twilio, Plivo) and three pipeline strategies for different latency/flexibility trade-offs.
Architecture
Three pipeline modes handle the voice-to-text-to-voice conversion differently:
Mode
How It Works
Latency
Provider Lock
Managed
Twilio ConversationRelay handles STT/TTS
~500ms
Twilio only
Cascading
Your STT → Agent → Your TTS
~800-1200ms
Any provider
Realtime
OpenAI speech-to-speech (no text step)
~200-300ms
OpenAI model
Setup
Install
pip install 'definable[call]'
This installs the websockets dependency needed for real-time audio streaming.
Automatic barge-in detection (speech during playback)
~800-1200ms latency
Realtime (OpenAI)
Audio flows directly to OpenAI’s Realtime API for speech-to-speech processing. No intermediate text conversion step.
Caller speaks → Twilio/Plivo → raw audio → OpenAI Realtime API → audio → Caller hears
Lowest latency (~200-300ms)
Native function calling (tools work without text intermediary)
Server-side VAD (voice activity detection)
Locked to OpenAI Realtime models (gpt-4o-realtime-preview)
Telephony Providers
Twilio
Supports all three pipeline modes. Uses Media Streams for cascading/realtime and ConversationRelay for managed mode.
call = CallInterface( provider="twilio", account_sid="AC...", # or TWILIO_ACCOUNT_SID env var auth_token="...", # or TWILIO_AUTH_TOKEN env var phone_number="+15551234567", pipeline="managed", # or "cascading" or "realtime")
Plivo
Supports cascading and realtime modes only. Uses bidirectional Audio Streaming over WebSocket.
call = CallInterface( provider="plivo", auth_id="MA...", # or PLIVO_AUTH_ID env var auth_token="...", # or PLIVO_AUTH_TOKEN env var phone_number="+15551234567", pipeline="cascading", # or "realtime" (NOT "managed") stt=DeepgramSTT(...), tts=CartesiaTTS(...),)
Key differences from Twilio:
No managed mode (no ConversationRelay equivalent)
Supports 16kHz PCM natively (Twilio only supports 8kHz mu-law)
Uses HMAC-SHA256 V3 for webhook signatures (Twilio uses HMAC-SHA1)
STT Providers
DeepgramSTT
Real-time streaming transcription via Deepgram’s WebSocket API.
from definable.agent.interface.call.stt.deepgram import DeepgramSTTstt = DeepgramSTT( api_key="...", # or DEEPGRAM_API_KEY env var model="nova-3", # Deepgram model language="en-US", endpointing=300, # silence detection (ms) smart_format=True, # format numbers, dates, etc. utterance_end_ms=1000, # utterance boundary detection)
TTS Providers
CartesiaTTS
Ultra-low latency streaming TTS via Cartesia’s WebSocket API (40-90ms TTFB).
from definable.agent.interface.call.tts.cartesia import CartesiaTTStts = CartesiaTTS( api_key="...", # or CARTESIA_API_KEY env var model="sonic-2", voice_id="a0e99841-...", # Cartesia voice ID language="en",)
Agent with Tools
Give your phone agent capabilities:
from definable.agent import Agentfrom definable.tool.decorator import tool@tooldef check_order(order_id: str) -> str: """Look up an order by ID.""" return f"Order {order_id}: Shipped, arriving March 15."@tooldef transfer_call(department: str) -> str: """Transfer the caller to a department.""" return f"Transferring to {department}. Please hold."agent = Agent( model="openai/gpt-4o-mini", instructions=( "You are a customer service agent for Acme Corp. " "Keep responses concise — you're on a phone call." ), tools=[check_order, transfer_call],)
Deployment
CallInterface integrates with AgentRuntime, which provides a shared FastAPI server for webhooks and WebSocket connections.