wonderful-wolf-51568
10/25/2025, 8:32 PMtall-airline-16756
10/25/2025, 8:32 PMtall-airline-16756
10/25/2025, 8:33 PMcancel_tool_reply() function inside the function_tools_executed event handler. This way, the old agent won’t generate any speech once the handoff is triggered.
Here’s a simple example to guide you:
@session.on("function_tools_executed")
def on_function_tools_executed(ev: FunctionToolsExecutedEvent):
if ev.has_agent_handoff:
ev.cancel_tool_reply() # This stops the agent from replying after the handoff
Using this approach will make sure the handoff happens smoothly and silently. If you have any questions or want me to walk you through it further, just let me know—I’m here to help!
Sources: livekit-agents/livekit/agents/voice/run_result.py | Tool definition and use | LiveKit Docswonderful-wolf-51568
10/25/2025, 9:04 PMtall-airline-16756
10/25/2025, 9:04 PMcancel_tool_reply() is applied just for a specific handoff tool. You can do this by checking the tool's name inside the function_tools_executed event. Here’s a simple example to guide you:
@session.on("function_tools_executed")
def on_function_tools_executed(ev: FunctionToolsExecutedEvent):
# Extract all tool names from the function calls
tool_names = [fnc.name for fnc in ev.function_calls]
# Cancel reply only if the specific handoff tool was called
if "your_handoff_tool_name" in tool_names:
ev.cancel_tool_reply()
This way, the reply gets canceled only when that particular tool runs. If you have any questions or need a hand with anything else, please don’t hesitate to ask—I’m here to help!
Sources: livekit-agents/livekit/agents/voice/agent_activity.py | Events and error handling | LiveKit Docs | Tool definition and use | LiveKit Docs