colossal-xylophone-68609
03/27/2026, 12:31 PMtall-airline-16756
03/27/2026, 12:31 PMtall-airline-16756
03/27/2026, 12:31 PMsession.say() and sessions inside an agent:
• You must start the AgentSession before calling session.say().
• session.say() depends on the session’s media pipeline and agent state being initialized, so calling it on a session that hasn’t been started will not produce the expected audio behavior.
• Typical usage patterns:
a. Call await session.start() (or start the session via the agent lifecycle).
b. Then call session.say() either from an agent lifecycle method (for example on_enter) or from code that runs after the session has started.
If you want, tell me which language or example you’re using (or share a short snippet) and I can show the exact sequence you should use.
Sources: Agent speech and audio | LiveKit Documentation | ElevenLabs Change Language | LiveKit Documentation | Playing Audio | LiveKit Documentation, with interactive elementscolossal-xylophone-68609
03/30/2026, 11:27 AMtall-airline-16756
03/30/2026, 11:27 AMawait session.say(msg), execution will wait until the agent finishes speaking the entire message (or the playback is interrupted) before moving on to the next line of code. Internally, session.say() returns a speech handle and awaiting it is equivalent to waiting for the play-out to complete, so your code will be paused until speech playback finishes.
If you want non-blocking behavior, tell me which language/runtime you’re using and I can show an example pattern (for example, start the speech without awaiting the handle or run it in a background task) so the rest of your code can continue while audio plays.
Sources: Agent speech and audio | LiveKit Documentation | How to detect when an agent has finished speaking | LiveKit, with interactive elementscolossal-xylophone-68609
03/30/2026, 11:33 AMtall-airline-16756
03/30/2026, 11:33 AMapi.LiveKitAPI needs to be referenced from a session or passed around, or if you can just use it directly in any function.
Short answer
• You can instantiate and use api.LiveKitAPI in any function — it does not need to be tied to an AgentSession or passed through a session object.
Key details and best practices
• LiveKitAPI is a server-side client for LiveKit APIs (room/participant/SIP/dispatch management). It operates independently of a session/room connection.
• You must provide the required credentials (URL, API key, secret) when creating the client.
• Call await lkapi.aclose() (or the language-equivalent close) when you’re done to free resources.
• For performance and simplicity, prefer reusing or caching a client instance rather than creating a new one on every call—especially inside hot paths or worker loops.
When you might pass it around
• If your function already has lifetime-managed resources (for example, a long-running worker, an agent process, or request-scoped objects), you may pass the LiveKitAPI instance as a parameter to avoid re-instantiation.
• Passing the same client also makes testing easier (you can inject a mock).
If you’d like, I can:
• Show an example in the language you’re using (Python, Node, etc.).
• Suggest a reuse/caching pattern appropriate for your architecture (singleton in server, dependency injection, or request-scoped client).
Which language or code structure are you using?
Sources: Python SDKs | livekit/livekit_composite | DeepWiki | Outbound Calling Script | LiveKit Documentation | Python Agents: Handling exceptions in your entrypoint | LiveKit, with interactive elements