agents
agents copied to clipboard
Allowing user to select one of the many connected agents
I have a Livekit server deployed to which there are 3 different LiveKit agents connected. I want a way to allow user to specify which one of those 3 to be connected to. I tried following:
- The agent can have request_fnc defined in which it can decide if the agent wants to handle the request or not. I tried this, but the method is not getting called. Then found that it's a known issue mentioned at https://docs.livekit.io/agents/build/anatomy/ so this approach does not work.
- The agent can provide an agent name while registering itself with the livekit server as part of WorkerOptions. I did that but then the agent is not called at all even if the user joins a room. Also for this approach, I could not find any way to send the agent name from the client side. Without providing agent name the agent gets called fine.
I would appreciate any suggestions or ideas to achieve the desired result. Thank you.
@meetakshay99 we just made our own API that connects the agents instead of using the livekit job scheduling to accomplish this. You can manually connect to the room and manually create an agent in a python function.
I have multiple agents manually created and being used. But how do I "connect" to an agent? Can you pls share more details on what and how was it exactly done?
I have multiple agents manually created and being used. But how do I "connect" to an agent? Can you pls share more details on what and how was it exactly done?
https://docs.livekit.io/home/get-started/api-primitives/
https://docs.livekit.io/home/client/connect/
https://docs.livekit.io/home/get-started/api-primitives/
https://docs.livekit.io/home/client/connect/
That connects with the room. I am already doing that. However, it does not allow me to specify which agent to connect to, which is what I am looking for.
I have multiple agents manually created and being used. But how do I "connect" to an agent? Can you pls share more details on what and how was it exactly done?
Let's say you have a http service somewhere:
At a high level:
will connect it to a room that you've created:
utils.http_context._new_session_ctx()
try:
room_options = rtc.RoomOptions()
room = rtc.Room()
url = os.getenv('LIVEKIT_URL')
api_key = os.getenv('LIVEKIT_API_KEY')
api_secret = os.getenv('LIVEKIT_API_SECRET')
token = api.AccessToken(api_key=api_key, api_secret=api_secret) \
.with_identity(os.getenv('AGENT_IDENTITY')) \
.with_name("Your agent name") \
.with_kind("agent") \
.with_grants(api.VideoGrants(
can_update_own_metadata=True,
room_join=True,
room=room_name,
agent=True
))
jwt = token.to_jwt()
await room.connect(url=url, token=jwt, options=room_options)
assistant = // initialize your agent
assistant.start(room)
await some_close_condition_you_decide
await assistant.aclose()
await room.disconnect()
finally:
await utils.http_context._close_http_ctx()
That's the basic idea. That will work with a simple aiohttp server to spawn the agent to get started.
this has been implemented as explicit dispatches