broad-painter-9222
11/17/2025, 3:28 PMtall-airline-16756
11/17/2025, 3:28 PMtall-airline-16756
11/17/2025, 3:29 PMbroad-painter-9222
11/17/2025, 4:02 PMtall-airline-16756
11/17/2025, 4:02 PMev.cancel_tool_reply() within the function_tools_executed event handler. Here's a simple example to guide you:
@session.on("function_tools_executed")
def on_function_tools_executed(ev: FunctionToolsExecutedEvent):
tools = (fnc.name for fnc in ev.function_calls)
if "turn_off_light" in tools:
ev.cancel_tool_reply() # This stops speech from being generated
• Make sure the tool function doesn’t return a value: If your tool function returns None, it won’t automatically generate a reply. Here’s a quick example:
@function_tool()
async def turn_on_light(self):
"""Called when user asks to turn on the light."""
self.light_on = True
# No return value means no automatic speech reply
Just a little heads-up: if you're working with a Realtime Model that auto-generates tool replies, sometimes replies might still appear even if you cancel them, and a warning will be logged in those cases. I hope this helps clarify things! Please feel free to ask if you'd like me to walk you through any part of this.
Sources: livekit-agents/livekit/agents/voice/agent_activity.pybroad-painter-9222
11/17/2025, 4:03 PMtall-airline-16756
11/17/2025, 4:04 PMAgentTask. You can achieve this by setting the replyRequired parameter to false when you return the tool output. This way, the system won’t generate a verbal response after the tool finishes running.
Here’s a simple example to guide you on how to adjust the return behavior of your tool:
return ToolExecutionOutput(
toolCall=tool_call,
toolCallOutput=tool_call_output,
agentTask=None,
rawOutput=result,
rawException=None,
replyRequired=False # Prevents speech generation
)
If you’re working with RunContext, you can handle this during the execution step like this:
@function_tool
async def my_tool(self, ctx: RunContext):
# Perform tool logic
result = await long_running_operation()
# Return without requiring a reply
return ToolExecutionOutput(
toolCall=ctx.function_call,
toolCallOutput=FunctionCallOutput(output=result),
replyRequired=False
)
This approach makes sure the agent stays silent when you don’t need a verbal response. If you have any more questions or need further clarification, feel free to ask—I’m here to support you!
Sources: agents/src/voice/agent_activity.tsbroad-painter-9222
11/17/2025, 4:18 PMtall-airline-16756
11/17/2025, 4:19 PMStopResponse to gracefully end the conversation: If you'd like the conversation to stop right after the tool call, simply return a StopResponse. This will pause any further processing, including speech generation.
if (isStopResponse(this.exception)) {
return _SanitizedOutput.create({
toolCall: FunctionCall.create({ ...this.toolCall }),
});
}
1. Disable auto-reply through Realtime Model settings: When working with a Realtime Model, you can configure it to turn off autoToolReplyGeneration. This way, automatic speech replies won’t be triggered after the tool runs.
1. Switch to a new Agent Task: If your current agent hands off to a new agent using newAgentTask, you can bypass speech generation depending on how the new task is set up. For example:
if (!ignoreTaskSwitch && newAgentTask !== null) {
this.agentSession.updateAgent(newAgentTask);
draining = true; // Suppresses speech
}
These approaches offer you flexibility, whether you want to end the session, let the LLM take the lead, or smoothly transition control to another task. If you have any questions or want to explore these options further, I’m here to help!
Sources: agents/src/voice/generation.ts