does livekit-agents support multi agent? if so sho...
# ask-ai
p
does livekit-agents support multi agent? if so show me a simple code of how i handoff from on agent to another
t
Thanks for reaching out, Yasser. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Absolutely!
livekit-agents
does support multi-agent functionality, which means agents can smoothly hand off control to each other during a session. This happens through
function_tool
-decorated methods or by using the
update_agent
method if you want to manage it programmatically. Here’s a simple example to show how one agent can hand off to another:
Copy code
@function_tool
async def information_gathered(self, context: RunContext[StoryData], name: str, location: str):
    context.userdata.name = name
    context.userdata.location = location
    story_agent = StoryAgent(name, location)
    return story_agent, "Let's start the story!"
In this snippet, the current agent gathers some user info, then passes control to a
StoryAgent
to keep the session going. The framework takes care of switching control automatically. If you prefer, you can also use the
update_agent
method to switch agents directly like this:
Copy code
self.session.update_agent(LongAgent())
Feel free to ask if you want me to walk you through more examples or if there’s anything else you’d like to know! Sources: Workflows | LiveKit Docs | livekit-agents/livekit/agents/voice/run_result.py | complex-agents/medical_office_triage/triage.py | Workflows | LiveKit Docs | Building Multi-Agent Architectures with LiveKit Agents
p
i want each agent has its own TTS, LLM and system prompt
t
Hey there! Just wanted to share how each agent in
livekit-agents
can have its own unique TTS, LLM, and system prompt by setting these up individually in the agent's class constructor. Here's a simple way to do it: 1. Define System Prompt (Instructions):
Copy code
class IntroAgent(Agent):
    def __init__(self):
        super().__init__(
            instructions="Your name is Echo. You are a storyteller... gather a few pieces of information from the user..."
        )
2. Configure LLM per Agent:
Copy code
llm = openai.LLM(model="gpt-4o-mini")
3. Configure TTS per Agent:
Copy code
tts = openai.TTS(voice="ash")
4. Combine All in a Custom Agent Class:
Copy code
class TriageAgent(Agent):
    def __init__(self):
        super().__init__(
            instructions="You are a triage assistant...",
            stt=deepgram.STT(),
            llm=openai.LLM(model="gpt-4o-mini"),
            tts=cartesia.TTS(),
            vad=silero.VAD.load()
        )
So, each agent can really have its own special setup for how it behaves, sounds, and thinks. If you want, I’m here to help with more examples or any questions you have! Sources: examples/voice_agents/mcp/mcp-agent.py | Building voice agents | LiveKit Docs | Realtime model integrations | LiveKit Docs | Gemini Live API integration guide | LiveKit Docs