Can I make a tool call during agent session uninte...
# ask-ai
a
Can I make a tool call during agent session uninterruptable by the user? I would like the agent to call a tool, and if a user says something then the agent wont cancell the tool call or try to answe my question before the tool call returns but it waits for the tool call to finish, and replies to the question after getting the tool context
t
Thanks for reaching out, Michał. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m replying about making a tool call uninterruptible during an agent session (so the agent waits for the tool result even if the user speaks). Yes — you can prevent user interruptions so the agent waits for the tool to finish before responding. Use the RunContext API to disable interruptions at the start of the tool call. How to implement it (high level) 1. Add a
context: RunContext
parameter to your tool function. 2. Call
context.disallow_interruptions()
at the beginning of the tool. 3. Run your asynchronous or long-running operation. 4. Return the tool result — the agent will then resume handling user input and reply using the tool’s context. Example
Copy code
@function_tool()
async def my_uninterruptible_tool(self, context: RunContext):
    # Disable interruptions for this tool
    context.disallow_interruptions()

    # Perform the long-running async operation
    result = await some_async_operation()

    return result
Notes and best practices • While interruptions are disabled, user speech will not cancel the tool or be acted on until the tool returns. • For long operations, consider sending an in-session message (for example with
session.generate_reply()
before you start) to let the user know the agent is processing and will reply when the operation finishes. • This works for both regular tools and tasks in the LiveKit Agents framework. If you’d like, tell me: • whether your tool is CPU-bound or network-bound, • an expected run time, and • if you want a user-visible progress/status update, and I’ll suggest the best pattern (e.g., sending a pre-start reply, polling/status updates, or breaking the work into cancellable chunks). Sources: Tool definition and use | LiveKit Documentation | External data and RAG | LiveKit Documentation