What happens when my function tool times out? Does...
# ask-ai
c
What happens when my function tool times out? Does it recall the same function?
t
Thanks for reaching out, Subham. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking what happens when a function tool times out and whether LiveKit will automatically recall the same function. LiveKit does not automatically recall or retry a function tool after a timeout. If a tool call times out and you haven't implemented retry logic, the call ends and the LLM receives no result (or an error if raised). To retry, you need to implement explicit retry handling in your tool (for example, a retry loop around
asyncio.wait_for()
or a wrapper that re-invokes the function). For long-running work, consider returning an early status update (e.g., "processing...") or running the operation as a separate async task and canceling the timeout task if the operation finishes first. Sources: External data and RAG | LiveKit Docs
c
Copy code
2025-12-15 16:08:26,089 - DEBUG livekit.agents - received user transcript {"room": "playground-rnBD-Lofr", "user_transcript": "me do your human", "language": "en-IN", "pid": 23504, "job_id": "AJ_tKnVvKEwRDDU"}
2025-12-15 16:08:26,099 - INFO livekit.agents - EOU metrics {"room": "playground-rnBD-Lofr", "end_of_utterance_delay": 0.62, "transcription_delay": 0.62, "pid": 23504, "job_id": "AJ_tKnVvKEwRDDU"}
2025-12-15 16:08:26,398 - INFO livekit.agents - LLM metrics {"room": "playground-rnBD-Lofr", "model_name": "openai/gpt-oss-120b", "model_provider": "<http://api.groq.com|api.groq.com>", "ttft": 0.3, "prompt_tokens": 3543, "prompt_cached_tokens": 3328, "completion_tokens": 56, "tokens_per_second": 187.94, "pid": 23504, "job_id": "AJ_tKnVvKEwRDDU"}
2025-12-15 16:08:26,403 - DEBUG livekit.agents - executing tool {"room": "playground-rnBD-Lofr", "function": "transfer_call", "arguments": "{\"reason\":\"User requested to speak with a human\"}", "speech_id": "speech_65154ac02a6a", "pid": 23504, "job_id": "AJ_tKnVvKEwRDDU"}
2025-12-15 16:08:26,403 - INFO agent - [room: playground-rnBD-Lofr] -- SIP_TRUNK_ID: ST_sic2q5UZsU64, HUMAN_AGENT_NUMBER: +916364276271, ROOM_NAME: playground-rnBD-Lofr {"room": "playground-rnBD-Lofr", "pid": 23504, "job_id": "AJ_tKnVvKEwRDDU"}
2025-12-15 16:08:27,299 - INFO livekit.agents - TTS metrics {"room": "playground-rnBD-Lofr", "model_name": "sonic-3", "model_provider": "Cartesia", "ttfb": 0.20620383299683454, "audio_duration": 2.93, "pid": 23504, "job_id": "AJ_tKnVvKEwRDDU"}
2025-12-15 16:08:30,047 - INFO livekit.agents - STT metrics {"room": "playground-rnBD-Lofr", "model_name": "nova-3", "model_provider": "Deepgram", "audio_duration": 5.0, "pid": 23504, "job_id": "AJ_tKnVvKEwRDDU"}
2025-12-15 16:08:35,097 - INFO livekit.agents - STT metrics {"room": "playground-rnBD-Lofr", "model_name": "nova-3", "model_provider": "Deepgram", "audio_duration": 5.05, "pid": 23504, "job_id": "AJ_tKnVvKEwRDDU"}
2025-12-15 16:08:40,098 - INFO livekit.agents - STT metrics {"room": "playground-rnBD-Lofr", "model_name": "nova-3", "model_provider": "Deepgram", "audio_duration": 5.0, "pid": 23504, "job_id": "AJ_tKnVvKEwRDDU"}
2025-12-15 16:08:44,892 - INFO livekit.agents - LLM metrics {"room": "playground-rnBD-Lofr", "model_name": "openai/gpt-oss-120b", "model_provider": "<http://api.groq.com|api.groq.com>", "ttft": 0.31, "prompt_tokens": 3574, "prompt_cached_tokens": 3328, "completion_tokens": 69, "tokens_per_second": 222.56, "pid": 23504, "job_id": "AJ_tKnVvKEwRDDU"}
2025-12-15 16:08:44,897 - DEBUG livekit.agents - executing tool {"room": "playground-rnBD-Lofr", "function": "transfer_call", "arguments": "{\"reason\":\"User requested to speak with a human\"}", "speech_id": "speech_91dacbea5c18", "pid": 23504, "job_id": "AJ_tKnVvKEwRDDU"}
2025-12-15 16:08:44,898 - INFO agent - [room: playground-rnBD-Lofr] -- SIP_TRUNK_ID: ST_sic2q5UZsU64, HUMAN_AGENT_NUMBER: +916364276271, ROOM_NAME: playground-rnBD-Lofr {"room": "playground-rnBD-Lofr", "pid": 23504, "job_id": "AJ_tKnVvKEwRDDU"}
2025-12-15 16:08:44,898 - INFO agent - Transfer already in progress, ignoring duplicate call {"room": "playground-rnBD-Lofr", "pid": 23504, "job_id": "AJ_tKnVvKEwRDDU"}
2025-12-15 16:08:45,148 - INFO livekit.agents - STT metrics {"room": "playground-rnBD-Lofr", "model_name": "nova-3", "model_provider": "Deepgram", "audio_duration": 5.05, "pid": 23504, "job_id": "AJ_tKnVvKEwRDDU"}
2025-12-15 16:08:46,004 - INFO livekit.agents - TTS metrics {"room": "playground-rnBD-Lofr", "model_name": "sonic-3", "model_provider": "Cartesia", "ttfb": 0.21625504099938553, "audio_duration": 3.25, "pid": 23504, "job_id": "AJ_tKnVvKEwRDDU"}
2025-12-15 16:08:48,399 - DEBUG livekit.agents - tools execution completed {"room": "playground-rnBD-Lofr", "speech_id": "speech_91dacbea5c18", "pid": 23504, "job_id": "AJ_tKnVvKEwRDDU"}
2025-12-15 16:08:48,399 - INFO agent - [room: playground-rnBD-Lofr] --function tools executed: ['transfer_call']
How can I prevent the double call?
t
You're asking how to stop the duplicate
transfer_call
invocations shown in your logs. The simplest, reliable fix is to make the transfer tool idempotent by tracking transfer state in the session and short-circuiting duplicate attempts. Suggested implementation (concise): 1. Add a session flag (e.g.,
userdata.transfer_in_progress = False
) when the AgentSession is created. 2. At the start of
transfer_call
, check the flag: ◦ If True, return immediately (log/notify "Transfer already in progress"). ◦ If False, set it to True before doing any async work. 1. Perform the transfer. 2. On transfer failure, reset the flag to False so retries are allowed; on success leave it True (or clear only after you know the transfer completed/ended if you want later transfers). 3. Optionally add a timeout to clear the flag if the transfer hangs. Key points: • Set the flag immediately to avoid race conditions when the LLM triggers the tool multiple times. • Return a clear message when a duplicate call is detected so logs/metrics show the intent was ignored. • Reset the flag only on explicit failure or after a safe timeout if you want retries. If you want, I can provide a short Python snippet that fits into your existing
transfer_call
tool. Would you like that? Sources: Agents telephony integration | LiveKit docs | Tool definition and use | LiveKit docs