when I run the agent in console mode - ctx.delete_...
# ask-ai
n
when I run the agent in console mode - ctx.delete_room() making hangup to the call but when I deploy it, and it run on the cloud, its not hang up the call, why ? and how to perform hang up in live mode ?
t
Thanks for reaching out, Niv. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The
ctx.delete_room()
method is designed to delete the entire room, which disconnects all participants and effectively ends the call. However, its behavior can vary between console mode and cloud deployment because of environment-specific settings or how the code runs. In console mode, the environment uses simulated settings, including mock values for the room and API credentials, so it might not fully reflect what happens in a live cloud environment. When deployed in the cloud,
ctx.delete_room()
works on real rooms and causes actual disconnections. This process might take a bit longer or trigger extra actions like webhook notifications or integration callbacks. To help make sure your call ends smoothly in live mode, here are a few things to check: • Double-check that your API key and secret are set up correctly for your cloud environment. • Make sure the room name you use in the deletion request exactly matches the room name in your cloud deployment. • Confirm that your agent has the right permissions to delete rooms in production. If you'd like, I'm here to help you review your cloud deployment setup or answer any questions you have. Just let me know! Sources: Agents telephony integration | LiveKit Docs | livekit-agents/livekit/agents/cli/cli.py | Job lifecycle | LiveKit Docs | Managing rooms | LiveKit Docs | Connecting to LiveKit | LiveKit Docs
n
how to Confirm that your agent has the right permissions to delete rooms in production. ?
t
Let’s make sure your agent has the right permissions to delete rooms in production. The key is to check that the agent's access token includes the
roomCreate
permission, as this controls both creating and deleting rooms in LiveKit. Here’s a simple way to verify and set this permission: 1. Check the Agent’s Token Grants: First, confirm that the agent's access token has
roomCreate: true
in its VideoGrant. For example, with the LiveKit Server SDK, it looks like this:
Copy code
const token = new AccessToken(apiKey, apiSecret, { identity: 'agent' });
token.addGrant({
  roomCreate: true,  // Needed to delete rooms
  roomList: true,
});
2. Using CLI Tool (Alternative): If you prefer the LiveKit CLI, just use the
--create
flag, which gives both room creation and deletion permissions:
lk token --create --room myroom
3. Test Deletion Request: Try calling
deleteRoom
through the RoomServiceClient. If the agent doesn’t have permission, you’ll get an authorization error from the server. If you’d like, I’m here to help you walk through setting or checking these permissions. Just let me know! Sources: pkg/service/agent_dispatch_service.go | Authentication | LiveKit Docs | CLI Tools & Token Management | livekit/livekit_composite | DeepWiki
n
await session.start( room=ctx.room, agent=agent, room_input_options=RoomInputOptions( # For telephony applications, use
BVCTelephony
instead for best results noise_cancellation=noise_cancellation.BVCTelephony(), ), )
t
I'm happy to help you get started with
session.start
using
RoomInputOptions
and
BVCTelephony
. By configuring the
noise_cancellation
parameter, you can enable advanced noise cancellation designed specifically for telephony, which really helps improve audio clarity by reducing background noise during calls. Here’s a simple example to guide you:
Copy code
await session.start(
    agent=agent,
    room=ctx.room,
    room_input_options=RoomInputOptions(
        noise_cancellation=noise_cancellation.BVCTelephony(),
        audio_enabled=True,
        text_enabled=True,
        close_on_disconnect=True,
        participant_kinds=[
            rtc.ParticipantKind.PARTICIPANT_KIND_SIP,
            rtc.ParticipantKind.PARTICIPANT_KIND_STANDARD
        ],
    ),
)
For telephony workflows, it’s important to start the agent session before making the SIP call to ensure you don’t miss any initial speech. Here’s how you can do that:
Copy code
session_started = asyncio.create_task(
    session.start(
        agent=agent,
        room=ctx.room,
        room_input_options=RoomInputOptions(
            noise_cancellation=noise_cancellation.BVCTelephony(),
        ),
    )
)

# Create SIP participant
await ctx.api.sip.create_sip_participant(
    api.CreateSIPParticipantRequest(
        room_name=ctx.room.name,
        sip_trunk_id=outbound_trunk_id,
        sip_call_to=phone_number,
        participant_identity=participant_identity,
        wait_until_answered=True,
    )
)

await session_started
If anything feels unclear or you’d like more personalized help with your setup, please don’t hesitate to reach out. I’m here to support you every step of the way! Sources: agent.py | examples/voice_agents/realtime_joke_teller.py | Agents telephony integration | LiveKit Docs | How to Enable Agent-to-Agent Speech Detection in LiveKit