creamy-byte-34126
08/09/2025, 9:28 PMtall-airline-16756
08/09/2025, 9:28 PMtall-airline-16756
08/09/2025, 9:29 PMRemoteParticipant
in the inbound call agent of the caller using LiveKit in Python, here’s a friendly step-by-step guide to help you out:
1. Create a SIP Participant: When the call is accepted, use the LiveKit API to create a SIP participant. This participant will then be added to a LiveKit room.
2. Access the Room: Make sure the agent can access the room where the SIP participant is added. Usually, this is available through the job context when the agent starts up.
3. Store the RemoteParticipant: The RemoteParticipant
object gets automatically added to the room’s _remote_participants
dictionary once they join. You can grab it by listening for the participant_connected
event or directly from the room’s remote participants list.
Here’s a simple example to show you how it all fits together:
from livekit.agents import JobContext, WorkerOptions, cli
from livekit import rtc
from livekit import api
class InboundCallAgent(Agent):
def __init__(self, job_context=None):
self.job_context = job_context
super().__init__(
instructions="Handle inbound calls by storing the caller as a RemoteParticipant.",
stt=YourSTT(),
llm=YourLLM(),
tts=YourTTS(),
vad=YourVAD()
)
self.remote_participant = None
async def on_enter(self):
# Initialize the room from the job context
self.room = self.job_context.room if self.job_context else None
# Listen for participant connection events
self.room.on("participant_connected", self.on_participant_connected)
# Check existing participants
for participant in self.room.remote_participants.values():
self.on_participant_connected(participant)
def on_participant_connected(self, participant: rtc.RemoteParticipant):
# Store the RemoteParticipant
self.remote_participant = participant
# Use the participant as needed
print(f"Stored RemoteParticipant: {participant.identity}")
async def entrypoint(ctx: JobContext):
session = AgentSession()
agent = InboundCallAgent(job_context=ctx)
await session.start(agent=agent, room=ctx.room)
cli.run_app(WorkerOptions(entrypoint=entrypoint))
This snippet listens for new participants joining the room and keeps the RemoteParticipant
handy for later. If you have any questions or want to dive deeper, just let me know—I’m here to help!