Im still looking for a little help on passing some...
# ask-ai
t
Im still looking for a little help on passing some metadata to the agent to switch the prompt / ctx on. Basically different query params represent different situations that I want the agent to switch prompts on. Whats the most straightforward way to do this since I cant pass the query param to the agent and I believe some data will need to be added to the participant
t
Thanks for reaching out, Ellis. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you want to pass metadata to an agent for switching prompts or context, you can do this easily using job metadata during agent dispatch. Think of this metadata as a flexible string field where you can pack structured data (like JSON) to guide the agent’s behavior—like picking a specific prompt or context when the agent runs. Here’s how you can pass metadata: • Using the Explicit Dispatch API: Just include the
metadata
field in your dispatch request. For example:
Copy code
// Node.js Example
const dispatch = await agentDispatchClient.createDispatch(roomName, agentName, {
  metadata: '{"prompt_type": "support", "user_id": "12345"}',
});
• Using a Participant Token: You can also embed the agent dispatch setup, including metadata, right into the participant’s access token with
RoomConfiguration
. Like this:
Copy code
// Node.js Example
at.roomConfig = new RoomConfiguration({
  agents: [
    new RoomAgentDispatch({
      agentName: agentName,
      metadata: '{"department": "technical_support"}',
    }),
  ],
});
How to use metadata in your agent: Inside your agent’s
entrypoint
, just parse the metadata to decide which prompt or context fits best:
Copy code
import json

async def entrypoint(ctx: JobContext):
    metadata = json.loads(ctx.job.metadata)
    prompt_type = metadata.get("prompt_type", "default")
    
    if prompt_type == "support":
        instructions = "You are a technical support agent..."
    elif prompt_type == "billing":
        instructions = "You are a billing specialist..."
    else:
        instructions = "You are a general assistant..."

    agent = MyAgent(instructions=instructions)
    await agent.start(ctx)
This way, you get dynamic, metadata-driven routing and personalization for your agent’s prompts and workflows. If you have any questions or want me to walk you through this, just let me know—I’m happy to help! Sources: examples/agent-dispatch/index.ts | examples/agent_dispatch.py | Job lifecycle | LiveKit Docs | Workflows | LiveKit Docs | Agent dispatch | LiveKit Docs
t
can I get some human help here? not entirely following.
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!
t
im not entirely following, would I add this in my nextjs project or in the nodejs backend running the agent?