Do you have example for telephone agent features b...
# ask-ai
c
Do you have example for telephone agent features below: 1- When the call exceed 5 minutes, the agent will say 'Because of time limit the call is end' and hangup. 2- When user do not say anything in 5 second, the agent will say 'Are you in there'. and after the next 5 second if user do not say anything the agent says smth and hangup.
t
Thanks for reaching out, Yusuf. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Here is an example of how you can implement silence detection and handling during calls:
Copy code
import asyncio
import time

SILENCE_THRESHOLD = 5  # seconds

async def entrypoint(ctx: JobContext):
    user_last_spoke_time = time.time()
    monitor_task = None

    async def monitor_interaction():
        while True:
            if time.time() - user_last_spoke_time > SILENCE_THRESHOLD:
                <http://logger.info|logger.info>("silent for too long! disconnecting")
                try:
                    await ctx.room.disconnect()
                except Exception as e:
                    logger.exception("Error while ending call")
            else:
                logger.trace("silence is not enough to disconnect")
            await asyncio.sleep(1)

    @agent.on("user_started_speaking")
    def on_user_started_speaking(_msg: llm.ChatMessage):
        user_last_spoke_time = time.time()

    monitor_task = asyncio.create_task(monitor_interaction())

    agent.start(ctx.room, participant)

    async def on_shutdown():
        <http://logger.info|logger.info>("shutting down session")
        if monitor_task:
            monitor_task.cancel()
    ctx.add_shutdown_callback(on_shutdown)
This example monitors silence during a call and disconnects if the silence exceeds a specified threshold (e.g., 5 seconds). You can modify the logic to include prompts like "Are you there?" before disconnecting. Unfortunately, I couldn't find a specific example for implementing a call time limit feature. If you need further assistance with that, please let me know! Sources: How to detect and handle silence during calls
f
@alert-easter-19258 your response answered second part of Yusuf's question which is: "When user do not say anything in 5 second, the agent will say 'Are you in there'. and after the next 5 second if user do not say anything the agent says smth and hangup." what about the first part? you did not answer this: "When the call exceed 5 minutes, the agent will say 'Because of time limit the call is end' and hangup."
f
thanks bro. i used this to find answer https://deepwiki.com/livekit/livekit_composite very helpful