wooden-postman-51252
08/25/2025, 7:08 PMlkapi = api.LiveKitAPI()
dispatch = await lkapi.agent_dispatch.create_dispatch(
api.CreateAgentDispatchRequest(
agent_name=agent_name, room=room_name, metadata=metadata
)
)
where can the metadata be accessed from after dispatch?tall-airline-16756
08/25/2025, 7:08 PMtall-airline-16756
08/25/2025, 7:10 PMCreateAgentDispatchRequest, you can access the metadata in a few handy ways:
• Right inside the Agent: The agent can grab the metadata through the JobContext as soon as it starts. Here’s a quick example:
async def entrypoint(ctx: JobContext):
logger.info(f"job metadata: {ctx.job.metadata}")
# Use the metadata for agent logic
• From the Dispatch Response: When you create the dispatch, the AgentDispatch object you get back includes the metadata.
dispatch = await lkapi.agent_dispatch.create_dispatch(
api.CreateAgentDispatchRequest(
agent_name=agent_name, room=room_name, metadata=metadata
)
)
print("created dispatch", dispatch) # Contains metadata field
• When Listing Dispatches: You can also pull the metadata by listing all dispatches for a room.
dispatches = await lkapi.agent_dispatch.list_dispatch(room_name=room_name)
for dispatch in dispatches:
print(f"Dispatch metadata: {dispatch.metadata}")
• When Getting a Specific Dispatch: And if you want, you can fetch the metadata by retrieving a specific dispatch using its ID.
Just a heads up—the metadata is a string, so it’s a good idea to use JSON if you want to pass structured data. It makes things clearer and more flexible!
Sources: examples/agent-dispatch/index.ts | protobufs/livekit_agent_dispatch.proto