cuddly-lizard-69432
03/27/2025, 4:23 AMtall-airline-16756
03/27/2025, 4:23 AMtall-airline-16756
03/27/2025, 4:23 AMagentName
when setting up the worker options: `opts = WorkerOptions(
...
agent_name="test-agent",
)`When the agent_name
is set, the agent will not be automatically dispatched to newly created rooms.
2. Use the AgentDispatchService
or AgentDispatchClient
to explicitly dispatch the agent to a room. For example, using the API client: import asyncio
from livekit import api
room_name = "my-room"
agent_name = "test-agent"
async def create_explicit_dispatch():
lkapi = api.LiveKitAPI()
dispatch = await lkapi.agent_dispatch.create_dispatch(
api.CreateAgentDispatchRequest(
agent_name=agent_name, room=room_name, metadata="my_job_metadata"
)
)
print("created dispatch", dispatch)
3. Alternatively, you can use the createDispatch
method: `createDispatch(
roomName: string,
agentName: string,
options?: CreateDispatchOptions
): Promise<agentdispatch>`This method creates an explicit dispatch for an agent to join a room and returns the dispatch that was created.
Let me know if you need further assistance!
Sources: Dispatching agents | LiveKit Docs | AgentDispatchClient | LiveKit JS Server SDK - v2.9.7cuddly-lizard-69432
03/27/2025, 4:24 AMtall-airline-16756
03/27/2025, 4:24 AMdef create_token_with_agent_dispatch() -> str:
token = (
AccessToken()
.with_identity("my_participant")
.with_grants(VideoGrants(room_join=True, room=room_name))
.with_room_config(
RoomConfiguration(
agents=[
RoomAgentDispatch(agent_name="test-agent", metadata="my_metadata")
],
),
)
.to_jwt()
)
return token
In this example, the token is configured to dispatch the agent named test-agent
with some metadata. Replace test-agent
with your specific agent name. Let me know if you need further clarification!
Sources: Dispatching agents | LiveKit Docscuddly-lizard-69432
03/27/2025, 4:24 AMtall-airline-16756
03/27/2025, 4:24 AMRoomAgentDispatch
is typically set as a string, based on available examples. While other parts of LiveKit often use JSON (stringified) for metadata, there is no explicit confirmation that JSON is supported for RoomAgentDispatch
metadata specifically.
If you’d like, you can try stringifying your JSON object and passing it as a string to see if it works. Let me know if you need further assistance!
Sources: Authentication | LiveKit Docscuddly-lizard-69432
03/27/2025, 4:25 AMtall-airline-16756
03/27/2025, 4:25 AM.with_metadata(json.dumps(metadata))
and RoomAgentDispatch
metadata. However, it seems that .with_metadata
is used to set metadata for a participant or token, while RoomAgentDispatch
metadata is specifically tied to the agent dispatch configuration.
If you have a specific use case in mind, feel free to share more details, and I’ll do my best to assist further!