livekit move a participant from one room to anothe...
# ask-ai
p
livekit move a participant from one room to another using api - can u provide end to end example
t
Thanks for reaching out, mithun. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hi there! If you're looking to move a participant from one room to another using the LiveKit API, you can do so with the
MoveParticipant
API. Just a quick heads-up: this feature is available in LiveKit Cloud or Private Cloud deployments and you'll need
roomAdmin
privileges to make it happen. Here’s a friendly, step-by-step example in Python to guide you through:
Copy code
from livekit.api import LiveKitAPI, MoveParticipantRequest
import asyncio

async def move_participant_safely():
    async with LiveKitAPI() as lkapi:
        source_room = "current-room-name"
        destination_room = "new-room-name"
        participant_identity = "user-123"

        try:
            # First, let's check if the source room exists and get its participants
            rooms = await lkapi.room.list_rooms()
            room_names = [room.name for room in rooms.rooms]
            if source_room not in room_names:
                print(f"Source room {source_room} does not exist.")
                return

            # Next, confirm the participant is actually in the source room
            participants = await lkapi.room.list_participants(
                MoveParticipantRequest(room=source_room)
            )
            participant_ids = [p.identity for p in participants.participants]
            if participant_identity not in participant_ids:
                print(f"Participant {participant_identity} not found in {source_room}.")
                return

            # Now, let's move the participant to the new room
            await lkapi.room.move_participant(
                MoveParticipantRequest(
                    room=source_room,
                    identity=participant_identity,
                    destination_room=destination_room,
                )
            )
            print(f"Successfully moved participant {participant_identity} from {source_room} to {destination_room}.")

        except Exception as e:
            print(f"Failed to move participant: {e}")
