how can i download livekit's turn detector plugin ...
# ask-ai
p
how can i download livekit's turn detector plugin during docker image build? I'm getting this error:
Copy code
14 [10/10] RUN python main.py download-files
#14 1.784 2025-10-22 23:37:56.959478580 [W:onnxruntime:Default, device_discovery.cc:164 DiscoverDevicesForPlatform] GPU device discovery failed: device_discovery.cc:89 ReadFileContents Failed to open file: "/sys/class/drm/card0/device/vendor"
#14 2.115 :package: Downloading model files...
#14 2.186 Traceback (most recent call last):
#14 2.186   File "/home/appuser/main.py", line 184, in <module>
#14 2.186     EnglishModel()     # Download English turn detector model (~66 MB)
#14 2.186     ^^^^^^^^^^^^^^
#14 2.186   File "/home/appuser/.local/lib/python3.11/site-packages/livekit/plugins/turn_detector/english.py", line 26, in __init__
#14 2.186     super().__init__(model_type="en", unlikely_threshold=unlikely_threshold)
#14 2.186   File "/home/appuser/.local/lib/python3.11/site-packages/livekit/plugins/turn_detector/base.py", line 161, in __init__
#14 2.186     self._executor = inference_executor or get_job_context().inference_executor
#14 2.186                                            ^^^^^^^^^^^^^^^^^
#14 2.186   File "/home/appuser/.local/lib/python3.11/site-packages/livekit/agents/job.py", line 46, in get_job_context
#14 2.186     raise RuntimeError(
#14 2.186 RuntimeError: no job context found, are you running this code inside a job entrypoint?
#14 ERROR: process "/bin/sh -c python main.py download-files" did not complete successfully: exit code: 1
------
 > [10/10] RUN python main.py download-files:
