Hi LiveKit Team, I had a question regarding agent ...
# ask-ai
h
Hi LiveKit Team, I had a question regarding agent capabilities in LiveKit. Is it possible to execute a tool (for example, an API call or backend operation) in the background while the agent continues to handle ongoing user queries in real time? More specifically, I’m trying to achieve a multitasking flow where: • A user request triggers a tool execution • The tool runs asynchronously (non-blocking) • Meanwhile, the agent continues the conversation with the user • Once the tool completes, the agent can return the result to the user Does LiveKit provide built-in support or recommended patterns for this kind of concurrent tool execution within voice agents?
✅ 1
t
Thanks for reaching out, Sahil. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to your question about running tools asynchronously while the agent continues the conversation. Short answer: LiveKit tools can run asynchronously (they’re async functions and can call external APIs), but a tool call blocks the agent’s current LLM reasoning cycle and the agent cannot process new user turns concurrently in the same session. In other words, true multitasking where the agent actively handles new queries while a tool runs in the background is not supported natively. Recommended patterns to achieve similar behavior: • Immediately acknowledge the user (e.g., “I’ll check that now”) with
session.say()
or
session.generate_reply()
so the conversation stays responsive, then start the async tool. • Run the long task outside the blocking LLM turn (e.g., push a job to your backend, queue, or an RPC/forwarding endpoint) and return control to the user. When the job completes, push the result back into the session or start a new reply from the agent (via an event or webhook). • Use
context.disallow_interruptions()
for critical operations you don’t want interrupted, and use
SpeechHandle.interrupt()
to cancel interim speech when results arrive. • Provide verbal status updates or “thinking” audio to improve user experience while waiting. If you want, tell me which pattern you prefer (in-session async with immediate ack, external job queue + callback, or forwarding to frontend), and I’ll give a concise implementation outline and code pointers. Sources: Function tool definition | LiveKit Documentation | Audio customization | LiveKit Documentation | External data and RAG | LiveKit Documentation | The ReAct Pattern for Voice Agents and How AI Agents Think, Act, and Respon... | Forwarding to the frontend | LiveKit Documentation, with interactive elements