glamorous-oil-12326
12/26/2025, 8:45 PMtall-airline-16756
12/26/2025, 8:45 PMtall-airline-16756
12/26/2025, 8:45 PMcontext.speech_handle.interrupted, but that only lets you clean up, not resume mid-execution.
Options to resolve or mitigate:
• Prevent interruptions during critical work: call context.disallow_interruptions() at the start of the tool to keep it from being cancelled.
• Implement external state persistence: save progress periodically (database or in-memory store) so the tool can restart and continue from the last saved checkpoint after an interruption.
• Re-initiate on resume: when a session restarts, detect the incomplete operation (session state) and prompt the agent/user to restart or continue from saved progress.
To give targeted guidance, can you tell me:
1. What kind of tool is being interrupted (API request, file processing, long computation, etc.)?
2. Are you currently using context.disallow_interruptions() or allow_interruptions=False anywhere?
3. Do you observe any error messages or logs when the interruption happens?
4. Would you prefer preventing interruptions entirely, or adding resumable checkpoints so the tool can continue after a restart?
Answering those will let me recommend concrete code patterns or storage approaches.
Sources: Tool definition and use | LiveKit docs | Turns overview | LiveKit docsglamorous-oil-12326
12/26/2025, 8:51 PMtall-airline-16756
12/26/2025, 8:51 PMcontext.speech_handle.interrupted. That lets you clean up and signal the agent that the operation ended prematurely.
• Persist partial progress (database, cache, session state) so on next turn the agent can inspect state and decide whether to retry, continue from a checkpoint, or abandon.
• Use explicit retry logic in the agent: after an interruption, have the agent ask the user whether to retry or automatically re-invoke the tool based on session/state rules.
• Prevent interruptions for critical sections with context.disallow_interruptions() when you need the operation to run to completion.
Minimal code example for detection and cleanup
@function_tool()
async def my_long_running_task(self, context: RunContext):
wait_for_result = asyncio.ensure_future(self._long_operation())
await context.speech_handle.wait_if_not_interrupted([wait_for_result])
if context.speech_handle.interrupted:
wait_for_result.cancel()
# persist any partial state here if useful
return None
else:
return await wait_for_result
Suggested flow to let the agent decide
1. Tool runs and writes checkpoints/partial results to storage.
2. If interrupted, tool returns/cleans up (and optionally notes interruption in session state).
3. On the next agent turn, check session/state:
◦ If state shows an incomplete operation, either prompt the user (“Resume previous task?”) or automatically re-invoke the tool with resume parameters.
◦ If no resume desired, clear the incomplete state.
If you tell me what type of tool and what state you can store (DB, Redis, in-memory), I can suggest a concrete retry/resume pattern or sample code tailored to your case.