AgentSession.__init__() got an unexpected keyword ...
# ask-ai
c
AgentSession.__init__() got an unexpected keyword argument 'before_tts_cb'
t
Thanks for reaching out, faiq. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I see you're hitting the error: AgentSession.*init*() got an unexpected keyword argument 'before_tts_cb' This means the
AgentSession
constructor does not accept a parameter named
before_tts_cb
. The
AgentSession
options include things like
stt
,
llm
,
tts
,
vad
, and
turn_detection
, but
before_tts_cb
is not a supported init argument. What you can do instead • Override the TTS node in a custom
Agent
subclass to run preprocessing before text is sent to the TTS engine. This is the supported way to inject logic before TTS runs. • Example pattern to override `tts_node`:
Copy code
async def tts_node(self, text: AsyncIterable[str], model_settings: ModelSettings) -> AsyncIterable[rtc.AudioFrame]:
    # custom text preprocessing can go here
    async for frame in Agent.default.tts_node(self, text, model_settings):
        # custom audio postprocessing can go here
        yield frame
Next steps for me to help further • If you want, paste the code where you construct
AgentSession
(the init call) and the
Agent
subclass you’re using. • Tell me whether you intended
before_tts_cb
to modify the text before TTS, or to change audio after TTS — that will determine whether to put logic in
tts_node
(pre/post) or another node. If you share the snippet, I can show exactly how to move your callback logic into
tts_node
or another appropriate hook. Sources: Agent session | LiveKit Documentation | Pipeline nodes and hooks | LiveKit Documentation