bulky-wall-61623
11/01/2025, 5:37 PMtall-airline-16756
11/01/2025, 5:38 PMtall-airline-16756
11/01/2025, 5:38 PMjoined_at, which helps you calculate the duration easily.
• Manual Tracking: Another approach is to track the time yourself in your app — just note when a participant connects (using the participantConnected event) and when they disconnect (with the disconnected event), then find the difference between those times.
• Prometheus Metrics: If you have Prometheus set up, you can check out the livekit_session_duration_ms metric to get some great insights on session length.
If you’d like, I’m happy to walk you through any of these methods or answer any questions you have. Just let me know!
Sources: examples/frontdesk/calendar_api.py | Sources/LiveKit/Protos/livekit_metrics.pb.swift | lib/livekit/proto/livekit_models_pb.rb | Analytics API | LiveKit docs | LiveKit Pricingbulky-wall-61623
11/01/2025, 5:46 PMtall-airline-16756
11/01/2025, 5:47 PMstarted_at and ended_at. From there, you can easily calculate the duration.
• Manual Tracking: Another way is to keep track of the timestamps yourself—note when the session starts (for example, right after session.start()) and when it ends (like on a close event). Then, just find the difference between those times.
If you’d like, I’m happy to walk you through these methods with more details or examples. Just let me know!
Sources: LiveKit Pricing | Community & Support | livekit/livekit_composite | DeepWiki | examples/primitives/room_stats.py | Analytics API | LiveKit docsbulky-wall-61623
11/01/2025, 6:44 PMtall-airline-16756
11/01/2025, 6:44 PMctx.room.name from the onEnter method in a LiveKit agent, you can easily access the room name directly through the context object provided during the session. Here’s a simple example in JavaScript/TypeScript that might help:
class MyAgent extends voice.Agent {
async onEnter() {
// Access the room name via this.context
console.log("Room name:", this.context.room.name);
this.session.generateReply("Hello! I've joined the room.");
}
}
Just make sure that the agent session is started with the room context, like this:
session.start({ agent, room: ctx.room });
If you have any questions or would like me to provide examples in another language, please don’t hesitate to ask. I’m here to help!
Sources: agent.py | examples/voice_agents/weather_agent.py | examples/src/tool_call_disfluency.tsbulky-wall-61623
11/01/2025, 6:44 PMtall-airline-16756
11/01/2025, 6:45 PMctx.room.name in the on_enter method of your LiveKit agent using Python. Here's a simple way to do it:
from livekit import Agent, AgentSession, JobContext
class MyAgent(Agent):
def __init__(self, ctx: JobContext):
super().__init__(
instructions="You are a helpful assistant."
)
self.ctx = ctx
async def on_enter(self):
room_name = self.ctx.room.name
print(f"Agent entered room: {room_name}")
# Perform any room-specific initialization
async def entrypoint(ctx: JobContext):
agent = MyAgent(ctx)
session = AgentSession()
await session.start(agent=agent, room=ctx.room)
This way, ctx.room.name is nicely accessible within the on_enter method. If you have any questions or need a bit more help, just let me know—I’m here for you!
Sources: examples/avatar_agents/audio_wave/README.md