agents icon indicating copy to clipboard operation
agents copied to clipboard

How to prevent the worker from shutting down on its own?

Open ghost opened this issue 1 year ago • 25 comments

Currently workers shut down on their own after about 25 seconds of inactivity. This is undesirable. How can I disable this?

ghost avatar Jun 30 '25 16:06 ghost

Do you mean the worker will shutdown after a few seconds the user left the room? Could you explain what is your use case to have the agent stay in the room when user disconnected?

longcw avatar Jul 01 '25 02:07 longcw

Currently workers shut down on their own after about 25 seconds of inactivity. This is undesirable. How can I disable this? i am also facing same issue as when i make the outbound call call getting triggered after picking up the call intro audio is played after that when i try to speak it is unable to respond and after 25 sec call getting disconnected in same way

Smshendehub avatar Jul 01 '25 04:07 Smshendehub

after picking up the call intro audio is played after that when i try to speak it is unable to respond and after 25 sec call getting disconnected in same way

@Smshendehub can you share an example to reproduce this? The worker shouldn't shutdown if the user is still in the room.

longcw avatar Jul 01 '25 05:07 longcw

Can you share the logs when worker shutdown, it might be related to user disconnect/reconnect to the room, if so there should be a log to indicate you to disable the close_on_disconnect if it's not expected. @Smshendehub @koakuma-chan

longcw avatar Jul 01 '25 05:07 longcw

