Skip to content

Commit 8032d30

Browse files
docs: add deployment field documentation for agent dispatch
Update docstrings and examples to document the deployment field for agent dispatch. The deployment field allows targeting a specific agent deployment (e.g., "staging"). Leave empty to target the production deployment. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent b279ae8 commit 8032d30

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

examples/agent_dispatch.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,38 @@
55
agent_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
1212
agent 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

1619
async 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():
3347
to new rooms. If you want that agent to be dispatched to a new room as soon as
3448
the participant connects, you can set the RoomConfiguration with the agent
3549
definition 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()

livekit-api/livekit/api/agent_dispatch_service.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ async def create_dispatch(self, req: CreateAgentDispatchRequest) -> AgentDispatc
3535
To use explicit dispatch, your agent must be registered with an `agentName`.
3636
3737
Args:
38-
req (CreateAgentDispatchRequest): Request containing dispatch creation parameters
38+
req (CreateAgentDispatchRequest): Request containing dispatch creation parameters.
39+
The request can include an optional `deployment` field to target a specific
40+
deployment. Leave empty to target the production deployment.
3941
4042
Returns:
4143
AgentDispatch: The created agent dispatch object

0 commit comments

Comments
 (0)