if i need my frontend to allow the user to choose ...
# ask-ai
b
if i need my frontend to allow the user to choose between different agents. will that require running each different agent separate on the backend?
t
Thanks for reaching out, Ibrahem. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Allowing users to choose between different agents on the frontend does not require running each agent separately on the backend in LiveKit. LiveKit supports dynamic agent switching within the same session and worker process. Here are the key approaches: • Agent Switching Within Sessions: You can dynamically switch agents during runtime using methods like
session.update_agent()
. For example, you can define multiple agent classes (e.g., ShortAgent and LongAgent) and switch between them as needed. Here's an example:
Copy code
class ShortAgent(Agent):
    @function_tool
    async def change_agent(self):
        """Change the agent to the long agent."""
        self.session.update_agent(LongAgent())

class LongAgent(Agent):
    @function_tool
    async def change_agent(self):
        """Change the agent to the short agent."""
        self.session.update_agent(ShortAgent())
• Single Worker, Multiple Agents: The LiveKit Agents framework allows a single worker to host multiple agent instances simultaneously. Each agent runs in its own process for isolation, but all agent logic can be contained within the same codebase and worker process. This enables seamless switching between agents without requiring separate backend processes for each agent type. This approach provides flexibility and efficiency, as all agent logic can be managed within a single deployable worker while dynamically creating and switching between different agent personalities or capabilities based on user interaction. Sources: Agents Overview | LiveKit Docs | complex-agents/medical_office_triage/triage.py | Anatomy of an Agent | LiveKit Docs
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!