@longcw @koakuma-chan i will share my logs what exactly happening with me

  • DEV livekit.agents - Watching /root/sip_twilio/voice-agent 2025-06-30 11:59:16,704 - DEBUG asyncio - Using selector: EpollSelector 2025-06-30 11:59:16,709 - INFO livekit.agents - starting worker {"version": "1.1.1", "rtc-version": "1.0.8"} 2025-06-30 11:59:16,709 - INFO livekit.agents - preloading plugins {"packages": ["livekit.plugins.openai", "livekit.plugins.silero", "livekit.plugins.deepgram", "livekit.plugins.cartesia"]} 2025-06-30 11:59:16,711 - INFO livekit.agents - see tracing information at http://localhost:33279/debug 2025-06-30 11:59:16,726 - INFO livekit.agents - registered worker {"id": "AW_HGmM5ewHBN4Y", "url": "wss://livekit.slingo.ai", "region": "", "protocol": 15} 2025-06-30 11:59:32,940 - INFO livekit.agents - received job request {"job_id": "AJ_QpScvRuh9GJN", "dispatch_id": "AD_KZmBhEmJVXN5", "room_name": "my-room21", "agent_name": "", "resuming": false} 2025-06-30 11:59:33,650 - INFO livekit.agents - initializing process {"pid": 19571} 2025-06-30 11:59:33,658 - INFO livekit.agents - process initialized {"pid": 19571, "elapsed_time": 0.01} 2025-06-30 11:59:33,658 - DEBUG asyncio - Using selector: EpollSelector {"pid": 19571, "job_id": "AJ_QpScvRuh9GJN"} 2025-06-30 11:59:34,080 - calling-agent - INFO - 🚀 === STARTING VOICE AGENT SESSION === 2025-06-30 11:59:34,080 - calling-agent - INFO - Agent: SalesAgent 2025-06-30 11:59:34,080 - calling-agent - INFO - Room: my-room21 2025-06-30 11:59:34,080 - INFO agents - SalesAgent 'Akash' initialized with enhanced VAD settings {"pid": 19571, "job_id": "AJ_QpScvRuh9GJN"} 2025-06-30 11:59:34,080 - calling-agent - INFO - 🚀 === STARTING VOICE AGENT SESSION === 2025-06-30 11:59:34,080 - INFO calling-agent - 🚀 === STARTING VOICE AGENT SESSION === {"pid": 19571, "job_id": "AJ_QpScvRuh9GJN"} 2025-06-30 11:59:34,080 - calling-agent - INFO - Agent: SalesAgent 2025-06-30 11:59:34,080 - INFO calling-agent - Agent: SalesAgent {"pid": 19571, "job_id": "AJ_QpScvRuh9GJN"} 2025-06-30 11:59:34,080 - calling-agent - INFO - Room: my-room21 2025-06-30 11:59:34,080 - INFO calling-agent - Room: my-room21 {"pid": 19571, "job_id": "AJ_QpScvRuh9GJN"} 2025-06-30 11:59:34,089 - DEBUG livekit.agents - http_session(): creating a new httpclient ctx {"pid": 19571, "job_id": "AJ_QpScvRuh9GJN"} 2025-06-30 11:59:34,091 - INFO agents - SalesAgent 'Akash' session started - generating initial greeting {"pid": 19571, "job_id": "AJ_QpScvRuh9GJN"} 2025-06-30 11:59:34,091 - DEBUG livekit.agents - start reading stream {"participant": "phone_user", "source": "SOURCE_MICROPHONE", "pid": 19571, "job_id": "AJ_QpScvRuh9GJN"} 2025-06-30 11:59:35,182 - INFO livekit.agents - LLM metrics: ttft=0.33, input_tokens=601, cached_input_tokens=0, output_tokens=422, tokens_per_second=388.70 {"pid": 19571, "job_id": "AJ_QpScvRuh9GJN"} 2025-06-30 11:59:37,427 - INFO livekit.agents - TTS metrics: ttfb=0.5966716620605439, audio_duration=114.42 {"pid": 19571, "job_id": "AJ_QpScvRuh9GJN"} 2025-06-30 11:59:39,108 - INFO livekit.agents - STT metrics: audio_duration=5.00 {"pid": 19571, "job_id": "AJ_QpScvRuh9GJN"} 2025-06-30 11:59:44,169 - INFO livekit.agents - STT metrics: audio_duration=5.05 {"pid": 19571, "job_id": "AJ_QpScvRuh9GJN"} 2025-06-30 11:59:49,189 - INFO livekit.agents - STT metrics: audio_duration=5.05 {"pid": 19571, "job_id": "AJ_QpScvRuh9GJN"} 2025-06-30 11:59:54,219 - INFO livekit.agents - STT metrics: audio_duration=5.00 {"pid": 19571, "job_id": "AJ_QpScvRuh9GJN"} 2025-06-30 11:59:59,239 - INFO livekit.agents - STT metrics: audio_duration=5.05 {"pid": 19571, "job_id": "AJ_QpScvRuh9GJN"} 2025-06-30 12:00:02,947 - DEBUG livekit.agents - closing agent session due to participant disconnect {"participant": "phone_user", "reason": "CLIENT_INITIATED", "pid": 19571, "job_id": "AJ_QpScvRuh9GJN"} 2025-06-30 12:00:02,948 - DEBUG livekit.agents - stream closed {"participant": "phone_user", "source": "SOURCE_MICROPHONE", "pid": 19571, "job_id": "AJ_QpScvRuh9GJN"} 2025-06-30 12:00:02,953 - WARNING livekit.agents - rotate_segment called while previous segment is still being rotated {"pid": 19571, "job_id": "AJ_QpScvRuh9GJN"} 2025-06-30 12:00:02,957 - DEBUG livekit.agents - session closed {"reason": "participant_disconnected", "error": null, "pid": 19571, "job_id": "AJ_QpScvRuh9GJN"} 2025-06-30 12:00:22,982 - DEBUG livekit.agents - shutting down job task {"reason": "", "user_initiated": false, "pid": 19571, "job_id": "AJ_QpScvRuh9GJN"} 2025-06-30 12:00:22,983 - INFO livekit.agents - process exiting {"reason": "", "pid": 19571, "job_id": "AJ_QpScvRuh9GJN"} 2025-06-30 12:00:22,984 - calling-agent - INFO - 📊 === SESSION USAGE SUMMARY === 2025-06-30 12:00:22,984 - calling-agent - INFO - Usage Summary: UsageSummary(llm_prompt_tokens=601, llm_prompt_cached_tokens=0, llm_completion_tokens=422, tts_characters_count=1943, stt_audio_duration=25.14999999999995) 2025-06-30 12:00:22,984 - calling-agent - INFO - 📊 === SESSION USAGE SUMMARY === 2025-06-30 12:00:22,984 - INFO calling-agent - 📊 === SESSION USAGE SUMMARY === {"pid": 19571, "job_id": "AJ_QpScvRuh9GJN"} 2025-06-30 12:00:22,984 - calling-agent - INFO - Usage Summary: UsageSummary(llm_prompt_tokens=601, llm_prompt_cached_tokens=0, llm_completion_tokens=422, tts_characters_count=1943, stt_audio_duration=25.14999999999995) 2025-06-30 12:00:22,984 - INFO calling-agent - Usage Summary: UsageSummary(llm_prompt_tokens=601, llm_prompt_cached_tokens=0, llm_completion_tokens=422, tts_characters_count=1943, stt_audio_duration=25.14999999999995) {"pid": 19571, "job_id": "AJ_QpScvRuh9GJN"} 2025-06-30 12:00:22,984 - DEBUG livekit.agents - http_session(): closing the httpclient ctx {"pid": 19571, "job_id": "AJ_QpScvRuh9GJN"}

