LiveKit Agents
In deepeval, you can run a voice simulation against a LiveKit agent. deepeval joins your agent's room as another participant and trades audio with it over WebRTC, so the agent has to be deployed and able to join a room.
Setting Up Your Credentials
A LiveKit agent has no id you can dial β it's a worker dispatched into a room. So instead of naming the agent, you give deepeval credentials for your LiveKit project and it mints a token and creates a room. DeepEval autoloads .env.local then .env at import time (process env -> .env.local -> .env).
Recommended (local dev):
# .env.local
LIVEKIT_URL=wss://your-project.livekit.cloud
LIVEKIT_API_KEY=<your-livekit-api-key>
LIVEKIT_API_SECRET=<your-livekit-api-secret>Alternative (Shell/CI):
export LIVEKIT_URL=wss://your-project.livekit.cloud
export LIVEKIT_API_KEY=<your-livekit-api-key>
export LIVEKIT_API_SECRET=<your-livekit-api-secret>Alternative (notebook):
If you're working in a notebook environment (Jupyter or Colab), set your credentials in a cell:
%env LIVEKIT_URL=wss://your-project.livekit.cloud
%env LIVEKIT_API_KEY=<your-livekit-api-key>
%env LIVEKIT_API_SECRET=<your-livekit-api-secret>In Code
Pass a LiveKitConnector to VoiceConfig, naming the agent to dispatch into the room:
from deepeval.voice import LiveKitConnector, VoiceConfig
connector = LiveKitConnector(
url="wss://your-project.livekit.cloud",
api_key="your-api-key",
api_secret="your-api-secret",
agent_name="restaurant-agent",
)
voice_config = VoiceConfig(
connector=connector,
...,
)There are ZERO mandatory and ELEVEN optional parameters when creating a LiveKitConnector.
- [Optional]
url: A string LiveKit server URL. Defaults toLIVEKIT_URL, and is required unlessroomis already connected. - [Optional]
api_key: A string LiveKit API key. Defaults toLIVEKIT_API_KEY, and is required to mint a token. - [Optional]
api_secret: A string LiveKit API secret. Defaults toLIVEKIT_API_SECRET, and is required to mint a token. - [Optional]
room: Anrtc.Roomto use instead of creating one, connected or not. Defaulted toNone. - [Optional]
token: A LiveKit access token you minted yourself, used instead ofapi_keyandapi_secret. Defaulted toNone. - [Optional]
room_name: A string naming the room to join. Defaulted toNone, which creates a room for the session. - [Optional]
identity: A string participant identity for the simulator. Defaulted to"deepeval-test". - [Optional]
agent_name: A string naming the agent to dispatch into the room. Defaulted toNone, which leaves your existing routing to place the agent there. - [Optional]
turn_detection: A string preset β"eager","balanced", or"patient"β controlling how long a pause has to last before your agent is considered finished speaking. Defaulted to"balanced". - [Optional]
connect_timeout_s: A float number of seconds to wait when establishing the room connection. Defaulted to15.0. - [Optional]
transcript_grace_s: A float number of seconds to wait after your agent stops speaking for its transcript to arrive. Defaulted to1.5.
room_name and agent_name are what actually find your agent. Omit room_name and the connector creates a room; set agent_name and LiveKit dispatches that agent into it.
Bringing Your Own Room
If your test setup already joined a room, hand that over instead and skip the credentials:
from livekit import rtc
from deepeval.voice import LiveKitConnector, VoiceConfig
room = rtc.Room()
await room.connect("wss://your-project.livekit.cloud", your_token)
voice_config = VoiceConfig(
connector=LiveKitConnector(room=room),
...,
)Concurrent conversations each get their own session, cloned from the connector you passed. A connector holding a room you connected yourself, a fixed room_name or a token (which is minted for one room) can't be cloned: every call would join the same room. The simulator stops with an error before any call starts, so give VoiceConfig a zero-argument callable that builds a fresh connector instead, or set max_concurrent=1.
deepeval publishes a microphone track, listens for the agent, and leaves the room as it found it β a room you connected stays connected afterwards, with just the simulated microphone removed. An unconnected room gets connected using the parameters above.
For how connectors fit into the simulation loop, and for turn detection in full, see Voice Connectors.
Calling a Phone Number
When your agent answers a phone line, deepeval can call it like a real caller would. A PhoneConnector with a LiveKitProvider places the call through an outbound SIP trunk on your LiveKit project, waits for your agent to pick up, and hangs up when the conversation ends:
from deepeval.voice import LiveKitProvider, PhoneConnector, VoiceConfig
voice_config = VoiceConfig(
connector=PhoneConnector(
"+14155550100",
caller_id="+14155550199",
provider=LiveKitProvider(trunk_id="ST_xxxxxxxxxxxx"),
),
...,
)PhoneConnector's own parameters, such as caller_id, ring_timeout_s and silence_timeout_s, are listed in Phone Calls. There are EIGHT optional parameters when creating a LiveKitProvider:
- [Optional]
url,api_keyandapi_secret: Strings for your LiveKit project. Default toLIVEKIT_URL,LIVEKIT_API_KEYandLIVEKIT_API_SECRET. - [Optional]
trunk_id: A string id of the outbound trunk to call through. Defaults toLIVEKIT_SIP_OUTBOUND_TRUNK_ID, and is required unlesstrunk_uriis set. - [Optional]
trunk_uri: A string SIP address of a trunk to call through without configuring it on LiveKit first, such as"sip:outbound@trunk.example.com". Defaulted toNone. - [Optional]
trunk_usernameandtrunk_password: Strings thetrunk_uritrunk authenticates with. Defaulted toNone. - [Optional]
headers: A dictionary of SIP headers sent with the call, such as{"X-Test-Case": "refund-1"}. Defaulted toNone. - [Optional]
media_encryption: ASipMediaEncryption(DISABLED,ALLOWEDorREQUIRED) deciding whether the call audio is encrypted (SRTP). Defaulted toSipMediaEncryption.DISABLED.
Phone audio carries no transcript, so every reply is transcribed with your speech-to-text model.
If the call can't be placed, the run stops with the reason, such as a busy line, no answer, or a number that can't be reached.
Calling a SIP Address
An agent reachable at a SIP address (for example a Vapi, Retell or self-hosted SIP endpoint) needs no phone number or trunk. A SIPConnector calls the address directly:
from deepeval.voice import LiveKitProvider, SIPConnector, VoiceConfig
voice_config = VoiceConfig(
connector=SIPConnector(
"sip:support@sip.example.com",
username="deepeval",
password="your-sip-password",
provider=LiveKitProvider(),
),
...,
)SIPConnector takes the same optional parameters as PhoneConnector, and LiveKitProvider the same ones except the trunk ones, plus:
sip_uri: A string SIP address such as"sip:support@sip.example.com". Add a port (sip:support@sip.example.com:5060) or a transport (;transport=tcp) when your endpoint needs them, or usesips:for TLS.- [Optional]
usernameandpassword: Strings for SIP digest authentication, when your endpoint asks for it. Defaulted toNone. - [Optional]
transport: ASipTransport(UDP,TCPorTLS) used when the address doesn't name one. Defaulted toSipTransport.UDP. - [Optional]
caller_id: A string your agent sees as the caller. Defaulted to"deepeval", because LiveKit won't place a SIP call without one.
Parallel Phone Calls
Every simulated conversation dials its own call into a room of its own, so up to max_concurrent calls run at once. Dials are spaced dial_interval_s apart across all phone and SIP connectors in the process, because carriers reject calls placed too quickly (Twilio allows one new call per second by default). Make sure your trunk allows as many concurrent calls as you run.