I have an Agent Task that must return either false...
# ask-ai
b
I have an Agent Task that must return either false or true depending on a user answer. what has a greater impact on the agent choice: function_tool descriptions or general llm instructions?
t
Thanks for reaching out, mateuszkasprowicz. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I understand how important it is to have clear guidance when choosing the right tools. The description field of a function tool plays a crucial role here—it helps the language model decide if the tool is the best fit for the situation. Think of it as a helpful nudge that points the agent in the right direction. On the other hand, general LLM instructions are more like the agent’s overall personality and style—they shape how responses are crafted but don’t directly influence which tool gets picked. So, to make sure the tools are used effectively and accurately, focusing on clear and specific tool descriptions really makes all the difference. Sources: agents/src/voice/agent_activity.ts | Tool definition and use | LiveKit docs | Building an Automated IVR Menu Caller | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_activity.py
b
how to make sure not speech is generated after a tool call?
t
I'm happy to help you ensure no speech is generated after a tool call! You have a couple of friendly options to achieve this: • Cancel the tool reply: You can use
ev.cancel_tool_reply()
within the
function_tools_executed
event handler. Here's a simple example to guide you:
Copy code
@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:
Copy code
@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.py
b
any other ideas specifically for this task? class QuestionAnsweredComprehensively(AgentMixin, AgentTask[bool]): """Task to check if the question was answered comprehensively.""" def *__init__*( self, _chat_ctx_: ChatContext | None = None, _evaluation_criteria_: str | None = None, _expected_duration_: int | None = None, ): instructions = get_evaluation_criteria(_evaluation_criteria_, _expected_duration_) voice_stack = build_default_voice_stack(_llm_kwargs_={"tool_choice": "required"}) super().__init__(_chat_ctx_=_chat_ctx_, instructions=instructions, **voice_stack) async def *on_enter*(self): """Initialize the agent and ask the question.""" self.session.say( text=self.session.userdata.question_prompt, _allow_interruptions_=False ) @function_tool() async def *confirm_comprehensive_answer*(self) -> bool: """Mark that the current question has been answered comprehensively. Use this tool when, based on the evaluation_criteria and expected_duration provided in the context, the candidate's answer is complete, correct, clear, relevant, and SUFFICIENTLY DETAILED. """ self.complete(True) return True @function_tool async def *decline_comprehensive_answer*(self) -> bool: """Mark that the current question has not yet been answered comprehensively. Use this tool when there are significant gaps, errors, lack of clarity, or insufficient depth in the candidate's answer. It also applies when the content is off-topic and further detail or clarification would be helpful. """ self.complete(False) return False
t
I’m happy to help you make sure no speech is generated after a tool call in your custom
AgentTask
. 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:
Copy code
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:
Copy code
@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.ts
b
any other options?
t
I'd love to share some additional options to help you prevent speech generation after a tool call: 1. Use
StopResponse
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.
Copy code
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:
Copy code
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