Smshendehub avatar Jul 01 '25 05:07 Smshendehub

2025-06-30 12:00:02,947 - DEBUG livekit.agents - closing agent session due to participant disconnect {"participant": "phone_user", "reason": "CLIENT_INITIATED", "pid": 19571, "job_id": "AJ_QpScvRuh9GJN"}
2025-06-30 12:00:02,948 - DEBUG livekit.agents - stream closed {"participant": "phone_user", "source": "SOURCE_MICROPHONE", "pid": 19571, "job_id": "AJ_QpScvRuh9GJN"}
2025-06-30 12:00:02,953 - WARNING livekit.agents - rotate_segment called while previous segment is still being rotated {"pid": 19571, "job_id": "AJ_QpScvRuh9GJN"}
2025-06-30 12:00:02,957 - DEBUG livekit.agents - session closed {"reason": "participant_disconnected", "error": null, "pid": 19571, "job_id": "AJ_QpScvRuh9GJN"}
2025-06-30 12:00:22,982 - DEBUG livekit.agents - shutting down job task {"reason": "", "user_initiated": false, "pid": 19571, "job_id": "AJ_QpScvRuh9GJN"}

yes, this is the case. the agent session closed due to user disconnected (theoretically we only close the session when the reason is "CLIENT_INITIATED", but maybe refresh or network issue causes the same reason). You can disable this with RoomInputOptions.close_on_disconnect=False

    await session.start(
        agent=MyAgent(),
        room=ctx.room,
        room_input_options=RoomInputOptions(close_on_disconnect=False),
    )

In agents 1.1.5, we will also disconnect the agent from the room and log a message like

closing agent session due to participant disconnect (disable via RoomInputOptions.close_on_disconnect=False)

Note that close_on_disconnect=False will disable the immediate closing of agent after user disconnected, but if user didn't reconnect after 20 seconds, the worker will still be shutdown.

longcw avatar Jul 01 '25 05:07 longcw

still the issue is same @longcw

Smshendehub avatar Jul 01 '25 06:07 Smshendehub

@Smshendehub

Note that close_on_disconnect=False will disable the immediate closing of agent after user disconnected, but if user didn't reconnect after 20 seconds, the worker will still be shutdown.

Can you share the logs, and it seems that the user never reconnect after disconnection. You may need to check why it's disconnected.

longcw avatar Jul 01 '25 06:07 longcw

