thousands-car-74964
08/26/2025, 3:25 AMtall-airline-16756
08/26/2025, 3:25 AMtall-airline-16756
08/26/2025, 3:26 AMsetMetadata() method to update the local participant’s metadata. For example, in JavaScript:
await localParticipant.setMetadata(JSON.stringify({ modalClicked: 'exampleModal' }));
• Make sure the participant’s token has the canUpdateOwnMetadata permission.
• Then, on the backend, listen for metadata changes using LiveKit’s server-side APIs or event listeners. For example, in Node.js:
room.on('participantMetadataChanged', (participant) => {
const data = JSON.parse(participant.metadata);
// Update agent context based on data.modalClicked
});
If you’re looking to send data directly to your own backend server (not just LiveKit), you can set up a separate API endpoint for that. Feel free to ask if you want me to walk you through it or if you have any other questions!
Sources: src/api/SignalClient.ts | lib/src/participant/local.dart | Runtime/Scripts/Room/Participant/LocalParticipant.cs | Managing participants | LiveKit Docs | Managing participants | LiveKit Docsthousands-car-74964
08/27/2025, 7:38 PMtall-airline-16756
08/27/2025, 7:38 PMthousands-car-74964
08/27/2025, 7:39 PMtall-airline-16756
08/27/2025, 7:39 PMasync def entrypoint(ctx: JobContext):
participant = ctx.room.local_participant
requested_agent = participant.metadata.get("agent_type", "default")
if requested_agent == "billing":
agent = BillingAgent()
elif requested_agent == "support":
agent = SupportAgent()
else:
agent = TriageAgent()
await session.start(agent=agent, room=ctx.room)
• Runtime Agent Switching: If you want to switch agents during a session, you can easily replace the active agent like this:
self.session.update_agent(NewAgent())
• Preserving Context: To keep the conversation flowing smoothly when switching agents, you can copy and trim the previous agent’s chat context like this:
chat_ctx = self.chat_ctx.copy()
chat_ctx.items = self._truncate_chat_ctx(prev_agent.chat_ctx.items, keep_last_n_messages=6)
await self.update_chat_ctx(chat_ctx)
One quick note: query parameters aren’t used directly in the backend, but you can pass them as metadata when joining a room or through a custom API call. If you’d like, I’m here to help you set that up!
Sources: Web Embed Example | livekit/livekit_composite | DeepWiki | Workflows | LiveKit Docs | complex-agents/shopify-voice-shopper/shopify.py | Accepting incoming calls | LiveKit Docsthousands-car-74964
08/27/2025, 8:35 PMtall-airline-16756
08/27/2025, 8:36 PMcreateParticipantToken! The metadata will be attached to the participant as they join the room. Here’s a friendly tip on how you can access it:
• On the backend or from other participants in the room, you can grab the metadata through the Participant.metadata field in the LiveKit SDKs. For example, in JavaScript:
const metadata = JSON.parse(participant.metadata);
console.log(metadata.scenarioId);
• Just make sure the metadata is serialized as a JSON string when you set it, like you’ve done with JSON.stringify({ scenarioId }).
If you have any questions or want a hand with accessing or using this metadata, feel free to ask—I’m here to help!
Sources: packages/livekit-server-sdk/src/AccessToken.ts | app/api/connection-details/route.ts | Participant attributes and metadata | LiveKit Docsthousands-car-74964
08/27/2025, 8:38 PMtall-airline-16756
08/27/2025, 8:38 PMRoomService client. Here’s a quick example to get you started:
• List all participants in a room:
from livekit.api import LiveKitAPI
from livekit.protocol.room import ListParticipantsRequest
async def list_room_participants(room_name: str):
async with LiveKitAPI() as api:
participants_response = await api.room.list_participants(
ListParticipantsRequest(room=room_name)
)
for participant in participants_response.participants:
print(f"Identity: {participant.identity}, Metadata: {participant.metadata}")
return participants_response.participants
• Get metadata for a specific participant:
from livekit.api import LiveKitAPI
from livekit.protocol.room import RoomParticipantIdentity
async def get_participant_data(room_name: str, identity: str):
async with LiveKitAPI() as api:
participant = await api.room.get_participant(
RoomParticipantIdentity(room=room_name, identity=identity)
)
print(f"Metadata: {participant.metadata}")
return participant
Just a heads up—make sure your environment variables for LIVEKIT_API_KEY, LIVEKIT_API_SECRET, and LIVEKIT_URL are all set up correctly. If you hit any bumps or want to dive deeper, feel free to ask. I’m here to help!
Sources: livekit-protocol/livekit/protocol/analytics.pyi | Managing participants | LiveKit Docs