A basic example of a voice agent using LiveKit and Python. Has a few extras to get started:
Run the following commands to:
- clone the repository
- change directory to
livekit-outbound-caller-agent - create a virtual environment and activate it
- install dependencies
- download files
git clone https://github.com/kylecampbell/livekit-outbound-caller-agent.git
cd livekit-outbound-caller-agent
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
python3 agent.py download-filesWindows instructions (click to expand)
:: Windows (CMD/PowerShell)
cd livekit-outbound-caller-agent
python3 -m venv venv
venv\Scripts\activate
pip install -r requirements.txtSet up the environment by copying .env.example to .env.local and filling in the required values:
LIVEKIT_URLLIVEKIT_API_KEYLIVEKIT_API_SECRETOPENAI_API_KEYDEEPGRAM_API_KEYSIP_OUTBOUND_TRUNK_ID(obtained from directions below)
You can also do this automatically using the LiveKit CLI:
lk app envRun the agent:
python3 agent.py devNow, your worker is running, and waiting for dispatches in order to make outbound calls.
- Create a Twilio account
- Get a Twilio phone number
- Create a SIP trunk
- In Twilio console go to Explore products > Elastic SIP Trunking > SIP Trunks > Get started > Create a SIP Trunk, name it, then Save.
- Configure SIP Termination
- Go to Termination, enter a Termination SIP URI, select the plus icon for Credentials Lists, enter a friendly name, username, and password.
- Using the outbound-trunk-example.json file, copy and rename to outbound-trunk.json and update it with your SIP provider's credentials. Do not push this file to a public repo.
name: Can be anythingaddress: Your SIP provider's outbound trunk address you created in previous stepTermination SIP URInumbers: Your Twilio phone number you want to call fromauth_username: Your username created in previous step in Twilio console.auth_password: Your password created in previous step in Twilio console.
- Run LiveKit CLI command to create the trunk:
lk sip outbound create outbound-trunk.json- Copy the
SIPTrunkIDreturned in the response and add it to the.env.localfile asSIP_OUTBOUND_TRUNK_ID.
You should now be able to make a call by dispatching an agent...
Open a new terminal while your agent is running. You can dispatch the agent to make a call by using the lk CLI (replace with number you want to call):
lk dispatch create \
--new-room \
--agent-name outbound-caller \
--metadata '+1234567890'lk project listlk sip outbound listlk sip dispatch list