To make sure everything goes smoothly, please check that: • Both the source and destination rooms exist. • The participant is currently connected to the source room. • Your API key has
roomAdmin
privileges for both rooms. If you'd like to explore more examples or details in other programming languages, feel free to visit the LiveKit documentation. We're here to help you every step of the way! Sources: Agent-assisted warm transfer | LiveKit Docs | examples/warm-transfer/README.md | livekit-api/livekit/api/room_service.py | Managing participants | LiveKit docs | packages/livekit-server-sdk/src/RoomServiceClient.ts
p
what are the other options available in self hosted version
t
Thank you for reaching out! I wanted to share that the self-hosted version of LiveKit doesn’t currently support the
MoveParticipant
or
ForwardParticipant
APIs, as these are available exclusively with LiveKit Cloud and Private Cloud deployments. But don’t worry—you can still achieve similar results in self-hosted setups with a bit of custom work: • Graceful Exit and Rejoin: You can use the
RemoveParticipant
API to gently disconnect the participant from their current room, then guide the client to join a new room by creating a new access token for that destination. • Track Replication: Another option is to subscribe to the participant’s tracks in the original room, relay those media streams through an intermediary service, and then publish them into the target room. • Agent-Assisted Coordination: You might consider deploying self-hosted agents that keep an eye on room states and help automate the process—removing participants from one room and helping them join another smoothly. These methods do require a bit more setup and infrastructure compared to the built-in
MoveParticipant
feature. If having seamless participant migration is really important for your use case, it might be worth exploring LiveKit Cloud or Private Cloud options, where this functionality is fully supported. Sources: Managing participants | LiveKit docs | livekit-api/livekit/api/room_service.py | Agent-assisted warm transfer | LiveKit Docs | LiveKit Pricing
p
is it possible to keep the participant in two room and publish the track to a particular room
t
Absolutely, you can keep a participant in one room and still share their tracks with another room using the
ForwardParticipant
API. This is a great way to let the participant stay connected to their original room while their audio, video, or data tracks are forwarded to one or more other rooms. Here are some important points to keep in mind: • The participant remains in their original room, and their tracks are duplicated in the destination room(s). • The forwarding will keep going until the participant leaves the original room or is removed from the destination room. • You can forward a participant to multiple rooms at the same time. • If the destination room doesn’t exist yet, it will be created automatically. This feature is really handy for cases like broadcasting a speaker to several audience rooms or linking participants across different sessions. Just a quick note: this is different from
MoveParticipant
, which completely moves the participant to another room. If you’d like, I’m happy to provide more details or some examples to help you get started with this. Just let me know! Sources: protobufs/livekit_room.proto | packages/livekit-server-sdk/README.md | cmd/lk/room.go | livekit-ffi/src/server/requests.rs
p
yes. can this be used for the original usecase I mentioned ?
t
Thanks for reaching out! The
ForwardParticipant
API can help with your original goal of moving a participant from one room to another, but it works a bit differently than the
MoveParticipant
API. Instead of fully transferring the participant, it forwards their tracks to the new room while they stay connected to the original one. If you’re aiming for the participant to be active in both rooms at the same time or want to broadcast their media to another room, this method is a great fit. On the other hand, if you want the participant to leave the first room and join the new one seamlessly, then the
MoveParticipant
API (available in LiveKit Cloud or Private Cloud) would be the best choice. Please feel free to reach out if you’d like me to explain anything further or help you get started with either option—I’m here to help!
p
I want the participants to be in a common room - where one person can talk at time - this is the walkie-talkie room - where message published is heard by everyone. But each individual participant also should be able to switch to 1-1 conversation with the agent
t
I'd love to help you set up a walkie-talkie room where participants can easily switch to 1-1 conversations with an agent. It’s a great way to keep communication smooth and flexible! Here’s a friendly guide on how you can make this happen: Walkie-Talkie Mode: • Implement push-to-talk functionality so only one person can speak at a time. This works by enabling or disabling audio input dynamically depending on who’s talking. • Participants simply press a button to talk, and their voice is shared with everyone in the room. 1-1 Conversations: • You can use the
RoomIO.set_participant
method to focus the agent’s audio input/output on a specific participant, creating a private 1-1 channel within the shared space. • When you want to switch back to the group walkie-talkie mode, just unset that participant to return to the group setting. State Management: • It’s helpful to keep track of the current mode (like walkie-talkie, 1-1, or on-hold) using a session manager, so transitions feel seamless. • To make the experience even nicer, you might want to play hold music during those transitions. Additional Features: • If you need agent-to-agent communication or want to escalate to a supervisor, you can set up the agent to listen to other agents or integrate SIP for external calls. • LiveKit’s APIs are super handy for managing participants and rooms dynamically as your needs change. This setup gives you a flexible and user-friendly communication system that supports both group chats and private conversations. If you’d like, I’m here to provide more details or even some code examples to help you get started! Sources: Making outbound calls | LiveKit Docs | README.md | Turn detection and interruptions | LiveKit Docs | How to Enable Agent-to-Agent Speech Detection in LiveKit | Operational Guidance & Best Practices | livekit/livekit_composite | DeepWik...
p
1-1 Conversations: • You can use the
RoomIO.set_participant
method to focus the agent’s audio input/output on a specific participant, creating a private 1-1 channel within the shared space. • When you want to switch back to the group walkie-talkie mode, just unset that participant to return to the group setting. -- can u expalin with an example. also provide relevant documentaiton
t
Here’s a friendly example of how you can use the
RoomIO.set_participant
method to enable 1-1 conversations in LiveKit:
Copy code
async def entrypoint(ctx: JobContext):
    session = AgentSession(llm=openai.realtime.RealtimeModel())
    room_io = RoomIO(session, room=ctx.room)
    await room_io.start()
    await session.start(agent=MyAgent())

    # RPC method to set the participant dynamically
    @ctx.room.local_participant.register_rpc_method("set_participant")
    async def on_set_participant(data: rtc.RpcInvocationData) -> None:
        target_identity = data.payload or data.caller_identity
        room_io.set_participant(target_identity)  # Direct the agent to process this participant's audio
