i'm using python agent i want to get instruction ...
# ask-ai
p
i'm using python agent i want to get instruction from room.metadata can you help ?
t
Thanks for reaching out, Yassine. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You can access instructions from
room.metadata
in your Python agent by reading the
metadata
property of the
Room
object. Typically, metadata is stored as a JSON string, so you should parse it to extract the desired fields. Here’s a simple example:
Copy code
import json

async def entrypoint(ctx):
    await ctx.connect()
    if ctx.room.metadata:
        try:
            metadata = json.loads(ctx.room.metadata)
            instructions = metadata.get("instructions", "Default instructions")
        except json.JSONDecodeError:
            instructions = ctx.room.metadata
    else:
        instructions = "Default instructions"
    # Now you can use the instructions in your agent logic.
• Room metadata is read-only for clients; it must be set via server APIs but is accessible to all participants, including agents. • If your application updates instructions while the agent is running, you can listen for the
room_metadata_changed
event for updates. This method lets your agent retrieve and act on instructions included in
room.metadata
Sources: livekit-protocol/livekit/protocol/agent_dispatch.pyi | External data and RAG | LiveKit Docs | README.md | Room metadata | LiveKit Docs