@longcw DEBUG asyncio - Using selector: EpollSelector 2025-07-01 12:30:20,948 - DEV livekit.agents - Watching /root/sip_twilio/voice-agent 2025-07-01 12:30:21,640 - DEBUG asyncio - Using selector: EpollSelector 2025-07-01 12:30:21,644 - INFO livekit.agents - starting worker {"version": "1.1.5", "rtc-version": "1.0.11"} 2025-07-01 12:30:21,644 - INFO livekit.agents - preloading plugins {"packages": ["livekit.plugins.openai", "livekit.plugins.silero", "livekit.plugins.deepgram"]} 2025-07-01 12:30:21,647 - INFO livekit.agents - see tracing information at http://localhost:33663/debug 2025-07-01 12:30:21,660 - INFO livekit.agents - registered worker {"id": "AW_ZJRWdAYXw69u", "url": "wss://livekit.slingo.ai", "region": "", "protocol": 15} 2025-07-01 12:30:32,267 - INFO livekit.agents - received job request {"job_id": "AJ_3tjaJKxi26Lu", "dispatch_id": "AD_oCx5rD6D2YS8", "room_name": "my-room21", "agent_name": "", "resuming": false} 2025-07-01 12:30:32,987 - INFO livekit.agents - initializing process {"pid": 7345} 2025-07-01 12:30:32,995 - INFO livekit.agents - process initialized {"pid": 7345, "elapsed_time": 0.01} 2025-07-01 12:30:32,995 - DEBUG asyncio - Using selector: EpollSelector {"pid": 7345, "job_id": "AJ_3tjaJKxi26Lu"} 2025-07-01 12:30:33,404 - calling-agent - INFO - 🚀 === STARTING VOICE AGENT SESSION === 2025-07-01 12:30:33,404 - calling-agent - INFO - Agent: SalesAgent 2025-07-01 12:30:33,404 - calling-agent - INFO - Room: my-room21 2025-07-01 12:30:33,404 - INFO agents - SalesAgent 'Akash' initialized {"pid": 7345, "job_id": "AJ_3tjaJKxi26Lu"} 2025-07-01 12:30:33,404 - calling-agent - INFO - 🚀 === STARTING VOICE AGENT SESSION === 2025-07-01 12:30:33,404 - INFO calling-agent - 🚀 === STARTING VOICE AGENT SESSION === {"pid": 7345, "job_id": "AJ_3tjaJKxi26Lu"} 2025-07-01 12:30:33,404 - calling-agent - INFO - Agent: SalesAgent 2025-07-01 12:30:33,404 - INFO calling-agent - Agent: SalesAgent {"pid": 7345, "job_id": "AJ_3tjaJKxi26Lu"} 2025-07-01 12:30:33,404 - calling-agent - INFO - Room: my-room21 2025-07-01 12:30:33,404 - INFO calling-agent - Room: my-room21 {"pid": 7345, "job_id": "AJ_3tjaJKxi26Lu"} 2025-07-01 12:30:33,412 - DEBUG livekit.agents - http_session(): creating a new httpclient ctx {"pid": 7345, "job_id": "AJ_3tjaJKxi26Lu"} 2025-07-01 12:30:33,413 - INFO agents - SalesAgent 'Akash' session started - generating initial greeting {"pid": 7345, "job_id": "AJ_3tjaJKxi26Lu"} 2025-07-01 12:30:33,414 - DEBUG livekit.agents - start reading stream {"participant": "phone_user", "source": "SOURCE_MICROPHONE", "pid": 7345, "job_id": "AJ_3tjaJKxi26Lu"} 2025-07-01 12:30:33,829 - INFO livekit.agents - LLM metrics: ttft=0.35, input_tokens=608, cached_input_tokens=0, output_tokens=30, tokens_per_second=74.49 {"pid": 7345, "job_id": "AJ_3tjaJKxi26Lu"} 2025-07-01 12:30:35,971 - INFO livekit.agents - TTS metrics: ttfb=0.5686532519757748, audio_duration=7.60 {"pid": 7345, "job_id": "AJ_3tjaJKxi26Lu"} 2025-07-01 12:30:38,438 - INFO livekit.agents - STT metrics: audio_duration=5.00 {"pid": 7345, "job_id": "AJ_3tjaJKxi26Lu"} 2025-07-01 12:30:43,500 - INFO livekit.agents - STT metrics: audio_duration=5.05 {"pid": 7345, "job_id": "AJ_3tjaJKxi26Lu"} 2025-07-01 12:30:48,518 - INFO livekit.agents - STT metrics: audio_duration=5.05 {"pid": 7345, "job_id": "AJ_3tjaJKxi26Lu"} 2025-07-01 12:30:53,548 - INFO livekit.agents - STT metrics: audio_duration=5.00 {"pid": 7345, "job_id": "AJ_3tjaJKxi26Lu"} 2025-07-01 12:30:58,568 - INFO livekit.agents - STT metrics: audio_duration=5.05 {"pid": 7345, "job_id": "AJ_3tjaJKxi26Lu"} ^C2025-07-01 12:31:02,227 - INFO livekit.agents - shutting down worker {"id": "AW_ZJRWdAYXw69u"} 2025-07-01 12:31:02,229 - INFO livekit.agents - process exiting {"reason": "", "pid": 7345, "job_id": "AJ_3tjaJKxi26Lu"} 2025-07-01 12:31:02,228 - DEBUG livekit.agents - shutting down job task {"reason": "", "user_initiated": false, "pid": 7345, "job_id": "AJ_3tjaJKxi26Lu"} 2025-07-01 12:31:02,229 - DEBUG livekit.agents - stream closed {"participant": "phone_user", "source": "SOURCE_MICROPHONE", "pid": 7345, "job_id": "AJ_3tjaJKxi26Lu"} 2025-07-01 12:31:02,235 - calling-agent - INFO - 📊 === SESSION USAGE SUMMARY === 2025-07-01 12:31:02,235 - calling-agent - INFO - Usage Summary: UsageSummary(llm_prompt_tokens=608, llm_prompt_cached_tokens=0, llm_completion_tokens=30, tts_characters_count=134, stt_audio_duration=25.14999999999995) 2025-07-01 12:31:02,235 - calling-agent - INFO - 📊 === SESSION USAGE SUMMARY === 2025-07-01 12:31:02,235 - INFO calling-agent - 📊 === SESSION USAGE SUMMARY === {"pid": 7345, "job_id": "AJ_3tjaJKxi26Lu"} 2025-07-01 12:31:02,235 - calling-agent - INFO - Usage Summary: UsageSummary(llm_prompt_tokens=608, llm_prompt_cached_tokens=0, llm_completion_tokens=30, tts_characters_count=134, stt_audio_duration=25.14999999999995) 2025-07-01 12:31:02,235 - INFO calling-agent - Usage Summary: UsageSummary(llm_prompt_tokens=608, llm_prompt_cached_tokens=0, llm_completion_tokens=30, tts_characters_count=134, stt_audio_duration=25.14999999999995) {"pid": 7345, "job_id": "AJ_3tjaJKxi26Lu"} 2025-07-01 12:31:02,239 - DEBUG livekit.agents - session closed {"reason": "job_shutdown", "error": null, "pid": 7345, "job_id": "AJ_3tjaJKxi26Lu"} 2025-07-01 12:31:02,240 - DEBUG livekit.agents - http_session(): closing the httpclient ctx {"pid": 7345, "job_id": "AJ_3tjaJKxi26Lu"} (venv) root@e2e-80-73:~/sip_twilio/voice-agent# python /root/sip_twilio/voice-agent/saurabh.py dev 2025-07-01 12:31:10,551 - DEBUG asyncio - Using selector: EpollSelector 2025-07-01 12:31:10,552 - DEV livekit.agents - Watching /root/sip_twilio/voice-agent 2025-07-01 12:31:11,302 - DEBUG asyncio - Using selector: EpollSelector 2025-07-01 12:31:11,307 - INFO livekit.agents - starting worker {"version": "1.1.5", "rtc-version": "1.0.11"} 2025-07-01 12:31:11,307 - INFO livekit.agents - preloading plugins {"packages": ["livekit.plugins.openai", "livekit.plugins.silero", "livekit.plugins.deepgram"]} 2025-07-01 12:31:11,309 - INFO livekit.agents - see tracing information at http://localhost:38767/debug 2025-07-01 12:31:11,326 - INFO livekit.agents - registered worker {"id": "AW_YfqFijRiWmhY", "url": "wss://livekit.slingo.ai", "region": "", "protocol": 15} ^C2025-07-01 12:31:43,082 - INFO livekit.agents - shutting down worker {"id": "AW_YfqFijRiWmhY"} (venv) root@e2e-80-73:~/sip_twilio/voice-agent# python /root/sip_twilio/voice-agent/saurabh.py dev 2025-07-01 12:31:59,518 - DEBUG asyncio - Using selector: EpollSelector 2025-07-01 12:31:59,519 - DEV livekit.agents - Watching /root/sip_twilio/voice-agent 2025-07-01 12:32:00,242 - DEBUG asyncio - Using selector: EpollSelector 2025-07-01 12:32:00,247 - INFO livekit.agents - starting worker {"version": "1.1.5", "rtc-version": "1.0.11"} 2025-07-01 12:32:00,247 - INFO livekit.agents - preloading plugins {"packages": ["livekit.plugins.openai", "livekit.plugins.silero", "livekit.plugins.deepgram"]} 2025-07-01 12:32:00,249 - INFO livekit.agents - see tracing information at http://localhost:40195/debug 2025-07-01 12:32:00,264 - INFO livekit.agents - registered worker {"id": "AW_DwZtuQrJAgPG", "url": "wss://livekit.slingo.ai", "region": "", "protocol": 15} 2025-07-01 12:32:06,102 - INFO livekit.agents - received job request {"job_id": "AJ_G4xZtqiNLmNG", "dispatch_id": "AD_BeZ68y4zecPs", "room_name": "my-room21", "agent_name": "", "resuming": false} 2025-07-01 12:32:06,859 - INFO livekit.agents - initializing process {"pid": 7842} 2025-07-01 12:32:06,868 - INFO livekit.agents - process initialized {"pid": 7842, "elapsed_time": 0.01} 2025-07-01 12:32:06,868 - DEBUG asyncio - Using selector: EpollSelector {"pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"} 2025-07-01 12:32:07,278 - calling-agent - INFO - 🚀 === STARTING VOICE AGENT SESSION === 2025-07-01 12:32:07,278 - calling-agent - INFO - Agent: SalesAgent 2025-07-01 12:32:07,278 - calling-agent - INFO - Room: my-room21 2025-07-01 12:32:07,277 - INFO agents - SalesAgent 'Akash' initialized {"pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"} 2025-07-01 12:32:07,278 - calling-agent - INFO - 🚀 === STARTING VOICE AGENT SESSION === 2025-07-01 12:32:07,278 - INFO calling-agent - 🚀 === STARTING VOICE AGENT SESSION === {"pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"} 2025-07-01 12:32:07,278 - calling-agent - INFO - Agent: SalesAgent 2025-07-01 12:32:07,278 - INFO calling-agent - Agent: SalesAgent {"pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"} 2025-07-01 12:32:07,278 - calling-agent - INFO - Room: my-room21 2025-07-01 12:32:07,278 - INFO calling-agent - Room: my-room21 {"pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"} 2025-07-01 12:32:07,287 - DEBUG livekit.agents - http_session(): creating a new httpclient ctx {"pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"} 2025-07-01 12:32:07,289 - INFO agents - SalesAgent 'Akash' session started - generating initial greeting {"pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"} 2025-07-01 12:32:07,289 - DEBUG livekit.agents - start reading stream {"participant": "phone_user", "source": "SOURCE_MICROPHONE", "pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"} 2025-07-01 12:32:07,728 - INFO livekit.agents - LLM metrics: ttft=0.40, input_tokens=608, cached_input_tokens=0, output_tokens=26, tokens_per_second=60.34 {"pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"} 2025-07-01 12:32:09,698 - INFO livekit.agents - TTS metrics: ttfb=0.5510210879147053, audio_duration=6.47 {"pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"} 2025-07-01 12:32:12,307 - INFO livekit.agents - STT metrics: audio_duration=5.00 {"pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"} 2025-07-01 12:32:17,367 - INFO livekit.agents - STT metrics: audio_duration=5.05 {"pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"} 2025-07-01 12:32:22,388 - INFO livekit.agents - STT metrics: audio_duration=5.05 {"pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"} 2025-07-01 12:32:27,417 - INFO livekit.agents - STT metrics: audio_duration=5.00 {"pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"} 2025-07-01 12:32:32,437 - INFO livekit.agents - STT metrics: audio_duration=5.05 {"pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"} 2025-07-01 12:32:36,109 - DEBUG livekit.agents - stream closed {"participant": "phone_user", "source": "SOURCE_MICROPHONE", "pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"} 2025-07-01 12:32:56,980 - DEBUG livekit.agents - shutting down job task {"reason": "", "user_initiated": false, "pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"} 2025-07-01 12:32:56,981 - INFO livekit.agents - process exiting {"reason": "", "pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"} 2025-07-01 12:32:56,981 - calling-agent - INFO - 📊 === SESSION USAGE SUMMARY === 2025-07-01 12:32:56,981 - calling-agent - INFO - Usage Summary: UsageSummary(llm_prompt_tokens=608, llm_prompt_cached_tokens=0, llm_completion_tokens=26, tts_characters_count=106, stt_audio_duration=25.14999999999995) 2025-07-01 12:32:56,981 - calling-agent - INFO - 📊 === SESSION USAGE SUMMARY === 2025-07-01 12:32:56,981 - INFO calling-agent - 📊 === SESSION USAGE SUMMARY === {"pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"} 2025-07-01 12:32:56,981 - calling-agent - INFO - Usage Summary: UsageSummary(llm_prompt_tokens=608, llm_prompt_cached_tokens=0, llm_completion_tokens=26, tts_characters_count=106, stt_audio_duration=25.14999999999995) 2025-07-01 12:32:56,981 - INFO calling-agent - Usage Summary: UsageSummary(llm_prompt_tokens=608, llm_prompt_cached_tokens=0, llm_completion_tokens=26, tts_characters_count=106, stt_audio_duration=25.14999999999995) {"pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"} 2025-07-01 12:32:56,983 - DEBUG livekit.agents - session closed {"reason": "job_shutdown", "error": null, "pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"} 2025-07-01 12:32:56,983 - DEBUG livekit.agents - http_session(): closing the httpclient ctx {"pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"} ^C2025-07-01 12:33:11,909 - INFO livekit.agents - shutting down worker {"id": "AW_DwZtuQrJAgPG"}