In this example: • The agent starts without focusing on any particular participant. • When the client calls the
set_participant
RPC method, the agent will then process audio only from the participant you specify. • This approach is especially handy for situations like push-to-talk or role-based interactions, where you want to hear just one user at a time. If you want to switch back to group mode, you can simply use:
Copy code
room_io.unset_participant()
For more details, feel free to check out the LiveKit Agents GitHub repository and examples such as
toggle_io.py
and
push_to_talk.py
. If you have any questions or need more examples, just let me know—I’m here to help! Sources: examples/voice_agents/push_to_talk.py | How to set a fixed participant for agent audio processing
p
how would it work from a mobile device. I am in a common room now.. I want to talk to the voice agent assistant on click of a button. once the conversation is done - I want to hear conversations from common room
t
I'd be happy to guide you through implementing the switch between a common room and a voice agent assistant on a mobile device. Here’s a step-by-step approach that should help: 1. Connect to the Room: • Start by using the LiveKit mobile SDK to connect to the room using your token and server URL. • Make sure to enable the microphone for the participant right when they connect, so everything runs smoothly. 2. Detect and Manage Agent Connection: • Keep an eye on whether the voice agent is connected to the room. If they’re not, it’s a good idea to either disconnect or gently notify the user. • You can use a timer or an event listener to monitor the agent’s presence, which helps keep things responsive. 3. Switch Between Modes: • When you want to start a 1-1 conversation, the
RoomIO.set_participant
method is your friend—it focuses the agent’s input/output on the chosen participant. • Once the conversation wraps up, just call
RoomIO.unset_participant
to smoothly return to the common room mode. 4. UI Controls: • It’s helpful to provide buttons so users can easily toggle between the common room and agent interaction. • For example, a "Talk to Agent" button can trigger
set_participant
, and an "End Conversation" button can trigger
unset_participant
. Example:
Copy code
async def entrypoint(ctx: JobContext):
    session = AgentSession(llm=openai.realtime.RealtimeModel())
    room_io = RoomIO(session, room=ctx.room)
    await room_io.start()

    @ctx.room.local_participant.register_rpc_method("set_participant")
    async def on_set_participant(data: rtc.RpcInvocationData):
        target_identity = data.payload or data.caller_identity
        room_io.set_participant(target_identity)

    @ctx.room.local_participant.register_rpc_method("unset_participant")
    async def on_unset_participant(data: rtc.RpcInvocationData):
        room_io.unset_participant()
