How ahmeds2099/via---interrupt-aware-voice-agent works
Purpose and entry points
Via is a document-grounded, interruption-aware voice agent. A Next.js browser client captures microphone PCM, plays streamed TTS, and exposes provider/state telemetry; a FastAPI backend owns the real-time voice state machine and HTTP APIs. Runtime entry points are backend/app/main.py (Uvicorn ASGI app) and frontend/app/page.tsx (browser UI).
Client voice transport and UI
The frontend establishes and supervises the voice session, records 16 kHz PCM, exchanges WebSocket events, and renders connection/voice state plus an architecture dashboard. API base URL/environment handling is isolated from UI behavior.
• frontend/hooks/usevoice.ts
• frontend/lib/voice/websocket.ts
• frontend/lib/voice/recorder.ts
• frontend/components/dashboard/architecturedashboard.tsx
API boundary
FastAPI exposes HTTP endpoints for health/status, document upload and search/ask workflows, STT/TTS, plus the primary streaming voice endpoint. The WebSocket boundary accepts audio and control events and emits transcript, playback, response, and observability events.
• backend/app/api/voice.py
• backend/app/api/stream.py
• backend/app/api/upload.py
• backend/app/main.py
Voice orchestration and interruption state
The backend explicitly owns voice control rather than delegating it to LangGraph/Vapi. Per-session state tracks active speech, paused responses, playback acknowledgments, interruption intent, and reconnect restoration. The dispatcher routes audio/control/ping messages; the voice pipeline coordinates VAD, streaming STT, response generation, TTS, cancellation, and resume behavior.
• backend/app/services/voice/voice_pipeline.py
• backend/app/services/voice/dispatcher.py
• backend/app/services/voice/session_manager.py
• backend/app/services/conversation/response_controller.py
• backend/app/services/conversation/paused_response.py
Speech and affect providers
Speech detection is pluggable: full deployments use local Silero VAD; lite deployments use energy VAD. Deepgram is the primary live transcription service, with an optional consent-based local Whisper fallback. Cartesia produces streamed speech. Emotion recognition is an optional local signal, used only when confidence/recent-turn smoothing supports adaptation.
• backend/app/services/voice/vad.py
• backend/app/services/voice/deepgram.py
• backend/app/services/stt/factory.py
• backend/app/services/tts/cartesia.py
• backend/app/services/emotion/provider.py
Grounded-answer pipeline
Uploads are extracted and chunked with source metadata, embedded through FastEmbed, and stored as vectors. At answer time, retrieval supplies relevant source context to prompt construction and Groq-backed LLM generation. The system can operate without an uploaded document as a general assistant.
• backend/app/services/document_ingestion.py
• backend/app/services/chunker.py
• backend/app/services/embedder.py
• backend/app/services/retrieval.py
• backend/app/services/llm.py
Persistence, infrastructure, and deployment modes
Qdrant Cloud is the durable semantic store for document chunks and long-term memory; Upstash Redis stores session snapshots, recent messages, and restoration state. Configuration selects full versus constrained lite runtime behavior, including model/provider availability. Required external services are Groq, Deepgram, Cartesia, Qdrant, and Upstash Redis.
• backend/app/core/config.py
• backend/app/core/qdrant.py
• backend/app/services/session_repository.py
• backend/app/services/memory_service.py
• backend/requirements-lite.txt
Main entry points: voice_pipeline.py Voice pipeline · main.py ASGI application · usevoice.ts Voice session hook · upload.py Document & speech APIs
Components 21
Browser client
- Voice UI & dashboard · Shows voice state, telemetry, and architecture.
frontend/app/page.tsx - Voice session hook · Supervises the browser voice session.
frontend/hooks/usevoice.ts - WebSocket transport · Exchanges audio, control, and voice events.
frontend/lib/voice/websocket.ts - PCM recorder · Captures 16 kHz microphone PCM.
frontend/lib/voice/recorder.ts - Architecture dashboard
frontend/components/dashboard/architecturedashboard.tsx
FastAPI boundary
- ASGI application · Hosts HTTP and streaming API routes.
backend/app/main.py - Document & speech APIs · Provides health, upload, search/ask, STT, and TTS workflows.
backend/app/api/upload.py - Streaming voice endpoint · Accepts audio/control events and emits transcript, playback, response, and observability events.
backend/app/api/voice.py - Stream API
backend/app/api/stream.py
Voice orchestration
- Event dispatcher · Routes audio, control, and ping messages.
backend/app/services/voice/dispatcher.py - Voice pipeline · Coordinates detection, transcription, generation, speech, cancellation, and resume.
backend/app/services/voice/voice_pipeline.py - Voice session manager · Tracks speech, playback acknowledgments, interruption, and reconnect state.
backend/app/services/voice/session_manager.py - Response control · Manages interruption and paused-response behavior.
backend/app/services/conversation/response_controller.py - VAD and live STT · Uses Silero or energy VAD and Deepgram with optional Whisper fallback.
backend/app/services/stt/factory.py - Cartesia TTS
backend/app/services/tts/cartesia.py
Grounded answers
- Document ingestion · Extracts, chunks, embeds, and preserves source metadata.
backend/app/services/document_ingestion.py - Retrieval · Supplies relevant source context for answers.
backend/app/services/retrieval.py - Groq answer generation · Generates grounded or general-assistant responses.
backend/app/services/llm.py
State and providers
- Qdrant Cloud · Durable store for document chunks and long-term memory.
backend/app/core/qdrant.py - Upstash Redis · Stores snapshots, recent messages, and restoration state.
backend/app/services/session_repository.py - Runtime mode config · Selects full or constrained lite provider behavior.
backend/app/core/config.py
Connections 24
- Voice UI & dashboard → Voice session hook: drives
- Voice UI & dashboard → Architecture dashboard: renders
- Voice session hook → PCM recorder: captures audio
- Voice session hook → WebSocket transport: supervises
- WebSocket transport → Streaming voice endpoint: WebSocket events
- ASGI application → Document & speech APIs: serves
- ASGI application → Streaming voice endpoint: serves
- ASGI application → Stream API: serves
- Streaming voice endpoint → Event dispatcher: incoming events
- Event dispatcher → Voice pipeline: audio and control
- Event dispatcher → Voice session manager: session events
- Voice pipeline → VAD and live STT: detects and transcribes
- Voice pipeline → Response control: interrupts or resumes
- Voice pipeline → Groq answer generation: requests answer
- Voice pipeline → Cartesia TTS: streams speech
- Voice pipeline → Voice session manager: updates voice state
- Voice session manager → Upstash Redis: snapshots and restoration
- Document & speech APIs → Document ingestion: uploads documents
- Document & speech APIs → Retrieval: searches and asks
- Document ingestion → Qdrant Cloud: stores vectors
- Retrieval → Qdrant Cloud: retrieves context
- Retrieval → Groq answer generation: grounding context
- Runtime mode config → VAD and live STT: selects providers
- Runtime mode config → Cartesia TTS: enables availability