wide-dress-57902
08/08/2025, 11:06 PMtall-airline-16756
08/08/2025, 11:06 PMtall-airline-16756
08/08/2025, 11:07 PMJobContext
through something called job metadata. You can easily access this metadata right inside the entrypoint
function using ctx.job.metadata
.
Here’s a quick example to make it clearer:
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"]
# Use the data as needed
Usually, this metadata comes as a JSON string, which you can parse to grab whatever info you need. This way, you can include any job-specific or user-specific details when you dispatch the agent. Pretty handy, right?wide-dress-57902
08/08/2025, 11:23 PMtall-airline-16756
08/08/2025, 11:23 PMwide-dress-57902
08/08/2025, 11:24 PMtall-airline-16756
08/08/2025, 11:24 PMagent_name
in Worker Options: When you register your agent, make sure to set the agent_name
in the WorkerOptions
. This will turn off automatic dispatch and give you full control over which agent gets assigned.
opts = WorkerOptions(
...,
agent_name="your-agent-name",
)
2. Create an Explicit Dispatch: Next, use the AgentDispatchService
to send your agent to the specific room you want.
lkapi = LiveKitAPI()
dispatch = await lkapi.agent_dispatch.create_dispatch(
CreateAgentDispatchRequest(
agent_name="your-agent-name",
room="your-room-name",
)
)
3. Configure Room Settings: When you create the room, include the agent in the room configuration through the access token.
at = AccessToken(...).with_room_config(
RoomConfiguration(
agents=[
RoomAgentDispatch(
agent_name="your-agent-name",
),
],
)
)
This way, only the agent you specify will be assigned to the room. If you want me to walk you through any of these steps or if something isn’t clear, just let me know—I’m happy to help!
Sources: Dispatching agents | LiveKit Docs | Agent dispatch | LiveKit Docs