How do I send data to livekit's agent, like if for...
# ask-ai
s
How do I send data to livekit's agent, like if for example I want to send the user_name to the agent. How would you normally do it?
t
Thanks for reaching out, Roman. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — you're asking how to send data (like
user_name
) to a LiveKit agent. The usual, recommended way is to include it in the job's metadata when you dispatch the agent. This makes the data available to the agent at startup. How to do it (summary): 1. Add JSON to the dispatch
metadata
field (stringified), e.g.:
Copy code
{
  "user_name": "John Doe",
  "user_id": "12345"
}
1. Dispatch with that metadata (example uses API or participant token with a RoomAgentDispatch): • API dispatch: include
metadata
on the dispatch request. • Participant token: add
RoomAgentDispatch
with
metadata
in the room config. 1. Read it inside the agent entrypoint:
Copy code
metadata = json.loads(ctx.job.metadata)
user_name = metadata["user_name"]
Alternatives: • Participant attributes (set on the participant and observed by the agent) • Room metadata (shared across participants) • In Agent Builder, reference
{{metadata.user_name}}
in prompts Best practice: use job metadata for static per-user values like
user_name
so the agent starts with that context. Would you like a code snippet for the specific SDK/language you’re using? Sources: Job lifecycle | LiveKit docs | Agent dispatch | LiveKit docs | External data and RAG | LiveKit docs | Context Variables | LiveKit docs | Agents and handoffs | LiveKit docs