many-fall-81099
08/05/2025, 11:59 AMtall-airline-16756
08/05/2025, 11:59 AMtall-airline-16756
08/05/2025, 12:00 PMturn_detection="manual" in the AgentSession constructor to disable automatic turn detection:
# Create an AgentSession with manual turn detection
session = AgentSession(
turn_detection="manual",
stt=deepgram.STT(),
vad=silero.VAD.load(),
)
• Disable audio input using session.input.set_audio_enabled(False) to stop the agent from receiving audio:
# Disable audio input
session.input.set_audio_enabled(False)
• Manually control user turns with session.commit_user_turn() or `session.clear_user_turn()`:
# Commit the user turn
session.commit_user_turn(transcript_timeout=10.0)
# Clear the user turn
session.clear_user_turn()
• Optionally, implement RPC methods to start and end user turns:
# Start a user's turn
@ctx.room.local_participant.register_rpc_method("start_turn")
async def start_turn(data: rtc.RpcInvocationData):
session.interrupt()
session.clear_user_turn()
session.input.set_audio_enabled(True)
# End a user's turn
@ctx.room.local_participant.register_rpc_method("end_turn")
async def end_turn(data: rtc.RpcInvocationData):
session.input.set_audio_enabled(False)
session.commit_user_turn(transcript_timeout=10.0)
These methods allow you to manually control when the agent responds or remains inactive.many-fall-81099
08/05/2025, 10:17 PMtall-airline-16756
08/05/2025, 10:17 PMaudio_enabled=False in RoomOutputOptions. This way, the agent won’t send any audio responses and will stick to text only—no speech sync needed.
• Use Agent Handoff Event: Make use of the AgentHandoffEvent class to smoothly transfer the call to a human agent. It also keeps a record of the handoff, so you can verify everything went well.
• Manual Turn Detection: When you create your AgentSession, set turn_detection="manual". This lets you take control of user turns during the handoff process.
Here’s a quick example showing how to disable the agent during handoff:
class YourAgent(Agent):
@function_tool
async def transfer_call(self, context: RunContext, phone_number: str):
# Initialize the handoff process
# Create a SIP participant for the human agent
# Transfer the call to the human agent
pass
async def entrypoint(ctx: JobContext):
session = AgentSession(turn_detection="manual")
# Initialize the agent and start the session
agent = YourAgent()
await session.start(agent=agent, room=ctx.room)
# Disable audio input at the start
session.input.set_audio_enabled(False)
If you want to see it all in action, check out the "telephony/warm_handoff.py" example—it’s a great reference for a warm handoff process.
Feel free to reach out if you want me to walk you through any part of this or if you have any questions. I’m here to help!
Sources: Text and transcriptions | LiveKit Docs | livekit-agents/livekit/agents/voice/run_result.py | Turn detection and interruptions | LiveKit Docs | basics/interrupts_user.py