acoustic-businessperson-48819
04/21/2026, 1:27 PMtall-airline-16756
04/21/2026, 1:27 PMtall-airline-16756
04/21/2026, 1:28 PMsession.generate_reply() (e.g., “Let me look into that for you…”).
3. Let the agent continue accepting/handling other turns while the background task runs.
4. When the task completes, deliver the result by:
◦ Sending a follow-up reply (TTS) when appropriate, or
◦ Storing result state and notifying the user via an event/RPC to the UI if you want non-verbal notification first.
1. Handle interruptions, cancellations, and errors cleanly (cancel the task if needed and raise a ToolError to surface failures).
Minimal example sketch
async def handle_request(context, query):
# 1) start background job
bg = asyncio.ensure_future(do_long_work(query))
# 2) immediate verbal acknowledgement
await context.session.generate_reply(instructions="Let me look into that for you.")
# 3) continue processing other conversation turns while bg runs
# Later: await result (in another handler/turn) and respond
result = await bg
await context.session.generate_reply(instructions=f"Right — based on the results: {result}")
Best practices
• Use context.speech_handle.wait_if_not_interrupted() if you need to synchronize speech with tool state or cancel if the user interrupts.
• For mutating operations, call context.disallow_interruptions() while performing the critical section to avoid partial state.
• Provide periodic or continuous feedback for very long ops (short status TTS, "thinking" audio, or UI progress via RPC).
• Pre-synthesize common acknowledgement TTS to reduce perceived latency.
• Always surface failures gracefully (raise a ToolError or send a clear error reply).
If you want, I can:
• Convert the sketch into a full runnable example tied to your agent framework,
• Show how to notify a web UI via LiveKit RPC when results are ready,
• Or add interruption/cancellation handling for your specific use case. Which would be most helpful? Sources: Function tool definition | LiveKit Documentation | External data and RAG | LiveKit Documentation | https://docs.livekit.io/agents/logic/tools/definition.md| | Bring your LangChain Agents to LiveKit | LiveKit, with interactive elementsacoustic-businessperson-48819
04/21/2026, 2:31 PMAsyncToolset what i need?tall-airline-16756
04/21/2026, 2:32 PMAsyncToolset in the docs I can access. It may be a new/experimental API or a library-specific helper outside the materials I see.
To answer whether it’s what you need, can you tell me:
• Where you found AsyncToolset (link or repo/package name)?
• Do you need background task scheduling only, or also built-in interruption, progress updates, and UI/RPC notifications?
• Any constraints (must use pure asyncio, run inside the agent process, or be cancellable from the client)?
If you share that, I’ll confirm whether it fits your long-running call pattern and either show how to use it or map the recommended asyncio + session.generate_reply() pattern to it.
Sources: AsyncAI TTS plugin guide | LiveKit Documentation | An open source stack for real-time multimodal AI | LiveKit | Voice Agent Architecture: STT, LLM, and TTS Pipelines Explained | LiveKit | https://docs.livekit.io/agents/logic/tools/definition.md| | Function tool definition | LiveKit Documentation, with interactive elements