You can use SIP participant attributes to create different workflows based on the caller. For example, look up customer information in a database to identify the caller.
Examples
The following examples use template apps as a starting point. If you completed the Accepting incoming calls quickstart, you can use the agent you created in Step 2: Creating an AI voice agent.
Otherwise, to create a template app, run the following LiveKit CLI command. For example, to create a voice-pipeline-agent-python
template app:
lk app create --template voice-pipeline-agent-python
You can find a full list of Public template
apps in the LiveKit examples repo.
The following example is based off the voice-pipeline-agent-python
example app. The entrypoint
function is modified to identify SIP participants.
Add the following line near the top of your
agent.py
file to import thertc
module:from livekit import rtcReplace the
entrypoint
function with the following code:async def entrypoint(ctx: JobContext):initial_ctx = llm.ChatContext().append(role="system",text=("You are a voice assistant created by LiveKit. Your interface with users will be voice. ""You should use short and concise responses, and avoiding usage of unpronouncable punctuation. ""You were created as a demo to showcase the capabilities of LiveKit's agents framework."),)logger.info(f"connecting to room {ctx.room.name}")await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)# Wait for the first participant to connectparticipant = await ctx.wait_for_participant()logger.info(f"starting voice assistant for participant {participant.identity}")# Default Deepgram modeldg_model = "nova-2-general"# Check if the participant is a SIP participantif participant.kind == rtc.ParticipantKind.PARTICIPANT_KIND_SIP:# Use a Deepgram model better suited for phone callsdb_model = "nova-2-phonecall"# Do something here based on SIP participant attributes# For example, look up customer information using their phone number# If this caller is calling from a specific phone number, do somethingif participant.attributes['sip.phoneNumber'] == '+15105550100':logger.info("Caller phone number is +1-510-555-0100")# This project is configured to use Deepgram STT, OpenAI LLM and TTS plugins# Other great providers exist like Cartesia and ElevenLabs# Learn more and pick the best one for your app:# https://docs.livekit.io/agents/pluginsassistant = VoicePipelineAgent(vad=ctx.proc.userdata["vad"],stt=deepgram.STT(model=dg_model),llm=openai.LLM(model="gpt-4o-mini"),tts=openai.TTS(),chat_ctx=initial_ctx,)assistant.start(ctx.room, participant)# The agent should be polite and greet the user when it joins :)await assistant.say("Hey, how can I help you today?", allow_interruptions=True)