glamorous-oil-12326
09/22/2025, 8:24 PMtall-airline-16756
09/22/2025, 8:24 PMtall-airline-16756
09/22/2025, 8:24 PMglamorous-oil-12326
09/22/2025, 10:23 PMtall-airline-16756
09/22/2025, 10:24 PM@function_tool decorator in your agent class. LiveKit takes care of running these asynchronously and makes sure the results come back to your agent’s context smoothly.
Here’s a quick rundown to help you get started:
• Define your tool as an async function and decorate it with @function_tool.
• Kick off the background task with asyncio.ensure_future.
• Manage interruptions gracefully using run_ctx.speech_handle.wait_if_not_interrupted.
• Return the tool’s result so it automatically flows back to the agent.
If you’d like, I’d be happy to provide a detailed code example or walk you through any part that feels unclear. Just let me know!
Sources: livekit-agents/livekit/agents/voice/agent_activity.py | agents/src/voice/agent_activity.ts