Files
hope-voice-api/Dockerfile
T
snowspeeder 8a7cca456f fix: force tool calls for drifted intents and harden tool-use prompt
Small local models (qwen2.5-vl-3b, gemma-4-e4b) narrate actions ('Sure,
I'll pause the music') without emitting the tool call once the full
system prompt and 26-tool set are in context. Measured: qwen emitted
tools in 2/8 realistic intents, gemma 5/8; single-tool tests pass 100%,
so this is context-induced drift, not plumbing.

- agent/intent_router.py: deterministic forced-call router for
  high-frequency intents — media controls, now_playing/list_library,
  'remember that ...' memory saves, explicit YouTube Music searches,
  and personal-fact recall (memory_recall/search_notes/skill_recall,
  excluded for weather/time questions). Fires only when the tool is
  available; guards against how-do-I questions.
- agent.py: generalize _ForcedToolCallStream to any tool; route through
  intent_router after the dispatch check. System prompt adds a hard
  'call, don't narrate' rule and reconditions 'answer directly'.
- tests/test_intent_router.py: 30 unit tests pinning router behavior.

Verified against the live LLM with the full fidelity harness: combined
forced-or-emitted coverage 8/8 on qwen2.5-vl-3b (was 2/8) and 8/8 on
gemma-4-e4b (was 5/8). Full suite: 79 passed.
2026-08-29 15:38:35 -04:00

94 lines
3.8 KiB
Docker

# syntax=docker/dockerfile:1
# ── Stage 1: Build Python agent deps with uv ───────────────────────────────
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS build
ENV PYTHONUNBUFFERED=1
ENV UV_COMPILE_BYTECODE=1
WORKDIR /app
# Install build tools for native extensions (azure-cognitiveservices-speech)
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc g++ python3-dev libasound2-dev \
&& rm -rf /var/lib/apt/lists/*
COPY agent/pyproject.toml ./agent/
COPY agent/uv.lock ./agent/
RUN cd /app/agent && uv sync --frozen
# ── Stage 2: Runtime (use same base for Python compat) ─────────────────────
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS runtime
ENV PYTHONUNBUFFERED=1
# Fix SSL cert path for the slim base image (ca-certificates installs to /etc/ssl/certs)
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
# Install LiveKit server binary + supervisord + nginx + ffmpeg (yt-dlp audio
# extraction/transcoding for the media player)
RUN apt-get update && apt-get install -y --no-install-recommends \
curl ca-certificates supervisor nginx libasound2 iproute2 ffmpeg \
&& rm -rf /var/lib/apt/lists/*
# Download LiveKit server (latest stable)
ARG LIVEKIT_VERSION=v1.13.5
ARG LIVEKIT_TAG=1.13.5
RUN curl -sSL "https://github.com/livekit/livekit/releases/download/${LIVEKIT_VERSION}/livekit_${LIVEKIT_TAG}_linux_amd64.tar.gz" \
| tar xz -C /usr/local/bin/ livekit-server \
&& chmod +x /usr/local/bin/livekit-server \
&& ln -sf /usr/local/bin/livekit-server /usr/local/bin/livekit
# Copy Python agent + venv from build stage
COPY --from=build /app/agent/.venv /opt/voice-agent/.venv
COPY agent/agent.py /opt/voice-agent/agent.py
COPY agent/web_mcp.py /opt/voice-agent/web_mcp.py
COPY agent/weather_mcp.py /opt/voice-agent/weather_mcp.py
COPY agent/skills_mcp.py /opt/voice-agent/skills_mcp.py
COPY agent/task_registry.py /opt/voice-agent/task_registry.py
COPY agent/task_router.py /opt/voice-agent/task_router.py
COPY agent/intent_router.py /opt/voice-agent/intent_router.py
COPY agent/task_worker.py /opt/voice-agent/task_worker.py
COPY agent/dispatch_mcp.py /opt/voice-agent/dispatch_mcp.py
COPY agent/media_mcp.py /opt/voice-agent/media_mcp.py
# Copy web frontend + token endpoint + media server
COPY web/index.html /var/www/voice/
COPY web/app.js /var/www/voice/
COPY web/style.css /var/www/voice/
COPY web/livekit-client.umd.js /var/www/voice/
COPY web/manifest.json /var/www/voice/
COPY web/favicon.svg /var/www/voice/
COPY web/token_server.py /opt/voice/token_server.py
COPY web/media_server.py /opt/voice/media_server.py
# Permanent media library mount point (bind-mounted from ./media)
RUN mkdir -p /data/media/files /data/media/thumbs /data/media/jobs
# Config files
COPY livekit.yaml /etc/livekit.yaml
COPY supervisord.conf /etc/supervisor/conf.d/voice.conf
COPY config/users.json /etc/hope/users.json
# Configure nginx to serve the voice UI on WEB_PORT (9178 by default).
# Browsers require a secure context (HTTPS or localhost) for microphone access.
# The self-signed cert (with the LAN IP in the SAN) is generated at container
# start by entrypoint.sh.
COPY nginx.conf /etc/nginx/sites-available/voice
RUN rm -f /etc/nginx/sites-enabled/default \
&& ln -sf /etc/nginx/sites-available/voice /etc/nginx/sites-enabled/voice \
&& mkdir -p /etc/voice/certs
# Create non-root user for agent and protect the server-side user registry.
RUN useradd -m -s /bin/bash voiceuser || true \
&& chown -R voiceuser:voiceuser /etc/hope \
&& chmod 600 /etc/hope/users.json
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
EXPOSE 7880 7881 7882/udp 9178
ENTRYPOINT ["/entrypoint.sh"]
CMD ["supervisord", "-n", "-c", "/etc/supervisor/conf.d/voice.conf"]