Smshendehub avatar Jul 01 '25 07:07 Smshendehub

@longcw yes i shared the logs please go through that and give me the solution for this in detailed way

Smshendehub avatar Jul 01 '25 07:07 Smshendehub

@Smshendehub for the logs it's the user disconnected and never reconnect, please check why the user disconnected instead

2025-07-01 12:32:07,289 - DEBUG livekit.agents - start reading stream {"participant": "phone_user", "source": "SOURCE_MICROPHONE", "pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"}
2025-07-01 12:32:07,728 - INFO livekit.agents - LLM metrics: ttft=0.40, input_tokens=608,  cached_input_tokens=0, output_tokens=26, tokens_per_second=60.34 {"pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"}
2025-07-01 12:32:09,698 - INFO livekit.agents - TTS metrics: ttfb=0.5510210879147053, audio_duration=6.47 {"pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"}
2025-07-01 12:32:12,307 - INFO livekit.agents - STT metrics: audio_duration=5.00 {"pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"}
2025-07-01 12:32:17,367 - INFO livekit.agents - STT metrics: audio_duration=5.05 {"pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"}
2025-07-01 12:32:22,388 - INFO livekit.agents - STT metrics: audio_duration=5.05 {"pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"}
2025-07-01 12:32:27,417 - INFO livekit.agents - STT metrics: audio_duration=5.00 {"pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"}
2025-07-01 12:32:32,437 - INFO livekit.agents - STT metrics: audio_duration=5.05 {"pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"}
2025-07-01 12:32:36,109 - DEBUG livekit.agents - stream closed {"participant": "phone_user", "source": "SOURCE_MICROPHONE", "pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"}
2025-07-01 12:32:56,980 - DEBUG livekit.agents - shutting down job task {"reason": "", "user_initiated": false, "pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"}
2025-07-01 12:32:56,981 - INFO livekit.agents - process exiting {"reason": "", "pid": 7842, "job_id": "AJ_G4xZtqiNLmNG"}