2.186     EnglishModel()     # Download English turn detector model (~66 MB)
2.186     ^^^^^^^^^^^^^^
2.186   File "/home/appuser/.local/lib/python3.11/site-packages/livekit/plugins/turn_detector/english.py", line 26, in __init__
2.186     super().__init__(model_type="en", unlikely_threshold=unlikely_threshold)
2.186   File "/home/appuser/.local/lib/python3.11/site-packages/livekit/plugins/turn_detector/base.py", line 161, in __init__
2.186     self._executor = inference_executor or get_job_context().inference_executor
2.186                                            ^^^^^^^^^^^^^^^^^
2.186   File "/home/appuser/.local/lib/python3.11/site-packages/livekit/agents/job.py", line 46, in get_job_context
2.186     raise RuntimeError(
2.186 RuntimeError: no job context found, are you running this code inside a job entrypoint?
------
Error: failed to fetch an image or build from source: error building: failed to solve: process "/bin/sh -c python main.py download-files" did not complete successfully: exit code: 1
Error: Process completed with exit code 1.
t
Thanks for reaching out, Vaneeza. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I understand the error you're seeing happens because the
get_job_context()
function is being called outside of a job entrypoint. This is totally expected during Docker builds since, at that stage, no job context exists yet. To help you download the turn detector plugin's model files while building your Docker image, you can explicitly trigger the download with this command:
Copy code
python my_agent.py download-files
This command will download the necessary model weights and tokenizer files directly to the local cache, so it doesn’t depend on any job context. Just make sure your Dockerfile includes this step right after installing your dependencies. For example:
Copy code
COPY requirements.txt .
RUN pip install -r requirements.txt

# Download turn detector model files during build
COPY my_agent.py .
RUN python my_agent.py download-files

COPY . .
By doing this, the model files will be pre-downloaded into your Docker image, helping you avoid any issues with downloads at runtime. If you have any questions or need further help, feel free to ask! Sources: livekit-agents/livekit/agents/ipc/job_thread_executor.py
p
how to explicitly download it when no job context exists?
t
Hey there! If you'd like to explicitly download the LiveKit turn detector plugin model files when there's no job context available, you can simply run this command:
Copy code
python my_agent.py download-files
This handy command will fetch all the necessary model files for you, including the ONNX model weights, tokenizer data, and language configuration files, straight from the Hugging Face Hub. It works smoothly without needing any job context and makes sure these files are saved locally so they're ready to go when you need them for inference. If you're working with Node.js, no worries—you can use:
Copy code
node your_agent.ts download-files
Or, if you're using the starter template with
pnpm
, just run:
Copy code
pnpm download-files
Following these steps will help you have all the necessary assets pre-downloaded and ready before runtime, making your experience smoother. If you have any questions or need a hand, feel free to ask! Sources: livekit-plugins/livekit-plugins-turn-detector/livekit/plugins/turn_detector... | plugins/livekit/src/turn_detector/base.ts
p
whats my agent.py
t
Just to clarify, the term
my_agent.py
is simply a placeholder for your own Python script that starts and runs your LiveKit agent. If you don’t mind, could you share the name of the script you’re using or tell me a bit more about how your setup looks? I’m here to help you through this!
p
i have done this but i get this error.
Copy code
{
  "message": "unhandled exception while running the job task\nTraceback (most recent call last):\n File \"/home/appuser/.local/lib/python3.11/site-packages/opentelemetry/util/_decorator.py\", line 71, in async_wrapper\n return await func(*args, **kwargs) # type: ignore\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/home/appuser/.local/lib/python3.11/site-packages/livekit/agents/ipc/job_proc_lazy_main.py\", line 240, in _traceable_entrypoint\n await self._job_entrypoint_fnc(job_ctx)\n File \"/home/appuser/main.py\", line 147, in entrypoint\n turn_detector = EnglishModel()\n ^^^^^^^^^^^^^^\n File \"/home/appuser/.local/lib/python3.11/site-packages/livekit/plugins/turn_detector/english.py\", line 26, in __init__\n super().__init__(model_type=\"en\", unlikely_threshold=unlikely_threshold)\n File \"/home/appuser/.local/lib/python3.11/site-packages/livekit/plugins/turn_detector/base.py\", line 166, in __init__\n config_fname = _download_from_hf_hub(\n ^^^^^^^^^^^^^^^^^^^^^^\n File \"/home/appuser/.local/lib/python3.11/site-packages/livekit/plugins/turn_detector/base.py\", line 28, in _download_from_hf_hub\n local_path = hf_hub_download(repo_id=repo_id, filename=filename, **kwargs)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/home/appuser/.local/lib/python3.11/site-packages/huggingface_hub/utils/_validators.py\", line 114, in _inner_fn\n return fn(*args, **kwargs)\n ^^^^^^^^^^^^^^^^^^^\n File \"/home/appuser/.local/lib/python3.11/site-packages/huggingface_hub/file_download.py\", line 1010, in hf_hub_download\n return _hf_hub_download_to_cache_dir(\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/home/appuser/.local/lib/python3.11/site-packages/huggingface_hub/file_download.py\", line 1117, in _hf_hub_download_to_cache_dir\n _raise_on_head_call_error(head_call_error, force_download, local_files_only)\n File \"/home/appuser/.local/lib/python3.11/site-packages/huggingface_hub/file_download.py\", line 1649, in _raise_on_head_call_error\n raise LocalEntryNotFoundError(\nhuggingface_hub.errors.LocalEntryNotFoundError: Cannot find the requested files in the disk cache and outgoing traffic has been disabled. To enable hf.co look-ups and downloads online, set 'local_files_only' to False.",
  "level": "ERROR",
  "name": "livekit.agents",
  "pid": 717,
  "job_id": "AJ_ouxLPDA9JpdG",
  "timestamp": "2025-10-23T19:47:37.062840+00:00"
}
t
It looks like the error is happening because the necessary model files for the turn detector plugin aren’t found in your local disk cache, and outgoing traffic is currently disabled. No worries though! To get everything up and running smoothly, you’ll just need to pre-download the model files before starting the agent. If you’re using Python, simply run this command:
Copy code
python your_agent_script.py download-files
For Node.js, depending on your setup, you can use one of these commands:
Copy code
pnpm download-files
Copy code
node ./your_agent.ts download-files
These commands will download all the required files—like the ONNX model, tokenizer, and configuration files—from the Hugging Face Hub directly to your local cache. Just make sure to complete this step before starting the agent, especially if you’re working in an environment without internet access. If you need any help along the way, feel free to reach out! Sources: plugins/livekit/src/index.ts | examples/voice_agents/realtime_turn_detector.py
p
i am doing this but still getting this error when worker runs. this is y docker file which runs this command.
Copy code
# This is an example Dockerfile that builds a minimal container for running LK Agents
# syntax=docker/dockerfile:1
ARG PYTHON_VERSION=3.11.6
FROM python:${PYTHON_VERSION}-slim

# Keeps Python from buffering stdout and stderr to avoid situations where
# the application crashes without emitting any logs due to buffering.
ENV PYTHONUNBUFFERED=1

# Create a non-privileged user that the app will run under.
# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user
ARG UID=10001
RUN adduser \
    --disabled-password \
    --gecos "" \
    --home "/home/appuser" \
    --shell "/sbin/nologin" \
    --uid "${UID}" \
    appuser


# Install gcc and other build dependencies.
RUN apt-get update && \
    apt-get install -y \
    gcc \
    python3-dev \
    && rm -rf /var/lib/apt/lists/*

USER appuser

RUN mkdir -p /home/appuser/.cache
RUN chown -R appuser /home/appuser/.cache

WORKDIR /home/appuser

COPY requirements.txt .
RUN python -m pip install --user --no-cache-dir -r requirements.txt

COPY . .

# ensure that any dependent models are downloaded at build-time
RUN python main.py download-files

# expose healthcheck port
EXPOSE 8080

# Run the application.
CMD ["python", "main.py", "start"]
t
It sounds like the issue might be happening because the model files downloaded during the Docker build aren’t being saved properly or might be getting overwritten when you run the container. Let’s walk through some steps together to make sure those files are cached and ready to go: 1. First, double-check that the
RUN python main.py download-files
command is placed right after all your dependencies are installed, but before the final runtime stage in your Dockerfile. 2. Next, take a look at your
.dockerignore
file to make sure it’s not accidentally excluding the cache directories where Hugging Face stores models (like
~/.cache/huggingface
). 3. Also, if you’re using runtime volume mounts (maybe with Kubernetes or docker-compose), make sure they aren’t overwriting the model cache directory, which could hide the files you downloaded earlier. 4. To help debug, you can add this step in your Dockerfile to check what’s inside the cache:
Copy code
RUN ls -R ~/.cache/huggingface/
This command will let you see if the model files are actually there during the build. If you’re still running into trouble, it’s worth checking that environment variables like
HF_HOME
or
TRANSFORMERS_CACHE
aren’t changing where the cache is stored unexpectedly. Sources: Agent Deployment & Docker Configuration | livekit/livekit_composite | DeepW... | livekit-agents/livekit/agents/voice/audio_recognition.py | plugins/livekit/src/index.ts | Voice AI quickstart | LiveKit Docs | LiveKit turn detector plugin | LiveKit Docs