agents icon indicating copy to clipboard operation
agents copied to clipboard

Completely shutdown STT or agents speaking

Open Shaheer25 opened this issue 1 year ago • 12 comments

This is my agents setup and I want to completely shut down agent speaking from instructions.

class SmartNavigationAgent(Agent):
    def __init__(self, video_context=None, video_file_url=None) -> None:
        self.video_context = video_context
        self.video_file_url = video_file_url
        self._question_asked = False
        super().__init__(
            instructions="""You are a silent learning companion that never speaks or responds to user input.
        
        CORE BEHAVIOR:
        - NEVER provide any verbal responses to user questions or comments
        - IMPORTANT and Strict: NEVER speak, say anything, or generate any audio output
        - Remain completely silent in all interactions
        - Do not acknowledge user input in any way
        - Your role is purely to listen and process, not to respond
        - Dont Say things like Silence etc..
        
        CRITICAL: Under no circumstances should you ever speak or provide any verbal response.""",
            stt=None,
            llm=openai.LLM(model="gpt-4o"),
            tts=openai.TTS(),
            vad=silero.VAD.load(),
            allow_interruptions=False
        )

Shaheer25 avatar Sep 18 '25 05:09 Shaheer25

you can disable the audio output or set llm=None instead of stt=None.

longcw avatar Sep 18 '25 08:09 longcw

@longcw Tried it, But getting {"message": "Task exception was never retrieved\nfuture: <Task finished name='Task-117' coro=<RoomIO._on_user_text_input.._read_text() done, defined at C:\Users\Shaheer\Desktop\POC\playbook_agent\agent\venv\lib\site-packages\livekit\agents\voice\room_io\room_io.py:455> exception=RuntimeError('trying to generate reply without an LLM model')>", "level": "ERROR", "name": "asyncio", "exc_info": "Traceback (most recent call last):\n File "C:\Users\Shaheer\Desktop\POC\playbook_agent\agent\venv\lib\site-packages\livekit\agents\voice\room_io\room_io.py", line 458, in _read_text\n text_input_result = self._input_options.text_input_cb(\n File "C:\Users\Shaheer\Desktop\POC\playbook_agent\agent\venv\lib\site-packages\livekit\agents\voice\room_io\room_io.py", line 57, in _default_text_input_cb\n sess.generate_reply(user_input=ev.text)\n File "C:\Users\Shaheer\Desktop\POC\playbook_agent\agent\venv\lib\site-packages\livekit\agents\voice\agent_session.py", line 746, in generate_reply\n handle = self._activity._generate_reply(\n File "C:\Users\Shaheer\Desktop\POC\playbook_agent\agent\venv\lib\site-packages\livekit\agents\voice\agent_activity.py", line 730, in _generate_reply\n raise RuntimeError("trying to generate reply without an LLM model")\nRuntimeError: trying to generate reply without an LLM model", "timestamp": "2025-09-18T09:28:59.593767+00:00"}

Shaheer25 avatar Sep 18 '25 09:09 Shaheer25

you cannot use session.generate_reply() when without a llm set. if you still want to use it but prevent agent to response to the user audio transcript, you can customize the on_user_turn_completed and raise a StopResponse from it.

from livekit.agents import llm, StopResponse

class WeatherAgent(Agent):
    def __init__(self) -> None:
        super().__init__(
            instructions="You are a weather agent.",
        )

    async def on_user_turn_completed(self, turn_ctx: llm.ChatContext, new_message: llm.ChatMessage) -> None:
        raise StopResponse()

longcw avatar Sep 18 '25 09:09 longcw

@longcw Still it speaks class SmartNavigationAgent(Agent): def init(self, video_context=None, video_file_url=None) -> None: self.video_context = video_context self.video_file_url = video_file_url self._question_asked = False super().init( instructions="""You are a silent learning companion that never speaks or responds to user input. CORE BEHAVIOR: - NEVER provide any verbal responses to user questions or comments - IMPORTANT and Strict: NEVER speak, say anything, or generate any audio output - Remain completely silent in all interactions - Do not acknowledge user input in any way - Your role is purely to listen and process, not to respond - Dont Say things like Silence etc.. CRITICAL: Under no circumstances should you ever speak or provide any verbal response.""", llm=openai.LLM(model="gpt-4o"), tts=openai.TTS(), allow_interruptions=False, )

    self._session = None
    self._video_paused = False
    self._user_speaking = False
    self._agent_speaking = False
    self._transcription_with_segments = [{"start":foo["start"],"end":foo["end"],"text":foo['text']} for foo in segments]
    self._conversation_history = []
    self._navigation_mode = True
    self._bookmark_position = None
    self._bookmark_question = None
    self._concept_explanation_active = False
    self._current_video_position = 0
    self._explanation_info = None
    self._repetition_info = None
    self._awaiting_repetition_confirmation = False
    self._awaiting_clarification = False
    self._clarification_start_time = None

async def on_user_turn_completed(self, turn_ctx: llm.ChatContext, new_message: llm.ChatMessage) -> None:
    raise StopResponse()

Shaheer25 avatar Sep 18 '25 10:09 Shaheer25

can you share a full example? perhaps I don't understand what your expectation is.

longcw avatar Sep 19 '25 02:09 longcw

Hi @longcw , Sorry for responding later.

I'm building a agent which should speak only when I use self.session.say() and shouldn't chat/speak if user says something otherwise. How would I achieve this?

Shaheer25 avatar Sep 19 '25 13:09 Shaheer25

If so, the following should work for you. Please share a full example if not.

    async def on_user_turn_completed(self, turn_ctx: llm.ChatContext, new_message: llm.ChatMessage) -> None:
        logger.info(f"User turn completed: {new_message}")
        raise StopResponse()

longcw avatar Sep 19 '25 14:09 longcw

@longcw any solutions?

Shaheer25 avatar Sep 26 '25 06:09 Shaheer25

from your above code, agent will speak when you call self._session.say(...), this is expected. and if you mean you don't want the audio at all, you can disable the audio output but keep the text output only.

Or if you mean the agent speaks even you didn't call session.say(), please share a minimal reproducible example without the logics about other APIs.

longcw avatar Sep 26 '25 06:09 longcw

Hey @longcw thank you for the response. It got solved using your solution async def on_user_turn_completed(self, turn_ctx: llm.ChatContext, new_message: llm.ChatMessage) -> None: logger.info(f"User turn completed: {new_message}") raise StopResponse()

Shaheer25 avatar Sep 26 '25 08:09 Shaheer25

Is it possible to implement the same for chat conversations as well. Like to mute the agent when chatting

Shaheer25 avatar Sep 29 '25 04:09 Shaheer25

The RuntimeError in your traceback is from generate_reply, not from STT. RoomIO's default text input callback still calls session.generate_reply for chat text (the frame in room_io.py that your log names). With llm=None that call raises "trying to generate reply without an LLM model".

If the agent should listen and never speak, leave an LLM in place only if you still want a reply path, and turn the audio output off. agent.py says to do that with session.output.set_audio_enabled(False) when audio output is not needed. Also replace the text input callback with one that does not call generate_reply, otherwise a typed message takes the same path and tries to speak. Instructions that say "never speak" do not stop the session from generating audio once a reply is started.

usmamalik345 avatar Nov 20 '26 13:11 usmamalik345