My bot is not always saying the text that is passe...
# ask-ai
c
My bot is not always saying the text that is passed to it through on_enter() method. Why is it so?
t
Thanks for reaching out, Subham. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hi there! I understand it can be a bit tricky when your bot doesn’t always say the text passed through the
on_enter()
method. Let’s walk through some common reasons together: • Use of
say()
vs. `generate_reply()`:
It’s best to use
session.say()
for more predictable results since
generate_reply()
might not always stick to the exact text you provide. • Missing TTS Plugin: Double-check that you have a TTS plugin (like
openai.TTS()
) set up in your agent’s constructor. • Missing `await`: Remember to use
await
with
session.say()
so the speech coroutine runs properly. • Conditional Logic: Take a look at your code to see if any conditions might be preventing
say()
from being called. • Session Initialization: Make sure the session starts correctly and that
on_enter()
is actually being triggered. • Custom Overrides: If you’ve customized the
tts_node()
method, review it to see if it might be changing or suppressing the text. Going through these steps should really help your bot speak consistently. If you have any questions or need more help, I’m here for you! Sources: Realtime model integrations | LiveKit Docs | flows/multi_stage_flow.py | tests/test_agent_session.py
c
does session.say() need to await? it's a sync function or async function?
t
session.say()
is an asynchronous function in LiveKit, so it’s important to call it with
await
. Here’s a simple example:
Copy code
await session.say("Hello! How can I assist you?")
Using
await
helps make sure the function runs smoothly and your speech is generated just right. If you have any more questions or need a hand with anything else, feel free to ask—I’m here to help! Sources: Agent speech and audio | LiveKit Docs | flows/simple_flow.py
c
what about session.generate_reply?
t
session.generate_reply()
is an asynchronous function in Python, so you'll want to use
await
when you need to wait for it to finish. Here's a little example to help:
Copy code
response = await session.generate_reply("What is your name?")
For JavaScript/TypeScript, the function runs synchronously, but it returns a
SpeechHandle
object that you can await if you want. If anything feels unclear or you'd like me to walk you through it more, just let me know—I'm here to help! Sources: tracking_state/npc_character.py | plugins/google/src/beta/realtime/realtime_api.ts | livekit-plugins/livekit-plugins-ultravox/livekit/plugins/ultravox/realtime/... | Agent speech and audio | LiveKit Docs | main.py
c
in which version of livekit is generate_reply an async function?
t
session.generate_reply()
is actually not an
async
function in LiveKit. Instead, it works as a synchronous method that returns an
asyncio.Future
, which you can await if you want to. This approach has been consistent in all the documented versions of LiveKit, and there’s no sign that it ever changed to being an
async
function. If you’d like me to explain this further or have any other questions, please feel free to ask—I’m here to help! Sources: Agent speech and audio | LiveKit Docs | Agent speech and audio | LiveKit Docs | livekit-agents/livekit/agents/llm/realtime.py | pipeline-llm/openai_llm.py
c
in function_tools, can I return json objects as the tool output?
t
Hi there! Just to clarify, the function tools in LiveKit can give you Python dictionaries or JavaScript objects, but before they’re sent to the LLM, they’re automatically turned into JSON strings. So, the LLM always gets the final output as a string, not a raw JSON object. If you have any more questions or need me to explain anything further, please don’t hesitate to ask—I’m here to help! Sources: Tool definition and use | LiveKit Docs | livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti... | mcp_client/util.py | agents/src/voice/generation.ts