can i create 2 agents, one agent that asks questio...
# ask-ai
p
can i create 2 agents, one agent that asks question and another agent that replies to the questions asked by the bot and i as the viewer can listen to these 2 bots conversing so that in room there are 3 participants 2 bots and one user. give me the names of the events that can be used when identifying one bot has finished speaking so that the other bot can start talking
t
Thanks for reaching out, Aaron. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — this is a great use case. I’m responding to your two points: confirming the multi-agent setup and giving the specific event names you can use to detect when one bot finishes speaking so the other can start. Short answer • Yes — you can have 3 participants in a room: two agents (bots) and one human listener. • Use these events to detect when a bot has finished speaking: ◦
agent_state_changed
— watch for
new_state == "idle"
. ◦
SpeechHandle.wait_for_playout()
(or the handle’s done/callback) — signals accurate TTS/playout completion. How to coordinate the two bots (recommended flow) 1. Create two independent AgentSession instances — one per bot. 2. When Bot A begins speaking, you can track that via
agent_state_changed
(
new_state == "speaking"
). 3. When Bot A finishes: ◦ Option A (accurate): await the returned
SpeechHandle
and call
await handle.wait_for_playout()
(or use
handle.add_done_callback
) — then trigger Bot B’s
say()
or
generate_reply()
. ◦ Option B (state-based): listen for
agent_state_changed
with
new_state == "idle"
and then start Bot B. 1. Repeat for handoff back to Bot A. Route each bot’s audio into the room so the human participant can hear both. Which method to use • Use
SpeechHandle.wait_for_playout()
for the most reliable detection of actual audio playback completion. • Use
agent_state_changed
with
idle
for simpler state-driven coordination (less precise if there’s buffering/latency). If you’d like, I can: • Show a concise code example (Python or TypeScript) that wires two AgentSessions together using
SpeechHandle.wait_for_playout()
and routes audio into the room. • Or provide a small state-machine pattern using
agent_state_changed
events. Which would you prefer — a code sample in Python or TypeScript? Sources: Pipeline nodes and hooks | LiveKit Documentation | Turns overview | LiveKit Documentation | How to detect when an agent has finished speaking | LiveKit