A production-ready example of a Voice Agent that leverages WebRTC through LiveKit to enable real-time voice interactions. This project showcases a unique architecture that bridges TypeScript and Python, enabling you to harness the best of both ecosystems.
The project demonstrates several key technical innovations:
- Python-TypeScript Bridge: Uses
pybridge
(built on Deepkit) to seamlessly integrate Python code with a Bun server through reflection - IPC Communication: Custom Hono server running on an IPC socket to enable bidirectional communication between Python and Bun processes
- Vector Operations: Efficient vector storage operations executed on the Bun side with results passed back to Python
- Real-time Voice: WebRTC-based voice communication powered by LiveKit
- Environment Setup
Create a .env
file with the following variables:
# Database Configuration
DATABASE_URL= # Postgres connection string (local or Neon)
# API Keys
DEEPGRAM_API_KEY= # For speech-to-text
OPENAI_API_KEY= # For AI processing
LIVEKIT_API_KEY= # For WebRTC
LIVEKIT_API_SECRET= # For WebRTC
LIVEKIT_URL= # Your LiveKit server URL
# Optional Configuration
LOG_LEVEL=DEBUG # Logging verbosity
- Python Environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -r apps/voice-agent/requirements.txt
- Node Dependencies
corepack pnpm install
- Start Development Server
cd apps/voice-agent
pnpm dev
- Visit LiveKit Agents Playground
- Connect to your running agent
- Start interacting through voice!
- Modify
apps/voice-agent/main.py
to adjust agent behavior - Update vector database embeddings for different knowledge domains
- Extend the Python-TypeScript bridge in
packages/pybridge
- Modify vector storage operations in
packages/llama-index-storage
- Customize the Hono server in
packages/vector-storage-hono
You have two options for the PostgreSQL database:
- Local Development: Run PostgreSQL in Docker
- Cloud Hosted: Use Neon Database for serverless PostgreSQL
- Deepgram - Speech-to-text API
- OpenAI - AI processing
- LiveKit Cloud - WebRTC infrastructure
- Configure your AWS credentials:
aws configure
- Install Doppler for secrets management and set up your project:
# Set up Doppler project
doppler setup
- Deploy to production:
doppler run -- npx sst deploy --stage=production
To remove the deployment:
npx sst remove --stage=production
Contributions are welcome! Please feel free to submit a Pull Request.