How to avaoid multiple tool calls at once, for exa...
# ask-ai
m
How to avaoid multiple tool calls at once, for example I write a function_tool for call_transfer when I ask my transfer_my call to agent it starts call_transfer but sometime it calls the function two times
t
Thanks for reaching out, Rajadurai. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The knowledge base does not show a built-in mechanism for preventing multiple or duplicate calls to a
function_tool
(such as
call_transfer
) in LiveKit. However, the examples demonstrate some common practices you can adopt: • State Tracking: Before executing
call_transfer
, check a local or session variable to ensure a transfer isn't already in progress. • Conditional Logic: Perform validation at the start of your tool—such as verifying that a transfer has not already been initiated for the current session/context—to prevent repeated execution. • Sequential Execution Model: Typical tool execution in LiveKit is sequential, meaning new tool calls wait for previous ones to finish; leverage this, but do not rely solely on it for idempotency. You'll need to handle these safeguards in your function implementation; the system does not enforce idempotency or lock out duplicate calls automatically. Sources: complex-agents/medical_office_triage/triage.py | examples/voice_agents/restaurant_agent.py
m
how to check funnction is running ?
t
Hey there! Let me break down how you can keep tabs on whether a
function_tool
(like
call_transfer
) is currently running. Think of it like tracking a friend's progress – we've got a few friendly ways to do this: • Keep an ear out for the `FunctionToolsExecutedEvent`: It's like getting a notification when a task is complete. By watching which tool calls have finished, you can easily figure out which ones are still in the works. • Agent State Checking: When the agent is in the
thinking
state, it means a tool is being worked on. You can listen for
agent_state_changed
events to get the full picture. • Your Personal Tracking: For those special or longer-running tools, create a personal status flag (like
is_transfer_running
) in your session. Think of it as your own little progress tracker – set it when something starts, and clear it once you know it's done. Just between us, there's no straightforward public API to directly check running functions. But don't worry – by using completion events and keeping track of your own state, you'll be a pro at monitoring tool progress in no time! Sources: livekit-agents/livekit/agents/voice/agent_activity.py | Handling RAG Delays in Voice Agents | LiveKit Docs | telephony/warm_handoff.py