Does pre-emptive still work on the latest livekit ...
# ask-ai
p
Does pre-emptive still work on the latest livekit implementations esp with agents? We cant find any flag for setting it up in the agent session? Do we need to set it up somewhere else?
t
Thanks for reaching out, Basit. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm glad you asked about pre-emptive generation! It's supported in the latest LiveKit implementations, but currently, this feature is available only in the Python SDK. To turn it on, you'll want to set the
preemptive_generation
parameter to
True
when you initialize an
AgentSession
. Here's a little example to help you out:
Copy code
session = AgentSession(
    preemptive_generation=True,
    # other parameters...
)
Just so you know, this parameter defaults to
False
. This feature is specially designed for STT-LLM-TTS pipeline agents and works best when the STT node returns final transcripts faster than the VAD sends the
end_of_speech
event. Also, make sure you have a turn detection model enabled for it to function smoothly. If you happen to be using another SDK like Node.js or JavaScript, pre-emptive generation isn’t supported yet. But don’t worry—if you want, I’d be happy to help you explore ways to optimize latency in those environments. Just let me know! Sources: Agent speech and audio | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_activity.py | Agent Session & Activity Management | livekit/livekit_composite | DeepWiki
p
We are using 1.1.5 version. eHere is the error I get. It says the parameter for preemptive_generaitgon doesnt exist: 2025-10-13 134412,049 - ERROR livekit.agents - unhandled exception while running the job task Traceback (most recent call last): File “/home/abdullah/Desktop/voice-ai-multiagent-backend/app.py”, line 1241, in entrypoint session = AgentSession[UserData](**{**session_kwargs, “preemptive_generation”: True}) File “/home/abdullah/anaconda3/lib/python3.10/typing.py”, line 957, in call result = self.__origin__(*args, **kwargs) TypeError: AgentSession.__init__() got an unexpected keyword argument ‘preemptive_generation’ {“pid”: 74768, “job_id”: “AJ_mHnSYWzNcMwG”}
t
It looks like the error might be happening because the 'preemptive_generation' parameter isn’t supported in the version of the LiveKit Python SDK you’re currently using. To help you better, could you please share a few details with me? • Which exact version of the
livekit-agents
package do you have installed? You can find out by running
pip show livekit-agents
. • Are you using the
preemptive_generation
parameter with the
AgentSession
class, or is it being passed to a different class? • Would you be able to share the full error traceback? That will help pinpoint exactly where the problem is coming from. Once I have this information, I’ll be in a much better position to guide you on whether an upgrade or another solution might be the best next step. Looking forward to helping you get this sorted! Sources: livekit-plugins/livekit-plugins-google/livekit/plugins/google/realtime/real... | Agent speech and audio | LiveKit Docs | Agent Session & Activity Management | livekit/livekit_composite | DeepWiki
p
We are using livekit-agents 1.1.7. We are using it with AgentSession Trceback: 2025-10-13 134412,049 - ERROR livekit.agents - unhandled exception while running the job task Traceback (most recent call last): File “/home/abdullah/Desktop/voice-ai-multiagent-backend/app.py”, line 1241, in entrypoint session = AgentSession[UserData](**{**session_kwargs, “preemptive_generation”: True}) File “/home/abdullah/anaconda3/lib/python3.10/typing.py”, line 957, in call result = self.__origin__(*args, **kwargs) TypeError: AgentSession.__init__() got an unexpected keyword argument ‘preemptive_generation’ {“pid”: 74768, “job_id”: “AJ_mHnSYWzNcMwG”}
t
Thank you for reaching out! The
preemptive_generation
parameter is supported in
livekit-agents
version 1.1.7, so the error you're seeing might be due to a version mismatch or something in your environment. Let’s try a few steps to get this sorted out: 1. First, please check the installed version of
livekit-agents
by running
pip show livekit-agents
. We want to make sure it’s version 1.1.7. 2. If it’s not the right version, you can upgrade it with
pip install --upgrade livekit-agents
. 3. Sometimes cached files can cause trouble, so try clearing them using
pip cache purge
and then reinstall the package. 4. Also, double-check that you’re working in the correct Python environment where the package is installed. If you still run into issues after trying these steps, please don’t hesitate to reach out again. I’m here to help and we’ll figure this out together! Sources: Agent speech and audio | LiveKit Docs | Agent Session & Activity Management | livekit/livekit_composite | DeepWiki | Quotas and limits | LiveKit Docs | tests/test_agent_session.py
p
Here is the class description of AgentSession from agent_session.py. as you can see there is no preemptive_generation
class AgentSession(rtc.EventEmitter[EventTypes], Generic[Userdata_T]): def __init__( self, *, turn_detection: NotGivenOr[TurnDetectionMode] = NOT_GIVEN, stt: NotGivenOr[stt.STT] = NOT_GIVEN, vad: NotGivenOr[vad.VAD] = NOT_GIVEN, llm: NotGivenOr[llm.LLM | llm.RealtimeModel] = NOT_GIVEN, tts: NotGivenOr[tts.TTS] = NOT_GIVEN, mcp_servers: NotGivenOr[list[mcp.MCPServer]] = NOT_GIVEN, userdata: NotGivenOr[Userdata_T] = NOT_GIVEN, allow_interruptions: bool = True, discard_audio_if_uninterruptible: bool = True, min_interruption_duration: float = 0.5, min_interruption_words: int = 0, min_endpointing_delay: float = 0.5, max_endpointing_delay: float = 6.0, max_tool_steps: int = 3, video_sampler: NotGivenOr[_VideoSampler | None] = NOT_GIVEN, user_away_timeout: float | None = 15.0, min_consecutive_speech_delay: float = 0.0, conn_options: NotGivenOr[SessionConnectOptions] = NOT_GIVEN, loop: asyncio.AbstractEventLoop | None = None,
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!
p
Here is the class description of AgentSession from agent_session.py. as you can see there is no preemptive_generation class AgentSession(rtc.EventEmitter[EventTypes], Generic[Userdata_T]): def __init__( self, *, turn_detection: NotGivenOr[TurnDetectionMode] = NOT_GIVEN, stt: NotGivenOr[stt.STT] = NOT_GIVEN, vad: NotGivenOr[vad.VAD] = NOT_GIVEN, llm: NotGivenOr[llm.LLM | llm.RealtimeModel] = NOT_GIVEN, tts: NotGivenOr[tts.TTS] = NOT_GIVEN, mcp_servers: NotGivenOr[list[mcp.MCPServer]] = NOT_GIVEN, userdata: NotGivenOr[Userdata_T] = NOT_GIVEN, allow_interruptions: bool = True, discard_audio_if_uninterruptible: bool = True, min_interruption_duration: float = 0.5, min_interruption_words: int = 0, min_endpointing_delay: float = 0.5, max_endpointing_delay: float = 6.0, max_tool_steps: int = 3, video_sampler: NotGivenOr[_VideoSampler | None] = NOT_GIVEN, user_away_timeout: float | None = 15.0, min_consecutive_speech_delay: float = 0.0, conn_options: NotGivenOr[SessionConnectOptions] = NOT_GIVEN, loop: asyncio.AbstractEventLoop | None = None,