How to make a tool call that the agent does not wa...
# ask-ai
g
How to make a tool call that the agent does not wait for. Instead it continues on while the tool call happens in the background. When tool call finishes then we can process it.
t
Thanks for reaching out, Aumesh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks for reaching out! Just to make sure I understand correctly, are you asking about how to make asynchronous API calls within LiveKit, or is this about a particular feature or integration? Also, would you like some help with managing the response after the call finishes? I'm here to help you through it!
g
I want to make tool calls that I don’t have to wait for a response, but when it does respond it pipes the data to the agent
t
I’m glad you’re exploring how to make tool calls that the agent doesn’t have to wait for and can process the response once it’s ready. You can achieve this by defining asynchronous functions using the
@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