Is there any way to force the agent to not speak t...
# ask-ai
w
Is there any way to force the agent to not speak the LLM response if the LLM response contained a tool call?
t
Thanks for reaching out, Alex. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you want to stop your agent from speaking out the LLM response whenever it includes a tool call, a handy way is to override the
llm_node
method in your agent. This lets you peek at each piece of the LLM response and skip the text if it has a tool call. Here’s a simple example to get you started:
Copy code
class CustomAgent(Agent):
    async def llm_node(self, chat_ctx, tools, model_settings):
        # Grab the original response from the parent class
        async for chunk in super().llm_node(chat_ctx, tools, model_settings):
            if isinstance(chunk, ChatChunk) and chunk.delta.tool_calls:
                # Don’t speak the response if it includes a tool call
                continue
            yield chunk
With this approach, any response that has a tool call won’t be sent to the TTS system, so it won’t be spoken out loud. Hope this helps you out!