iam going to self host the livekit ai bot while cr...
# ask-ai
m
iam going to self host the livekit ai bot while creating docker file and run that iam getting error of downloadfiles i tried to change the docker file added download files command it succesed but still when run same error i also tried to run download files with the docker run images download-files then run in docker run image dev also the same error then how to get off this error of downlaodfiles
t
Thanks for reaching out, Rithwikreddy. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I hear your frustration. You’re getting a persistent
download-files
error when trying to self-host the LiveKit AI bot with Docker, and you’ve already tried adding the download step both in the Dockerfile and by running one-off containers but the error keeps happening. I can help — first I’ll explain the most reliable fixes, then I’ll ask a couple quick questions so I can give a precise next step for your setup. Why this usually happens (short) • Files downloaded in a temporary container or at runtime are not preserved unless they are included in the image during build or written to a mounted volume. That’s why running
download-files
in a one-off
docker run
often “succeeds” but you still see the error when you run your service container later. What you can do (recommended order) 1) Best: run
download-files
during image build so model files are baked into the image • Add a RUN step in your Dockerfile after copying your app code: ◦ Example flow: i. COPY your source (e.g.,
COPY src ./src
) ii. RUN the download step:
RUN uv run src/agent.py download-files
iii. Then set user and CMD as usual • This ensures files persist in the built image and aren’t lost between runs. 2) Alternative: persist files with a Docker volume if you must download at runtime • Create or use a named volume to store the model cache: ◦ First run to download into volume: docker run -v model-cache:/app/.cache my-agent-image uv run src/agent.py download-files • Then run your service using same volume: docker run -v model-cache:/app/.cache my-agent-image uv run src/agent.py dev • Make sure your agent uses that path (for example set ENV HF_HUB_CACHE=/app/.cache/huggingface if needed). 3) If you downloaded in a container once and expect them to persist: that won’t work unless you committed the container as an image or used a volume. One-off containers are ephemeral. Quick checks and debugging steps • Confirm files exist inside the built image: docker run --rm my-agent-image ls -R ~/.cache/huggingface/hub • Confirm the path your agent expects (for example
~/.cache/huggingface/hub
or a custom
HF_HUB_CACHE
). • Ensure you COPY your source into the image before the RUN download step. If the download command references a script (e.g.,
src/agent.py
), that file must be present in the image layer where you run it. • If you get permission errors, run the download as root during build and switch to non-root user afterward. If you want, I can give an exact Dockerfile snippet tailored to your project. To do that, please share: • The current Dockerfile you’re using (or paste the relevant parts). • The exact command you run that shows the
download-files
error and the full error text (or a screenshot). • Where your agent script lives (for example
src/agent.py
) and the cache path you expect (default:
~/.cache/huggingface/hub
or if you set
HF_HUB_CACHE
). If you paste those, I’ll point out the exact change to fix this and provide a final Docker build/run example you can copy-paste. Sources: examples/bank-ivr | livekit/livekit_composite | DeepWiki | examples/survey | livekit/livekit_composite | DeepWiki | Updating the Turn Detector Model | LiveKit | LiveKit turn detector plugin | LiveKit Documentation | examples/voice_agents | livekit/livekit_composite | DeepWiki
m
FROM python:3.10-slim AS runtime # Create non-root user RUN groupadd --gid 1000 avoice && \ useradd --uid 1000 --gid avoice --shell /bin/bash --create-home avoice WORKDIR /app # Install runtime dependencies only RUN apt-get update && apt-get install -y --no-install-recommends \ libpq5 \ curl \ && rm -rf /var/lib/apt/lists/* # Copy virtual environment from builder COPY --from=builder /opt/venv /opt/venv ENV PATH="/opt/venv/bin:$PATH" # Copy application code COPY --chown=avoice:avoice . . # Switch to non-root user USER avoice this is how docke file is build in my bot
t
Thanks — that Dockerfile snippet helps a lot. I can see why you keep hitting the
download-files
error: your Dockerfile shows a runtime stage that copies a virtualenv from a builder stage, but I don’t see the builder stage or any step that runs
download-files
during build. That means model files are likely being downloaded (or attempted) at container runtime into an ephemeral container and aren’t persisted for subsequent runs. What to fix (short) • Run
download-files
during image build (in the builder stage) or persist the files to a volume. Don’t rely on a one-off
docker run
to permanently save them unless you use a volume or commit the container. Recommended changes — two options 1) Preferred: download during build (embed files in image) • Add a builder stage that installs dependencies, copies source, and runs: RUN uv run src/agent.py download-files • Copy the resulting venv and downloaded files into the runtime stage. High-level example flow (replace paths/commands to match your project): 1. Builder stage: install build deps, create venv, pip install, COPY source, RUN download-files 2. Runtime stage (your current stage): COPY venv from builder, COPY app files, USER non-root, CMD start 2) If you must download at runtime: use a named volume • First run (downloads into volume): docker run -v model-cache:/app/.cache my-agent-image uv run src/agent.py download-files • Then run service with same volume: docker run -v model-cache:/app/.cache my-agent-image uv run src/agent.py dev • Make sure your agent uses that cache path or set ENV HF_HUB_CACHE=/app/.cache/huggingface Concrete suggestions tailored to your snippet • I can help produce a concrete Dockerfile. To do that I need either: ◦ Your full current Dockerfile (including the missing builder stage), or ◦ The path to the agent script you run (e.g.,
src/agent.py
) and the exact command you use for download and start. Helpful debugging commands to run now • Check if files exist in the built image: docker run --rm my-agent-image ls -R /home/avoice/.cache/huggingface/hub • If your download command references
src/agent.py
, ensure that file is present in the layer where you run
download-files
. • If you see permission errors, run the download as root in build, then switch to
USER avoice
. If you want, paste: • Your full Dockerfile (including builder stage), and • The exact error output you see when running the container. I’ll then give a ready-to-copy Dockerfile snippet (or a volume-based run sequence) that resolves the
download-files
error.
m
# AVoice Agent Dockerfile # Multi-stage build for production-like containerization # # Phase 4.26: Containerize the agent for Docker Compose stack # # Build: docker build -t avoice-agent . # Run: docker run --env-file .env avoice-agent # ============================================================================ # Stage 1: Builder # ============================================================================ FROM python:3.10-slim AS builder WORKDIR /build # Install build dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ gcc \ libpq-dev \ && rm -rf /var/lib/apt/lists/* # Create virtual environment RUN python -m venv /opt/venv ENV PATH="/opt/venv/bin:$PATH" # Install Python dependencies # NOTE: In production, use a requirements.txt or pyproject.toml with locked deps COPY pyproject.toml ./ # Install core dependencies (adjust as needed for your project) RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir \ livekit-agents>=0.12.0 \ livekit-api>=0.8.0 \ livekit-plugins-openai \ livekit-plugins-deepgram \ livekit-plugins-turn-detector \ livekit-plugins-silero \ livekit-plugins-elevenlabs \ aiohttp>=3.9.0 \ asyncpg>=0.29.0 \ redis>=5.0.0 \ python-dotenv>=1.0.0 # ============================================================================ # Stage 2: Runtime # ============================================================================ FROM python:3.10-slim AS runtime # Create non-root user RUN groupadd --gid 1000 avoice && \ useradd --uid 1000 --gid avoice --shell /bin/bash --create-home avoice WORKDIR /app # Install runtime dependencies only RUN apt-get update && apt-get install -y --no-install-recommends \ libpq5 \ curl \ && rm -rf /var/lib/apt/lists/* # Copy virtual environment from builder COPY --from=builder /opt/venv /opt/venv ENV PATH="/opt/venv/bin:$PATH" # Copy application code COPY --chown=avoice:avoice . . # Switch to non-root user USER avoice exactly where to add exact lines
t
Thanks — this is perfect. I’ll show exactly where to add the
download-files
step in your multi-stage Dockerfile and explain why. I’ll also include a ready-to-copy snippet for the builder stage and a small runtime note. Where to add it • Add the
RUN uv run <path-to-agent> download-files
command in the builder stage after you install dependencies and after you COPY your application code into the builder. That ensures the download runs during image build and the files are baked into the image. Exact change (what to add) • In the builder stage, copy your app into /build (so the script exists), then run the download step. Keep the runtime stage unchanged except for using the venv copied from builder (as you already do). Example Dockerfile changes (insert into your builder stage) 1. After installing Python deps, add: COPY . /build RUN uv run src/agent.py download-files 1. Keep the rest of your builder stage (venv already created and deps installed), then your runtime stage can remain the same. Full builder-stage example (copy-paste and adapt
src/agent.py
to your agent path)
Copy code
FROM python:3.10-slim AS builder