If you’d like, I’m here to help with more details or specific examples for platforms like iOS, Android, Flutter, or React Native—just let me know! Sources: Mobile SDKs (Flutter, iOS, Android) | livekit/livekit_composite | DeepWiki | VoiceAgent/App/AppViewModel.swift | lib/controllers/app_ctrl.dart | app/assistant/index.tsx | Voice Assistant Applications | livekit/livekit_composite | DeepWiki
p
is the agent shared between all participants ? or every user talks to his own instance of the agent
t
Thanks for reaching out! Whether the voice agent is shared among all participants or dedicated to each user really depends on how you set it up: • Shared Agent: When the agent is set up with
WorkerType.ROOM
, it means one agent instance is shared by everyone in the room. This is great for group conversations where all participants interact with the same agent together. • Dedicated Agent: On the other hand, if you configure the agent with
WorkerType.PUBLISHER
, each participant who publishes audio or video gets their own dedicated agent. This way, each user enjoys a more personalized and private interaction. For smooth performance, each agent session runs in its own process. You can also customize how the agent behaves using tools like
RoomIO
, which lets you decide who the agent listens to or responds to. If you'd like, I’m here to help you set this up exactly how you need it. Just let me know! Sources: Worker options | LiveKit Docs | Job lifecycle | LiveKit Docs | Building voice agents | LiveKit Docs | pipeline-tts/tts_comparison/README.md
p
yes. I want the user to talk to dedicated instance of the agent.. also when user switches from talk to agent to room to agent again - will agent loose context
t
When you chat with a dedicated instance of the agent in LiveKit, it’s designed to keep track of the conversation throughout your session. The agent stores the conversation history in its
ChatContext
, so even if you switch between talking to the agent and the room, then come back to the agent, it will remember everything from before. The agent’s state—whether it’s listening, thinking, or speaking—is managed smoothly, so switching between these modes won’t make it lose any context. If you’d like, I’m here to help with more details or guide you through setting this up! Sources: Web and mobile frontends | LiveKit Docs | main.py | agents/src/voice/agent_session.ts | pipeline-tts/tts_comparison/README.md
p
ok. does this approach have any performance implications ?
t
Using dedicated agent instances in LiveKit for each user comes with some important performance considerations that I'd love to walk you through: • Resource Requirements: Each agent instance does require a fair amount of resources—about 4 CPU cores and 8GB of RAM per worker. Typically, one worker can manage 10-25 concurrent agent jobs depending on the workload. • Cold Starts: If you're on a free or limited plan, agents might scale down to zero when they're not active, which can cause a slight delay (cold start) when a new user connects. Upgrading to a paid plan helps keep agents “warm” and ready to go, avoiding that wait time. • Infrastructure Impact: When using burstable cloud instances like AWS t3 or t4g, there’s a chance of CPU throttling under heavy load, which might slow down agent responses. For smoother and more consistent performance, non-burstable instances such as m5 or c5 are a great choice. • Scaling: LiveKit does support elastic scaling to handle traffic spikes, but because agents are resource-intensive, there’s a limit to how many can run on a single machine. • Load Balancing: Stateful load balancing helps by placing agents smartly based on CPU, memory, and network conditions, so your interactions stay quick and high-quality. Best Practices: • Opt for non-burstable instances for your production workloads to keep things steady. • Set resource limits if you’re using container orchestration platforms like Kubernetes. • If you’re on a paid LiveKit Cloud tier, take advantage of auto-warm agents to avoid cold starts altogether. • Keep an eye on CPU credit balances if you’re using burstable instances to prevent unexpected slowdowns. If you’d like, I’m here to help with any further details or assist you in optimizing performance for your specific use case. Just let me know! Sources: Deploying to custom environments | LiveKit Docs | kubernetes/agent-manifest.yaml | Deploying to production | LiveKit Docs | Deploy and scale agents on LiveKit Cloud | Troubleshooting Latency and Timeout Errors with Turn Detection on AWS
p
the above can be implemented in selfhosted opensource version also ?
t
Absolutely! You can definitely implement dedicated agent instances and their functionality in the self-hosted open-source version of LiveKit. The LiveKit Agents framework, which enables real-time programmable participants, is completely open source and ready to be deployed on your own infrastructure. With the self-hosted version, you’ll be able to: • Deploy agents easily using the LiveKit CLI with commands like
lk agent init
,
lk agent create
, and
lk agent deploy
. • Tailor your agent deployments by integrating your own AI providers or plugins to fit your needs. • Allow agents to connect to LiveKit rooms, manage room events, and interact with participants through RPCs and data APIs. This way, you can enjoy the same great functionality as the cloud version, including dedicated agent instances for each user. If you’d like, I’m here to help guide you through the setup process—just let me know! Sources: livekit/livekit_composite | DeepWiki | livekit/livekit_composite | DeepWiki | Voice AI quickstart | LiveKit docs | test/agent_test.go | LiveKit Pricing
p
can you create a summary of the final approach we discussed ? also provide any relevant links
t
Here’s a friendly summary of the final approach we talked about for setting up a walkie-talkie room with 1-1 agent interactions: 1. Walkie-Talkie Room: • Participants join a shared room where only one person can speak at a time using push-to-talk functionality. • Audio input is dynamically enabled or disabled based on user actions to create that classic walkie-talkie feel. 2. 1-1 Agent Interactions: • Each user gets their own dedicated voice agent instance, so conversations stay personal and private. • Use the
RoomIO.set_participant
method to direct the agent’s input/output to a specific participant for those one-on-one chats. • When the conversation wraps up, simply use
RoomIO.unset_participant
to switch back to the shared room mode. 3. Context Retention: • The agent keeps track of the conversation history using
ChatContext
, so no context is lost when moving between the shared room and private interactions. 4. Performance Considerations: • Each agent instance needs solid resources (4 CPU cores, 8GB RAM per worker) to run smoothly. • We recommend using non-burstable cloud instances like AWS m5 or c5 to avoid throttling and keep performance steady. • Take advantage of LiveKit’s autoscaling and warm-instance features to manage traffic spikes and keep latency low. 5. Self-Hosted Implementation: • You can implement this approach with the self-hosted open-source version of LiveKit using the Agents framework. • Deploy agents through the LiveKit CLI and customize them to work with your AI providers or plugins. Relevant Links: • LiveKit Agents GitHub Repository • LiveKit Documentation • LiveKit Open Source Repository If you have any questions or need more details, please don’t hesitate to reach out—I’m here to help!