Hallo, Where are the room names created? `from do...
# ask-ai
h
Hallo, Where are the room names created?
from dotenv import load_dotenv
import os
from livekit import agents
from livekit.agents import AgentSession, Agent, RoomInputOptions, ConversationItemAddedEvent
from livekit.plugins import openai, noise_cancellation
from datetime import datetime, timezone
from supabase import create_client, Client
import asyncio
load_dotenv()
# Supabase Client initialisieren
SUPABASE_URL = os.getenv("SUPABASE_URL")
SUPABASE_KEY = os.getenv("SUPABASE_KEY")
supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY)
class Assistant(Agent):
def __init__(self) -> None:
super().__init__(
instructions="You are a helpful voice AI assistant. Always respond in English only, regardless of the language the user speaks in."
)
async def entrypoint(ctx: agents.JobContext):
session = AgentSession(
llm=openai.realtime.RealtimeModel(voice="coral")
)
await session.start(
room=ctx.room,
agent=Assistant(),
room_input_options=RoomInputOptions(
noise_cancellation=noise_cancellation.BVC(),
),
)
import asyncio
async def insert_log_async(data):
await asyncio.to_thread(lambda: supabase.table("test-speech-interaction").insert(data).execute())
@session.on("conversation_item_added")
def on_conversation_item_added(event: ConversationItemAddedEvent):
ts = datetime.now(timezone.utc)
data = {
"room": ctx.room.name,
"role": event.item.role,
"message": event.item.text_content,
"interrupted": event.item.interrupted,
"ts": ts.isoformat()
}
asyncio.create_task(insert_log_async(data))
await session.generate_reply(
instructions="Greet the user and offer your assistance in English."
)
if __name__ == "__main__":
agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint))
t
Thanks for reaching out, Ju. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! Just wanted to share how room names work in LiveKit—they're created in two main ways: • Explicit creation via server API: You can set the room name yourself when you create a room using the server SDKs'
CreateRoom
method. This way, you get to customize the room settings right from the start. • Implicit creation upon participant join: If you prefer, rooms get created automatically the moment the first participant joins. The room name is included in the connection token, which also contains the participant’s identity and permissions. In your code, you’re probably passing the room name through the
ctx.room
object. This would have been set earlier on—maybe during token generation or when making API calls. Sources: Rooms, participants, and tracks | LiveKit Docs | packages/livekit-server-sdk/src/RoomServiceClient.ts | livekit-api/livekit/api/room_service.py | Connecting to LiveKit | LiveKit Docs
h
has the job contect attribute to call the 'participant'?
t
Hey there! The
JobContext
class doesn’t have a direct
participant
attribute itself. But no worries—you can still work with participants using methods like
wait_for_participant()
and
add_participant_entrypoint()
. If you’re looking to get participant details, try using these methods or check out
ctx.job.participant
if that fits your situation. Hope this helps! Sources: lib/livekit/proto/livekit_agent_pb.rb | livekit-agents/livekit/agents/job.py
h
What happens if you connect to the same room multiple times? is the coxt the same then?
t
Hey there! Just a quick heads-up about connecting to the same room multiple times in LiveKit: the context isn’t shared between connections. Each time you connect, it creates a brand new participant session, even if you’re using the same room name and participant identity. • If someone tries to join a room with an identity that’s already connected, the existing participant will be disconnected with a
DUPLICATE_IDENTITY
reason. It’s kind of like making sure there’s only one “you” in the room at a time. • If you disconnect and then reconnect, that’s totally fine! Just keep in mind that each connection starts fresh, so any tracks or subscriptions you had before won’t automatically come back—you’ll need to set those up again. This way, LiveKit keeps things running smoothly by making sure only one instance of each participant identity is in the room at once. Sources: Connecting to LiveKit | LiveKit Docs | Connecting to LiveKit | LiveKit Docs | examples/multiple_connections.py | test/singlenode_test.go