WORKDIR /build

# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc \
    libpq-dev \
    && rm -rf /var/lib/apt/lists/*

# Create virtual environment
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"

# Install Python dependencies
COPY pyproject.toml ./
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir \
    livekit-agents>=0.12.0 \
    livekit-api>=0.8.0 \
    livekit-plugins-openai \
    livekit-plugins-deepgram \
    livekit-plugins-turn-detector \
    livekit-plugins-silero \
    livekit-plugins-elevenlabs \
    aiohttp>=3.9.0 \
    asyncpg>=0.29.0 \
    redis>=5.0.0 \
    python-dotenv>=1.0.0

# Copy application source into builder so download command can run
COPY . /build

# Run download-files during build so model files are baked into image
# Replace `src/agent.py` with the path to your agent entrypoint if different
RUN uv run src/agent.py download-files
Why this works • Running
download-files
during build puts the model/cache files into the image layers. When you copy
/opt/venv
and your app from builder into runtime, those downloaded files remain available — you won’t rely on ephemeral containers or manual downloads at runtime. Runtime notes (keep as-is, with small checks) • Keep your runtime stage that copies
/opt/venv
from builder and switches to non-root. • If your agent expects the HF cache at a specific path, ensure the
download-files
step writes to that path (default is
~/.cache/huggingface/hub
). If you want a custom location in the image, set: ENV HF_HUB_CACHE=/app/.cache/huggingface before running the download step in builder and ensure runtime uses the same path. If you prefer volumes instead (alternative) • If you cannot bake files into the image, download once into a named volume and reuse it: ◦ docker run -v model-cache:/app/.cache my-agent-image uv run src/agent.py download-files ◦ docker run -v model-cache:/app/.cache my-agent-image uv run src/agent.py dev Two quick clarifying questions so I can give the final exact Dockerfile: • Is your agent entrypoint script
src/agent.py
(or a different path)? • Do you rely on a custom HF cache path or the default
~/.cache/huggingface/hub
? Tell me those and I’ll paste your complete multi-stage Dockerfile with the exact lines in the right places.
m
path is apps.agent.agent_v2
t
Thanks — that path helps. Below is a ready-to-use multi-stage Dockerfile that runs the
download-files
step during the builder stage using your agent entrypoint
apps.agent.agent_v2
. This bakes the downloaded model files into the image so you won’t hit the ephemeral-container
download-files
error at runtime. Copy this into your project (adapt any package list or paths if needed):
Copy code
# AVoice Agent Dockerfile (multi-stage)
# Build: docker build -t avoice-agent .
# Run: docker run --env-file .env avoice-agent

# ======================================================================
# Stage 1: Builder
# ======================================================================
FROM python:3.10-slim AS builder

WORKDIR /build

# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc \
    libpq-dev \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Create virtual environment
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"

# Copy dependency manifest and install Python dependencies
COPY pyproject.toml ./
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir \
    livekit-agents>=0.12.0 \
    livekit-api>=0.8.0 \
    livekit-plugins-openai \
    livekit-plugins-deepgram \
    livekit-plugins-turn-detector \
    livekit-plugins-silero \
    livekit-plugins-elevenlabs \
    aiohttp>=3.9.0 \
    asyncpg>=0.29.0 \
    redis>=5.0.0 \
    python-dotenv>=1.0.0

# Copy application source into builder so the agent script is available
COPY . /build

# Optional: set HF cache inside image (uncomment & adjust if you want custom path)
# ENV HF_HUB_CACHE=/app/.cache/huggingface

# Run download-files during build so model files are baked into the image
# Use your provided agent module: apps.agent.agent_v2
RUN uv run apps.agent.agent_v2 download-files

# ======================================================================
# Stage 2: Runtime
# ======================================================================
FROM python:3.10-slim AS runtime

# Create non-root user
RUN groupadd --gid 1000 avoice && \
    useradd --uid 1000 --gid avoice --shell /bin/bash --create-home avoice

WORKDIR /app

# Install runtime dependencies only
RUN apt-get update && apt-get install -y --no-install-recommends \
    libpq5 \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Copy virtual environment (with installed deps) from builder
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"

# Copy application code into runtime image and set ownership
COPY --chown=avoice:avoice . .

# Switch to non-root user
USER avoice

# Default command (adjust to your dev/start command)
CMD ["uv", "run", "apps.agent.agent_v2", "dev"]
Notes and checks • I used
uv run apps.agent.agent_v2 download-files
exactly as you specified. If your package entrypoint differs (for example a different module name or script), replace it accordingly. • If your agent writes the Hugging Face cache to the default (
~/.cache/huggingface/hub
) that path will be inside the image and available at runtime. If you want the cache in a different path, uncomment and set
ENV HF_HUB_CACHE=/app/.cache/huggingface
before the RUN that calls
download-files
. • Keep the
RUN uv run ... download-files
in the builder stage — that’s the key to persistence. • If you get permission errors when the agent later tries to write to the cache at runtime, ensure downloads are performed in builder (as shown) and that at runtime the process has write permission only where needed. Running the download as root during build and switching to non-root at runtime avoids many permission issues. If you’d like, I can: • Adjust the Dockerfile to use a specific
HF_HUB_CACHE
path (tell me which), or • Provide the volume-based alternative (download at runtime into a named volume) if you prefer not to embed model files in the image. Tell me which option you prefer (embed in image with a custom cache path, or volume-based), or paste any error output if building still fails and I’ll help debug.
m
164157.521 DEBUG… filelock Attempting to release lock 140291431376320 on /root/.cache/huggingface/hub/.lock… 164157.524 DEBUG… filelock Lock 140291431376320 released on /root/.cache/huggingface/hub/.lock… {"timestamp": "2026-02-21T164157.528305Z", "level": "INFO", "logger": "livekit.agents", "message": "Finished downloading files for livekit.plugins.turn_detector"} 164157.528 INFO … livekit.agents Finished downloading files for livekit.plugins.turn_detector and the error i got is still is 164322.526 ERROR… livekit.…_detector Could not find file "languages.json". Make sure you have downloaded the model before running the agent. Use
Copy code
python3
                                           your_agent.py download-files
to download the model. {"timestamp": "2026-02-21T164322.534261Z", "level": "INFO", "logger": "livekit.agents", "message": "process exiting"} {"pid": 39, "job_id": "AJ_Gm59eQNH8XCY", "room_id": "RM_WhfkQYeKfRs2"} 164322.534 INFO … livekit.agents process exiting {"timestamp": "2026-02-21T164322.537495Z", "level": "ERROR", "logger": "livekit.agents", "message": "unhandled exception while running the job task\nTraceback (most recent call last):\n File \"/opt/venv/lib/python3.10/site-packages/opentelemetry/util/_decorator.py\", line 71, in async_wrapper\n return await func(*args, **kwargs) # type: ignore\n File \"/opt/venv/lib/python3.10/site-packages/livekit/agents/ipc/job_proc_lazy_main.py\", line 306, in _traceable_entrypoint\n await self._job_entrypoint_fnc(job_ctx)\n File \"/app/apps/agent/agent_v2.py\", line 1754, in entrypoint\n turn_detection=EnglishModel(),\n File \"/opt/venv/lib/python3.10/site-packages/livekit/plugins/turn_detector/english.py\", line 29, in __init__\n super().__init__(model_type=\"en\", unlikely_threshold=unlikely_threshold)\n File \"/opt/venv/lib/python3.10/site-packages/livekit/plugins/turn_detector/base.py\", line 216, in __init__\n config_fname = _download_from_hf_hub(\n File \"/opt/venv/lib/python3.10/site-packages/livekit/plugins/turn_detector/base.py\", line 40, in _download_from_hf_hub\n raise RuntimeError(\nRuntimeError: livekit-plugins-turn-detector initialization failed. Could not find file \"languages.json\"."} {"reason": "job crashed", "pid": 39, "job_id": "AJ_Gm59eQNH8XCY", "room_id": "RM_WhfkQYeKfRs2"} 164322.527 ERROR… livekit.agents unhandled exception while running the job task Traceback (most recent call last): File "/opt/venv/lib/python3.10/site-pac… line 71, in async_wrapper return await func(*args, **kwargs) # type: ignore File "/opt/venv/lib/python3.10/site-pac… line 306, in _traceable_entrypoint await self._job_entrypoint_fnc(job_ctx) File "/app/apps/agent/agent_v2.py", line 1754, in entrypoint turn_detection=EnglishModel(), File "/opt/venv/lib/python3.10/site-pac… line 29, in init super().__init__(model_type="e… unlikely_threshold=unlikely_thresh… File "/opt/venv/lib/python3.10/site-pac… line 216, in init config_fname = _download_from_hf_hub( File "/opt/venv/lib/python3.10/site-pac… line 40, in _download_from_hf_hub raise RuntimeError( RuntimeError: livekit-plugins-turn-detector initialization failed. Could not find file "languages.json". {"pid": 39, "job_id": "AJ_Gm59eQNH8XCY", "room_id": "RM_WhfkQYeKfRs2"} Traceback (most recent call last): File "/opt/venv/lib/python3.10/site-packages/opentelemetry/util/_decorator.py", line 71, in async_wrapper return await func(*args, **kwargs) # type: ignore File
t
Thanks — this log is very helpful. You’ve confirmed the builder ran
download-files
(download finished for turn_detector) but at runtime the agent still can’t find "languages.json" and errors out. That means the file wasn’t present in the runtime image where the plugin expects it. I’ll explain why that happens and give an exact Dockerfile change to ensure the HF cache (including languages.json) is available at runtime. Why this happened (short) • The download step wrote files to the builder container’s default cache path (root’s HF cache: /root/.cache/huggingface/hub). Your runtime stage runs as user avoice and has a different home (/home/avoice) and filesystem. The builder’s /root cache isn’t being copied into the runtime image, so the plugin can’t find languages.json at runtime. Two reliable fixes (pick one) • Option A — Best: Bake the HF cache into the image during build and copy it into the runtime stage. ◦ Ensures all downloaded model/config files are present and readable at runtime. • Option B — Alternate: Use a shared HF cache path inside the image (set HF_HUB_CACHE) and copy that path from builder to runtime. ◦ Useful if you prefer a specific location (e.g., /app/.cache) and want non-root runtime user access. Exact change — copy the Hugging Face cache from builder to runtime Add these exact lines to your Dockerfile. They assume downloads were written to /root/.cache/huggingface in the builder; we copy them into /app/.cache/huggingface in runtime and set HF_HUB_CACHE so the agent looks there. 1) In the builder stage (after RUN uv run apps.agent.agent_v2 download-files) ensure the cache exists and is owned by root (download step will create it). No change needed if you already run download-files there. 2) In the runtime stage, add these lines after copying the venv and before switching to non-root user:
Copy code
# Copy Hugging Face cache from builder into a consistent location used at runtime
# Adjust source path if download-files wrote to a different path in builder.
COPY --from=builder /root/.cache/huggingface /app/.cache/huggingface

# Ensure the runtime process uses the same cache path
ENV HF_HUB_CACHE=/app/.cache/huggingface

# Give the non-root user ownership so the agent can access the files
RUN chown -R avoice:avoice /app/.cache
Where to place them in your Dockerfile (exact spot) • Place the COPY line right after: COPY --from=builder /opt/venv /opt/venv ENV PATH="/opt/venv/bin:$PATH" • Then add ENV HF_HUB_CACHE and the chown before USER avoice. Why this fixes it • The builder's /root/.cache/huggingface content (including languages.json) is copied into the runtime image at /app/.cache/huggingface. • Setting HF_HUB_CACHE tells the turn_detector plugin and other HF-based code to look at /app/.cache/huggingface. • chown ensures avoice (non-root) can read the files — preventing permission issues. If you prefer to keep the cache under the default home cache path • Alternative copy source: if download-files wrote to /root/.cache/huggingface/hub, copy that path specifically: COPY --from=builder /root/.cache/huggingface/hub /app/.cache/huggingface/hub Volume-based alternative (if you don’t want the cache baked in) • Create a named volume and download files into it once: docker run --rm -v model-cache:/app/.cache your-image uv run apps.agent.agent_v2 download-files • Then run your container with the same volume: docker run -v model-cache:/app/.cache --env HF_HUB_CACHE=/app/.cache/huggingface your-image • Make sure you set ENV HF_HUB_CACHE or pass it in env so the agent reads from the volume path. Next steps I can do for you • If you want, I’ll paste your full Dockerfile merged with these exact lines so you can copy/paste and rebuild. • Or, tell me the exact path shown in the builder logs for where languages.json was saved (for example /root/.cache/huggingface/hub/path/to/languages.json) and I’ll adjust the COPY path precisely. Which would you like — full merged Dockerfile or help confirming the exact cache path in the builder logs?