Skip to content

Commit bb53150

Browse files
fix agent dispatch example imports (#322)
1 parent a07e5eb commit bb53150

File tree

1 file changed

+21
-30
lines changed

1 file changed

+21
-30
lines changed

examples/agent_dispatch.py

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
import asyncio
2-
import os
3-
import aiohttp
4-
from livekit.protocol.room import RoomConfiguration
5-
from livekit.protocol.agent_dispatch import (
6-
RoomAgentDispatch,
7-
CreateAgentDispatchRequest,
8-
)
9-
from livekit.api import AccessToken, VideoGrants
10-
from livekit.api.agent_dispatch_service import AgentDispatchService
11-
2+
from livekit import api
123

134
room_name = "my-room"
145
agent_name = "test-agent"
@@ -22,20 +13,19 @@
2213
"""
2314

2415

25-
async def create_explicit_dispatch(http_session: aiohttp.ClientSession):
26-
agent_dispatch_service = AgentDispatchService(
27-
session=http_session,
28-
url=os.getenv("LIVEKIT_URL"),
29-
api_key=os.getenv("LIVEKIT_API_KEY"),
30-
api_secret=os.getenv("LIVEKIT_API_SECRET"),
31-
)
32-
dispatch_request = CreateAgentDispatchRequest(
33-
agent_name=agent_name, room=room_name, metadata="my_metadata"
16+
async def create_explicit_dispatch():
17+
lkapi = api.LiveKitAPI()
18+
19+
dispatch = await lkapi.agent_dispatch.create_dispatch(
20+
api.CreateAgentDispatchRequest(
21+
agent_name=agent_name, room=room_name, metadata="my_metadata"
22+
)
3423
)
35-
dispatch = await agent_dispatch_service.create_dispatch(dispatch_request)
3624
print("created dispatch", dispatch)
37-
dispatches = await agent_dispatch_service.list_dispatch(room_name=room_name)
25+
26+
dispatches = await lkapi.agent_dispatch.list_dispatch(room_name=room_name)
3827
print(f"there are {len(dispatches)} dispatches in {room_name}")
28+
await lkapi.aclose()
3929

4030

4131
"""
@@ -48,13 +38,15 @@ async def create_explicit_dispatch(http_session: aiohttp.ClientSession):
4838

4939
async def create_token_with_agent_dispatch() -> str:
5040
token = (
51-
AccessToken()
41+
api.AccessToken()
5242
.with_identity("my_participant")
53-
.with_grants(VideoGrants(room_join=True, room=room_name))
43+
.with_grants(api.VideoGrants(room_join=True, room=room_name))
5444
.with_room_config(
55-
RoomConfiguration(
45+
api.RoomConfiguration(
5646
agents=[
57-
RoomAgentDispatch(agent_name="test-agent", metadata="my_metadata")
47+
api.RoomAgentDispatch(
48+
agent_name="test-agent", metadata="my_metadata"
49+
)
5850
],
5951
),
6052
)
@@ -64,11 +56,10 @@ async def create_token_with_agent_dispatch() -> str:
6456

6557

6658
async def main():
67-
async with aiohttp.ClientSession() as http_session:
68-
token = await create_token_with_agent_dispatch()
69-
print("created participant token", token)
70-
print("creating explicit dispatch")
71-
await create_explicit_dispatch(http_session)
59+
token = await create_token_with_agent_dispatch()
60+
print("created participant token", token)
61+
print("creating explicit dispatch")
62+
await create_explicit_dispatch()
7263

7364

7465
asyncio.run(main())

0 commit comments

Comments
 (0)