how the agent gets meta data from room?
# ask-ai
h
how the agent gets meta data from room?
t
Thanks for reaching out, YUNYI. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You can get metadata from a room in LiveKit using the following methods: • Using the LiveKit SDKs, you can access room metadata through the
Metadata()
function on the Room object. For example, in the Go SDK, the Room struct has a method:`func (r *Room) Metadata() string` • To receive updates when room metadata changes, you can handle the
RoomMetadataChanged
event. This allows your application to be notified when the metadata is updated. Please note that while all participants can access room metadata, it can only be set using server APIs, specifically the CreateRoom and UpdateRoomMetadata APIs. Sources: lksdk package - github.com/livekit/server-sdk-go/v2 - Go Packages | Room metadata | LiveKit Docs | Room metadata | LiveKit Docs
h
can I get metadata by this: ctx.job.metadata
t
Yes, metadata is super easy to work with in LiveKit! Think of ctx.job.metadata like a little package of custom info you can send along with your job. It's basically a flexible way to pass extra details that your job might need. Here's a friendly example of how you might use it:
Copy code
import json

async def entrypoint(ctx: JobContext):
    metadata = json.loads(ctx.job.metadata)
    user_id = metadata["user_id"]
    user_name = metadata["user_name"]
    user_phone = metadata["user_phone"]
    # ...
Pro tip: I recommend using JSON to structure your metadata. It's a great way to include user information, specific job parameters, or any other custom data you want your agent to know about. Pretty cool, right? 😊 This approach gives you tons of flexibility in how you pass information around. Sources: Job lifecycle | LiveKit Docs
h
can I send job metadata from frontend?
t
Hey there! Let me break down how job metadata works in a super friendly way. 😊 When you're dispatching an agent, you can actually include some extra details through a metadata field – think of it like adding a little note to give more context. Here's a quick example of what that looks like in code:
Copy code
await lkapi.agent_dispatch.create_dispatch(
    api.CreateAgentDispatchRequest(
        agent_name=agent_name, room=room_name, metadata='{"user_id": "12345"}'
    )
)
Cool thing is, this metadata gets picked up right in the job's entrypoint. While the documentation doesn't specifically call out frontend applications sending metadata, it's totally doable if your frontend is set up to make these API calls. Pretty neat, right? šŸ‘ Just wanted to make sure you know all the flexible ways you can pass along extra information when you're working with dispatches! Sources: Job lifecycle | LiveKit Docs | Agent dispatch | LiveKit Docs