12:32:36,109 - DEBUG livekit.agents - stream closed user disconnected, after 20s the agent shutdown 2025-07-01 12:32:56,980 - DEBUG livekit.agents - shutting down job task. This is expected behavior.

longcw avatar Jul 01 '25 07:07 longcw

@Smshendehub Probably it's related to the outbound call, you can check the example of an outbound call agent here https://github.com/livekit-examples/outbound-caller-python

longcw avatar Jul 01 '25 07:07 longcw

@longcw yes i went through same example but still issue is same i am not able to get solution for this issue

Smshendehub avatar Jul 01 '25 09:07 Smshendehub

Do you mean the worker will shutdown after a few seconds the user left the room?

Yes, after 20-25 seconds.

Could you explain what is your use case to have the agent stay in the room when user disconnected?

I would like the agent to remain in the room so that, if the user reconnects, the user is able to continue using the agent. I had a similar issue in the past #2480 where the tavus avatar would disconnect immediately after the user disconnected, and it went away after I set close_on_disconnect=False.

Here however, it appears to me that, as opposed to closing the AgentSession or the AvatarSession upon the user disconnect, the worker itself gets shut down after 20-25 seconds of inactivity, and it does not get dispatched back into the same room when the user reconnects.

Here is the relevant logs:

# library version
2025-07-01 06:21:38,525 - INFO livekit.agents - starting worker {"version": "1.1.1", "rtc-version": "1.0.8"}

