Is there a way to shut the agent. Basically manual...
# ask-ai
m
Is there a way to shut the agent. Basically manually keep the agent from responding back.
t
Thanks for reaching out, AI. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To manually prevent the agent from responding, you can use the Manual Turn Detection feature. Here are the steps: • Set
turn_detection="manual"
in the
AgentSession
constructor to disable automatic turn detection:
Copy code
# 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:
Copy code
# Disable audio input
session.input.set_audio_enabled(False)
• Manually control user turns with
session.commit_user_turn()
or `session.clear_user_turn()`:
Copy code
# 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:
Copy code
# 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.
m
Hmm basically the agent shouldnt respond at this point. This is for implementing human handoff feature..where when human is joined, the agent shoould not respond
t
If you want to set up a human handoff feature where the agent stops responding once a human joins, here’s a friendly step-by-step guide to help you out: • Disable Audio Output: Just set
audio_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:
Copy code
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