I’m creating a room in the backend using the LiveK...
# ask-ai
g
I’m creating a room in the backend using the LiveKit SDK and adding metadata to it. The backend then returns the room details and token in the API response. On the frontend, I use the token to connect to the room, which works fine. However, when the agent connects through the Agent SDK, the room’s metadata is missing — even though I’ve confirmed that the room does contain the metadata. When I try to access it using ctx.room.metadata, it returns empty or undefined.
t
Thanks for reaching out, BHAVESH. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm here to help you understand why the room metadata might be missing when accessed through the Agent SDK. There are a few common reasons this can happen, so let's walk through them together: • Metadata Initialization: It's important to make sure the metadata is explicitly set when the room is created using the
CreateRoom
API, or updated later with the
UpdateRoomMetadata
API. If it was never set or left as an empty string, it will understandably show up as missing. • Agent Initialization: Sometimes, during the agent's initialization, the metadata might not be populated yet. It’s a good idea for the agent to check if the metadata exists before trying to access it and gracefully handle situations where it’s not available right away. • Server-Side Updates: Remember, only server-side components that have access to the LiveKit API key and secret can update the room metadata. Double-check that the server logic responsible for setting this metadata is running correctly. • Listening for Updates: The agent should also be set up to listen for
RoomMetadataChanged
events. This way, it can stay updated whenever the metadata changes. To sum up, please verify that the metadata is being properly set and updated on the server side, and that your agent is handling and listening for these metadata updates as expected. If you have any questions or need further assistance, I’m here to help! Sources: agent/game_host.py | Room metadata | LiveKit Docs | State synchronization