# i join the room
2025-07-01 06:22:55,034 - DEBUG livekit.agents - start reading stream {"participant": "redacted", "source": "SOURCE_MICROPHONE", "pid": 4951, "job_id": "AJ_TGjmKNief6dv"}

# i leave the room
2025-07-01 06:23:00,916 - DEBUG livekit.agents - stream closed {"participant": "redacted", "source": "SOURCE_MICROPHONE", "pid": 4951, "job_id": "AJ_TGjmKNief6dv"}

# the worker get shut down
2025-07-01 06:23:24,343 - DEBUG livekit.agents - shutting down job task {"reason": "", "user_initiated": false, "pid": 4951, "job_id": "AJ_TGjmKNief6dv"}
2025-07-01 06:23:24,351 - INFO livekit.agents - process exiting {"reason": "", "pid": 4951, "job_id": "AJ_TGjmKNief6dv"}
2025-07-01 06:23:24,353 - WARNING livekit - livekit::rtc_engine:450:livekit::rtc_engine - received session close: "signal client closed: \"stream closed\"" UnknownReason Resume {"pid": 4951, "job_id": "AJ_TGjmKNief6dv"}
2025-07-01 06:23:24,368 - DEBUG livekit.agents - session closed {"reason": "job_shutdown", "error": null, "pid": 4951, "job_id": "AJ_TGjmKNief6dv"}
2025-07-01 06:23:24,368 - DEBUG livekit.agents - http_session(): closing the httpclient ctx {"pid": 4951, "job_id": "AJ_TGjmKNief6dv"}
2025-07-01 06:23:24,368 - DEBUG livekit.agents - http_session(): creating a new httpclient ctx {"pid": 4951, "job_id": "AJ_TGjmKNief6dv"}
2025-07-01 06:23:27,944 - INFO livekit.agents - shutting down worker {"id": "AW_Djm6fyJk9tEX"}
2025-07-01 06:23:27,945 - INFO livekit.agents - process exiting {"reason": "", "pid": 4628, "inference": true}

