request = CreateSIPParticipantRequest( sip...
# ask-ai
b
request = CreateSIPParticipantRequest( sip_trunk_id=trunk_id, sip_call_to=phone_number, room_name=room_name, participant_identity="ai-agent", participant_name="AI_Agent", wait_until_answered=True, participant_metadata=metadata ) how to acess the partecipant metadata in the entrypoint function
t
Thanks for reaching out, Aman. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Could you please help me understand a bit better what you mean by "entrypoint function"? Are you thinking about a specific function in your application where you'd like to access the participant metadata, or are you asking about how to access it within LiveKit's server-side logic? I'm here to help!
b
import asyncio import os from dotenv import load_dotenv from livekit import agents from livekit.agents import AgentSession, Agent, RoomInputOptions from livekit.plugins import ( noise_cancellation, google ) # from tools import lookup_weather,send_message_to_aman load_dotenv() import time async def wait_for_file(file_path: str, timeout: int = 5): start = time.time() while not os.path.exists(file_path): await asyncio.sleep(0.2) if time.time() - start > timeout: return False return True class Assistant(Agent): def __init__(self,prompt="you are a helpful assistant") -> None: super().__init__(instructions=prompt, # tools=[lookup_weather,send_message_to_aman] ) async def entrypoint(ctx: agents.JobContext): # system_prompt=prompts.prompt2 system_prompt="your name is ravina tandon" # parts = str(ctx.room.name).split("-") # filename = "-".join(parts[:-1]) # prompt_file_path = f'{get_constant("custom_prompt_dir")}/{filename}.txt' # print("looking for file name:-",filename) # if(os.path.exists(prompt_file_path)): # print("custom prompt file exists") # with open(prompt_file_path, 'r', encoding='utf-8') as file: # system_prompt = file.read() # print("content read success",system_prompt) # else: # print("custom prompt file does not exists") session = AgentSession( # llm=openai.realtime.RealtimeModel( # voice="coral" # ) llm=google.beta.realtime.RealtimeModel( model="gemini-2.0-flash-exp", voice="Aoede", temperature=0.8, instructions="start with a greeting", ), ) print("session created") await session.start( room=ctx.room, agent=Assistant(prompt=system_prompt), room_input_options=RoomInputOptions( # LiveKit Cloud enhanced noise cancellation # - If self-hosting, omit this parameter # - For telephony applications, use
BVCTelephony
for best results noise_cancellation=noise_cancellation.BVC(), ), ) print("Room created:", ctx.room) await ctx.connect() await session.generate_reply( instructions="start with a greeting ", ) if name == "__main__": agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint,num_idle_processes=2,agent_name="AI_Agent"))
t
Hi there! To help you access participant metadata in the entrypoint function, you can easily retrieve it from a connected participant right after they join the room. The
metadata
field is a string property of a participant that can hold any data you need, and you can access it through the participant object in the agent’s
JobContext
. Here’s a simple way to do it:
Copy code
async def entrypoint(ctx: JobContext):
    # Connect to the room
    await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)

    # Wait for the first participant to join
    participant = await ctx.wait_for_participant()

    # Access participant metadata
    metadata = participant.metadata
    print(f"Participant metadata: {metadata}")

    # You can also access attributes (key-value pairs)
    language = participant.attributes.get("user.language")
    print(f"User language: {language}")
Also, if you'd like to respond when a participant’s metadata changes, you can set up an event listener like this:
Copy code
@ctx.room.on("participant_metadata_changed")
def on_metadata_changed(p: rtc.Participant, old_metadata: str, new_metadata: str):
    print(f"Participant {p.identity} metadata changed from {old_metadata} to {new_metadata}")
One more tip: you can set the initial values for
metadata
and
attributes
right in the participant’s access token. This way, they’re ready and waiting as soon as the participant joins the room. Sources: Participant attributes and metadata | LiveKit Docs | examples/primitives/participant_entrypoint.py