millions-beach-70733
06/06/2025, 12:45 PMtall-airline-16756
06/06/2025, 12:45 PMtall-airline-16756
06/06/2025, 12:45 PMfrom livekit.api import (
AccessToken,
RoomAgentDispatch,
RoomConfiguration,
VideoGrants,
)
# Create a token to dispatch the first agent
token = (
AccessToken()
.with_identity("my_participant")
.with_grants(VideoGrants(room_join=True, room=room_name))
.with_room_config(
RoomConfiguration(
agents=[
RoomAgentDispatch(agent_name="always_connected_agent", metadata='{"type": "permanent"}')
],
),
)
.to_jwt()
)
• On-demand agent: Implement RPC methods to control when the second agent connects. For example:
@ctx.room.local_participant.register_rpc_method("connect_second_agent")
async def on_connect_second_agent(data: rtc.RpcInvocationData) -> None:
# Logic to dispatch the second agent to the room
# Example: await lkapi.agent_dispatch.create_dispatch(...)
The worker can manage multiple agent instances simultaneously in the same room, allowing for flexible session management. Let me know if you need further assistance!
Sources: Agent dispatch | LiveKit Docs | Tree View: | dse-workbench | LiveKit Agentsmillions-beach-70733
06/06/2025, 12:47 PMtall-airline-16756
06/06/2025, 12:47 PMmillions-beach-70733
06/06/2025, 1:52 PM