Note that close_on_disconnect=False will disable the immediate closing of agent after user disconnected, but if user didn't reconnect after 20 seconds, the worker will still be shutdown.

Is there a way to prevent this? (or increase the timeout)

ghost avatar Jul 01 '25 10:07 ghost

Hey @longcw, I assume the 20 second timeout is a feature of livekit-agents, is that correct? If so, would you be able to advise me where exactly that is implemented, so that, if that is not something that can be configured at the moment, I could just make a fork and increase the value?

ghost avatar Jul 02 '25 10:07 ghost

@koakuma-chan it's not configurable right now, the room will be closed by the server if there is no human participant in the room after the timeout. (If you really don't want to close the room, perhaps you can create a mock human participant)

Can you explain what is the user case you want this feature? If it's to have the agent loading some models before user join the room, you can use the prewarm feature of the agent.

longcw avatar Jul 02 '25 10:07 longcw

Can you explain what is the user case you want this feature? If it's to have the agent loading some models before user join the room, you can use the prewarm feature of the agent.

I am building an app where the user can create a room, join, and speak to an "AI." In my implementation, the server creates a room and an access token, and returns the access token to the client. The client then joins the created room, and an agent instance gets assigned to the user via automatic dispatch.

Now, the tricky part is that, the user may leave the call for whatever reason (e.g. connectivity issues or simply by accident), and it can take the user more than 20 seconds to reconnect. In such a scenario, if the user reconnects after 20 seconds, the automatic dispatch would not trigger, and the user would only find an empty room.

In my case, I assume, there would be no harm in allowing the agent to just sit there, even if the user left, because I have another supervisor process cleaning up rooms that existed for too long, but if that is not possible, since the timeout is not configurable, I assume one solution would be to just delete the room when the user leaves, and create another one if necessary.

ghost avatar Jul 02 '25 11:07 ghost

I assume one solution would be to just delete the room when the user leaves, and create another one if necessary.

I think so. I guess you just need to generate a new access token with a new random room id if user left for awhile.

longcw avatar Jul 02 '25 11:07 longcw

what in my case @longcw see as we are working livekit sip for outbound call after making the call instructions was played for whole 25 sec without interuptions and after that call get disconncted and i also shared logs for same

Smshendehub avatar Jul 02 '25 13:07 Smshendehub

Exact requirement as you have mentioned, We are building an Interviewing platform and getting many reports of candidate's getting disconnected due to network issues. However because of short timeout, agent disconnects and their session gets over. Please look into it, very important.

hari01584 avatar Jul 07 '25 08:07 hari01584