when dispatching an agent this way: ```lkapi = api...
# ask-ai
w
when dispatching an agent this way:
Copy code
lkapi = 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?
t
Thanks for reaching out, Spencer. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! Once you’ve dispatched an agent using the LiveKit API and
CreateAgentDispatchRequest
, 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:
Copy code
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.
Copy code
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.
Copy code
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
👍 1