```await self._agent_session.say()``` throws Runt...
# ask-ai
l
Copy code
await self._agent_session.say()
throws RuntimeError("AgentSession isn't running"). How to put a check
t
Thanks for reaching out, Deepak. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're seeing RuntimeError("AgentSession isn't running") when calling
await self._agent_session.say()
. To avoid that, you can either ensure the session is started before calling
say()
or handle the error when it occurs. Two safe patterns: 1) Await start and track state
Copy code
self._session_started = False

await self._agent_session.start()
self._session_started = True

# before saying
if self._session_started:
    await self._agent_session.say("Hello")
else:
    # handle not-started case
2) Catch the RuntimeError
Copy code
try:
    await self._agent_session.say("Hello")
except RuntimeError as e:
    if str(e) == "AgentSession isn't running":
        # handle gracefully (log, retry, start session, etc.)
    else:
        raise
Which approach fits your code flow better — do you prefer ensuring start completes before calls or handling transient missing-starts with retries? Sources: Turn detection and interruptions | LiveKit Docs | Agent session | LiveKit docs