55agent_name = "test-agent"
66
77"""
8- This example demonstrates how to have an agent join a room
9- without using the automatic dispatch. In order to use this
10- feature, you must have an agent running with `agent_name` set
11- when defining your WorkerOptions. A dispatch requests the
8+ This example demonstrates how to have an agent join a room
9+ without using the automatic dispatch. In order to use this
10+ feature, you must have an agent running with `agent_name` set
11+ when defining your WorkerOptions. A dispatch requests the
1212agent to enter a specific room with optional metadata.
13+
14+ You can also specify a `deployment` to target a specific agent deployment.
15+ Leave empty to target the production deployment.
1316"""
1417
1518
1619async def create_explicit_dispatch ():
1720 lkapi = api .LiveKitAPI ()
1821
22+ # Create a dispatch targeting the production deployment (default)
1923 dispatch = await lkapi .agent_dispatch .create_dispatch (
2024 api .CreateAgentDispatchRequest (
2125 agent_name = agent_name , room = room_name , metadata = "my_metadata"
2226 )
2327 )
2428 print ("created dispatch" , dispatch )
2529
30+ # Create a dispatch targeting a specific deployment (e.g., "staging")
31+ # dispatch = await lkapi.agent_dispatch.create_dispatch(
32+ # api.CreateAgentDispatchRequest(
33+ # agent_name=agent_name,
34+ # room=room_name,
35+ # metadata="my_metadata",
36+ # deployment="staging",
37+ # )
38+ # )
39+
2640 dispatches = await lkapi .agent_dispatch .list_dispatch (room_name = room_name )
2741 print (f"there are { len (dispatches )} dispatches in { room_name } " )
2842 await lkapi .aclose ()
@@ -33,6 +47,9 @@ async def create_explicit_dispatch():
3347to new rooms. If you want that agent to be dispatched to a new room as soon as
3448the participant connects, you can set the RoomConfiguration with the agent
3549definition in the access token.
50+
51+ You can also specify a `deployment` in the RoomAgentDispatch to target a specific
52+ agent deployment. Leave empty to target the production deployment.
3653"""
3754
3855
@@ -43,7 +60,13 @@ async def create_token_with_agent_dispatch() -> str:
4360 .with_grants (api .VideoGrants (room_join = True , room = room_name ))
4461 .with_room_config (
4562 api .RoomConfiguration (
46- agents = [api .RoomAgentDispatch (agent_name = "test-agent" , metadata = "my_metadata" )],
63+ agents = [
64+ api .RoomAgentDispatch (
65+ agent_name = "test-agent" ,
66+ metadata = "my_metadata" ,
67+ # deployment="staging", # Optional: target a specific deployment
68+ )
69+ ],
4770 ),
4871 )
4972 .to_jwt ()
0 commit comments