FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-sdks/examples/agent_dispatch.py at main · livekit/python-sdks · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
livekit
/
python-sdks
Public
Notifications
You must be signed in to change notification settings
Fork
132
Star
380
Code
Issues
16
Pull requests
28
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-sdks
/
examples
/
agent_dispatch.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
76 lines (60 loc) · 2.31 KB
Breadcrumbs
python-sdks
/
examples
/
agent_dispatch.py
Copy path
File metadata and controls
76 lines (60 loc) · 2.31 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import
asyncio
from
livekit
import
api
room_name
=
"my-room"
agent_name
=
"test-agent"
"""
This example demonstrates how to have an agent join a room
without using the automatic dispatch. In order to use this
feature, you must have an agent running with `agent_name` set
when defining your WorkerOptions. A dispatch requests the
agent to enter a specific room with optional metadata.
You can also specify a `deployment` to target a specific agent deployment.
Leave empty to target the production deployment.
"""
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_metadata"
,
# deployment="staging", # Optional: target a specific deployment
)
)
print
(
"created dispatch"
,
dispatch
)
dispatches
=
await
lkapi
.
agent_dispatch
.
list_dispatch
(
room_name
=
room_name
)
print
(
f"there are
{
len
(
dispatches
)
}
dispatches in
{
room_name
}
"
)
await
lkapi
.
aclose
()
"""
When agent name is set, the agent will no longer be automatically dispatched
to new rooms. If you want that agent to be dispatched to a new room as soon as
the participant connects, you can set the RoomConfiguration with the agent
definition in the access token.
You can also specify a `deployment` in the RoomAgentDispatch to target a specific
agent deployment. Leave empty to target the production deployment.
"""
async
def
create_token_with_agent_dispatch
()
->
str
:
token
=
(
api
.
AccessToken
()
.
with_identity
(
"my_participant"
)
.
with_grants
(
api
.
VideoGrants
(
room_join
=
True
,
room
=
room_name
))
.
with_room_config
(
api
.
RoomConfiguration
(
agents
=
[
api
.
RoomAgentDispatch
(
agent_name
=
"test-agent"
,
metadata
=
"my_metadata"
,
# deployment="staging", # Optional: target a specific deployment
)
],
),
)
.
to_jwt
()
)
return
token
async
def
main
():
token
=
await
create_token_with_agent_dispatch
()
print
(
"created participant token"
,
token
)
print
(
"creating explicit dispatch"
)
await
create_explicit_dispatch
()
asyncio
.
run
(
main
())
Back
|
FazBrowse Home
|
New Git URL