is it possible to have a custom speaking order bet...
# ask-ai
c
is it possible to have a custom speaking order between one user and multiple agents? I want agents to speak after one another
t
Thanks for reaching out, Nathan. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Absolutely, you can set up a custom speaking order between one user and multiple agents in LiveKit. Here are a few ways you might approach this: • Turn Detection Parameters: You can tweak settings like
min_endpointing_delay
and
max_endpointing_delay
to manage the timing of turns. This helps control when agents jump in after the user finishes speaking. • Turn Detection Models: LiveKit’s turn detection models can predict when the user’s done talking, which is super handy for lining up agent responses smoothly. • Agent Transfer: Check out the
multi_agent.py
example—it shows how to hand off control between agents. You can set your own order using logical transfers and hooks like
on_enter()
and
on_exit()
. • Custom Hooks: Try using the
on_user_turn_completed()
hook to run some logic right after the user finishes speaking, so you can decide which agent should reply next. If you want, I’d be happy to walk you through any of these methods in more detail—just let me know! Sources: livekit-agents/livekit/agents/voice/agent_session.py | Voice pipeline nodes | LiveKit Docs | livekit-compose-components/src/main/java/io/livekit/android/compose/sorting... | lib/src/ui/layout/sorting.dart | AI voice agents | LiveKit Docs
c
will this allow agents to speak directly after each other, or only after the user?
t
Hey there! In LiveKit, agents can be set up to chat one after the other without waiting for the user to jump in, depending on how it’s set up. Could you let me know if you’d like the agents to speak back-to-back on their own, or only when the user responds? That way, I can give you the best advice possible. Sources: Agent speech and audio | LiveKit Docs | How does end-of-utterance detection work in conversations?
c
I'd like the agents to speak back-to-back on their own
t
If you want your agents to chat back-to-back in LiveKit without waiting for user input, you can do that by manually controlling when they speak. Here’s a simple way to set it up: 1. Manual Turn Detection: Use
turn_detection="manual"
in your
AgentSession
so you decide the flow of conversation. 2. Disable Audio Input: Turn off audio input at the start so agents don’t pause waiting for the user. 3. Sequential Speech: Call
session.say()
for each message you want your agents to say, one right after another. Here’s a quick example to get you going:
Copy code
class BackToBackSpeechAgent(Agent):
    async def on_enter(self):
        self.session.say("Hello, this is the first message.")
        self.session.say("This is the second message.")

async def entrypoint(ctx: JobContext):
    session = AgentSession(turn_detection="manual")
    session.input.set_audio_enabled(False)
    await session.start(agent=BackToBackSpeechAgent())
    await session.commit_user_turn()
This way, your agents can have a smooth back-to-back conversation without any pauses for user input. If you have any questions or want to tweak it further, just let me know—I’m here to help!
c
is there a way to make use of the turn detection model while still achieving this behavior
t
Great news! You can definitely use turn detection models while letting agents chat back-to-back, it just takes a bit of thoughtful setup. Here’s a friendly guide on how to make it work: 1. Turn Detection Models: LiveKit’s turn detection models are pretty smart—they can tell when someone’s finished speaking. You can use these to smoothly switch between the user and the agent. 2. Custom Logic for Agent Turns: These models mainly focus on user input, but you can add your own logic to let agents jump in one after another once the user’s turn wraps up. 3. Manual Overrides: Mixing turn detection with manual overrides gives your agents the freedom to keep the conversation flowing without waiting on the user every time. This way, you get the best of both worlds—using turn detection while keeping control over how your agents respond. If you want, I’m here to share more details or examples anytime!
c
give me an example of how you can use the turn detection model AND the manual overrides
t
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!