Completely shutdown STT or agents speaking
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
)
you can disable the audio output or set llm=None instead of stt=None.
@longcw Tried it, But getting
{"message": "Task exception was never retrieved\nfuture: <Task finished name='Task-117' coro=<RoomIO._on_user_text_input.
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 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()
can you share a full example? perhaps I don't understand what your expectation is.
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?
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 any solutions?
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.
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()
Is it possible to implement the same for chat conversations as well. Like to mute the agent when chatting
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.