# Project export: CareCompanion

This document was generated by HackStack to give an AI agent context about a hackathon project. Sections are labeled with their provenance; content marked as truncated was cut to keep this document small.

## Project metadata

- Hackathon: UC Berkeley AI Hackathon 2025
- Tagline: Future of Companion Care
- Devpost: https://devpost.com/software/mediai-mqf26j
- GitHub: http://github.com/Pavanmahaveer7/Berkeley-hack
- Team: 1 GitHub contributor(s) — Slytherin-dev (1 commits)

## Devpost submission (written by the team)

### Inspiration

idk

### What it does

idk

## README (from the GitHub repository)

# AI Assistant Hub 🤖

A powerful multi-modal AI assistant platform combining voice interaction and vision capabilities with persistent memory.

## 🌟 Features

### Voice Agent MVP (Port 8091)
- 🎙️ Natural voice conversations
- 🧠 Persistent memory across sessions
- 🗣️ High-quality text-to-speech
- 📝 Real-time transcription

### Vision System (Port 8093)
- 📸 Image upload and analysis
- 🎥 Webcam integration
- 🔍 Powered by Claude Vision
- 📊 Detailed visual feedback

### Home Server (Port 8080)
- 🏠 Unified interface
- 🚦 Service health monitoring
- 🔄 Real-time status updates
- 🎯 Easy navigation

## 🚀 Quick Start

1. **Clone the repository**
   ```bash
   git clone https://github.com/yourusername/ai-assistant-hub.git
   cd ai-assistant-hub
   ```

2. **Set up environment**
   ```bash
   python -m venv venv
   source venv/bin/activate  # Linux/Mac
   venv\Scripts\activate     # Windows
   pip install -r requirements.txt
   ```

3. **Configure API keys**
   ```bash
   cp .env.example .env
   # Edit .env with your API keys
   ```

4. **Start services**
   ```bash
   # Terminal 1: Start Letta Server
   letta serve --port 8283

   # Terminal 2: Start Home Server
   python home_server.py

   # Terminal 3: Start Voice Agent
   python main.py

   # Terminal 4: Start Vision System
   python simple_vision_server.py
   ```

5. **Access the application**
   - Open http://localhost:8080 in your browser
   - Navigate to Voice or Vision services
   - Start interacting!

## 📚 Documentation
- [DevPost Submission](docs/DEVPOST.md)
- [Technical Documentation](docs/TECHNICAL.md)
- [API Documentation](http://localhost:8080/docs)

## 🛠️ Development

### Using Docker
```bash
# Build and start all services
docker-compose up --build

# Stop services
docker-compose down
```

### Running Tests
```bash
pytest tests/
```

## 📋 Requirements
- Python 3.9+
- OpenAI API key
- Anthropic API key
- Letta API key

## 🤝 Contributing
1. Fork the repository
2. Create a feature branch
3. Commit your changes
4. Push to the branch
5. Open a pull request

## 📄 License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## 🙏 Acknowledgments
- OpenAI for Whisper and TTS
- Anthropic for Claude Vision
- Letta for conversation management
- FastAPI team for the awesome framework

## 🎤 Voice Agent MVP

> A full-stack AI-powered voice conversation application with persistent memory

[![Python](https://img.shields.io/badge/python-3.8+-blue.svg)](https://python.org)
[![FastAPI](https://img.shields.io/badge/FastAPI-0.115+-green.svg)](https://fastapi.tiangolo.com)
[![OpenAI](https://img.shields.io/badge/OpenAI-Whisper%20%26%20TTS-orange.svg)](https://openai.com)
[![Letta](https://img.shields.io/badge/Letta-Memory%20Agent-purple.svg)](https://github.com/cpacker/MemGPT)

## 🌟 Features

- **🎙️ Real-time Voice Recording** - Record audio directly in the browser
- **📁 Audio File Upload** - Support for MP3, WAV, WebM, and other formats
- **🗣️ Speech-to-Text** - Powered by OpenAI Whisper API
- **🤖 AI Conversation** - Intelligent responses using OpenAI GPT models
- **🔊 Text-to-Speech** - Natural voice responses with multiple voice options
- **🧠 Persistent Memory** - Conversation history using Letta memory agent
- **💬 Text Chat** - Alternative text-based interaction
- **📊 Session Management** - Track conversations and user sessions
- **🔄 Real-time Health Monitoring** - Component status tracking

## 🏗️ Architecture

```
┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│   Frontend      │    │   FastAPI       │    │   AI Services   │
│   (HTML/CSS/JS) │◄──►│   Backend       │◄──►│   (OpenAI/Letta)│
└─────────────────┘    └─────────────────┘    └─────────────────┘
        │                       │                       │
        │                       │                       │
        ▼                       ▼                       ▼
┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│   Voice Input   │    │   SQLite DB     │    │   Memory Agent  │
│   Audio Upload  │    │   Sessions      │    │   Conversation  │
└─────────────────┘    └─────────────────┘    └─────────────────┘
```

## 🚀 Quick Start

### Prerequisites

- Python 3.8+
- OpenAI API Key
- Modern web browser with microphone support

### Installation

1. **Clone the repository**
```bash
git clone https://github.com/Pavanmahaveer7/voice-agent-mvp.git
cd voice-agent-mvp
```

2. **Create virtual environment**
```bash
python -m venv venv

# Windows
.\venv\Scripts\activate

# macOS/Linux
source venv/bin/activate
```

3. **Install dependencies**
```bash
pip install -r requirements.txt
```

4. **Set up environment variables**
```bash
# Create .env file
echo "OPENAI_API_KEY=your_openai_api_key_here" > .env
```

5. **Start Letta server** (in a separate terminal)
```bash
letta server --port 8283
```

6. **Run the application**
```bash
python -m uvicorn main:app --host 0.0.0.0 --port 8091 --reload
```

7. **Open your browser**
```
http://localhost:8091
```

## 🎯 Usage

### Voice Recording
1. Click **"Start Recording"** button
2. Speak your message
3. Click **"Stop Recording"** 
4. Audio is automatically transcribed and sent to the AI

### File Upload
1. Click the upload area or drag & drop an audio file
2. Supported formats: MP3, WAV, WebM, M4A, FLAC, AAC, OGG
3. Click **"Send Audio"** to process

### Text Chat
1. Type your message in the text input
2. Press Enter or click the send button
3. Receive both text and audio responses

### Voice Settings
- Choose from 6 different AI voices (Alloy, Echo, Fable, Onyx, Nova, Shimmer)
- Toggle auto-play for audio responses
- Adjust voice settings in real-time

## 🔧 Configuration

### Environment Variables

Create a `.env` file in the root directory:

```bash
# Required
OPENAI_API_KEY=your_openai_api_key_here

# Optional
LETTA_SERVER_URL=http://localhost:8283
DATABASE_PATH=voice_agent_mvp.db
DEBUG=false
```

### Audio Settings

Configure audio processing in `src/config/settings.py`:

```python
ALLOWED_AUDIO_FORMATS = ['wav', 'mp3', 'm4a', 'flac', 'aac', 'webm', 'ogg']
MAX_AUDIO_SIZE_MB = 25
TTS_MODEL = "tts-1"
TTS_VOICE = "alloy"
```

## 📚 API Documentation

Once running, visit:
- **Interactive API Docs**: http://localhost:8091/docs
- **ReDoc Documentation**: http://localhost:8091/redoc
- **Health Check**: http://localhost:8091/health

### Key Endpoints

- `GET /` - Web interface
- `POST /voice-chat` - Process voice messages
- `POST /chat` - Text-based chat
- `GET /health` - System health status
- `GET /session/info` - Session information
- `POST /session/new` - Create new session

## 🧠 Memory System

The application uses **Letta** (formerly MemGPT) for persistent conversation memory:

- **Session Persistence** - Conversations saved across sessions
- **User Context** - Remembers user preferences and history
- **Long-term Memory** - Maintains context over extended conversations
- **Mock Mode** - Fallback when Letta server is unavailable

## 🔍 Monitoring & Health

### Health Check Components
- ✅ **Whisper Handler** - Speech recognition
- ✅ **TTS Handler** - Text-to-speech
- ✅ **Audio Utils** - Audio processing
- ✅ **Conversation Handler** - Memory management
- ✅ **OpenAI API** - External API connectivity
- ✅ **Letta Agent** - Memory agent status

### Logs
Check application logs for detailed debugging:
```bash
# View real-time logs
tail -f logs/voice_agent.log
```

## 🧪 Testing

Run the test suite:
```bash
# Install test dependencies
pip install pytest pytest-asyncio

# Run tests
pytest tests/

# Run with coverage
pytest --cov=src tests/
```

## 🚀 Deployment

### Docker (Coming Soon)
```bash
docker build -t voice-agent-mvp .
docker run -p 8091:8091 voice-agent-mvp
```

### Production Considerations
- Use environment variables for secrets
- Set up proper CORS origins
- Configure HTTPS
- Use production ASGI server (Gunicorn + Uvicorn)
- Set up proper logging and monitoring

## 🤝 Contributing

1. Fork the repository
2. Creat

[README truncated for size]

## Detected evidence (automated analysis)

Indexed codebase: 75 recognized source files, 657 KB.
- CSS (language) — detected in the code
- HTML (language) — detected in the code
- JavaScript (language) — detected in the code
- Python (language) — detected in the code
- Anthropic (technology) — claimed on Devpost, not found in the code
- Google Gemini (technology) — claimed on Devpost, not found in the code
- OpenAI (technology) — claimed on Devpost, not found in the code
- AI coding agent: Cursor — evidence: config files committed to the repository

## Codebase structure (from repository index)

### Files (88 of 88)

```
.cursor/rules/create-prd.mdc
.cursor/rules/generate-tasks.mdc
.cursor/rules/rules-letta.mdc
.cursor/rules/tasks-lists.mdc
.early.coverage/python/coverage.json
.env.example
.gitignore
benchmark_cli.py
benchmark_summary.py
BENCHMARKING_RESULTS.md
check_agents.py
clear_cache.py
demo_vision.py
docker-compose.yml
Dockerfile
docs/DEVPOST.md
docs/TECHNICAL.md
env.example
functions/__init__.py
functions/health_functions.py
functions/vision_functions.py
home_server.py
letta_agents/__init__.py
letta_agents/health_agent.py
letta_agents/vision_agent.py
LICENSE
main_multiagent.py
main.py
quick_test.py
quick_vision_test.py
README_BENCHMARKING.md
README.md
requirements_multiagent.txt
requirements_simple.txt
requirements.txt
simple_benchmark.py
SIMPLE_MULTIAGENT_SETUP.md
simple_multiagent.py
simple_vision_server.py
src/benchmarking/__init__.py
src/benchmarking/benchmark_runner.py
src/benchmarking/load_tester.py
src/benchmarking/metrics_collector.py
src/benchmarking/performance_monitor.py
src/benchmarking/reporting.py
src/config/__init__.py
src/config/benchmarking_config.py
src/config/settings.py
src/memory/__init__.py
src/memory/conversation_handler.py
src/memory/letta_manager.py
src/memory/persistence.py
src/rl_agent/__init__.py
src/rl_agent/memory_environment.py
src/rl_agent/reward_system.py
src/rl_agent/rl_memory_agent.py
src/voice/__init__.py
src/voice/audio_utils.py
src/voice/error_handler.py
src/voice/exceptions.py
src/voice/tts_handler.py
src/voice/whisper_handler.py
start.sh
static/app.js
static/index.html
static/multiagent.html
static/style.css
tasks/prd-voice-agent-mvp.md
tasks/tasks-prd-voice-agent-mvp.md
test_endpoints.py
test_final_vision.py
test_image_analysis.py
test_letta_api.py
test_server.py
test_simple_agents.py
test_ui_upload.py
test_webm_final.py
tests/__init__.py
tests/conftest.py
tests/test_audio_utils.py
tests/test_conversation_handler.py
tests/test_error_handler.py
tests/test_exceptions.py
tests/test_letta_manager.py
tests/test_persistence.py
tests/test_tts_handler.py
tests/test_whisper_handler.py
tests/unit/test_health.py
```

### Dependencies

No dependency index available.

### Recent commits (newest first)

- Initial commit: AI Assistant Hub with secure environment variable handling

## Key source files (fetched from GitHub, selected and truncated for size)

### BENCHMARKING_RESULTS.md

```markdown
# Voice Agent Benchmarking Results

## Summary

Successfully implemented and tested a comprehensive benchmarking system for your Voice Agent MVP. The system is working perfectly and your voice agent is performing excellently!

## 🎯 Key Findings

### Performance Metrics
- **Health Check Endpoint**: 100% success rate, ~1.9ms average latency
- **Chat Endpoint**: 100% success rate, ~1.4ms average latency  
- **Session Info Endpoint**: 100% success rate, ~1.3ms average latency
- **Load Test Results**: 100% success rate with 5 concurrent users, 4.9 requests/sec

### System Status
- ✅ **Server**: Running on HTTPS (port 8000)
- ✅ **All Endpoints**: Responding correctly
- ✅ **Performance**: Excellent latency (all under 10ms)
- ✅ **Reliability**: 100% success rate across all tests
- ✅ **Concurrency**: Handles multiple users without issues

## 🚀 Benchmarking Tools Available

### 1. Simple Benchmark Tool (`simple_benchmark.py`)
A standalone tool that works without complex imports:

```bash
# Health check
python simple_benchmark.py health

# Basic performance tests
python simple_benchmark.py test --requests 10 --save

# Load testing
python simple_benchmark.py load --users 5 --duration 20 --save
```

### 2. Advanced Benchmarking System (`src/benchmarking/`)
Full-featured benchmarking module with:
- Metrics collection and storage
- Real-time monitoring
- Detailed reporting
- Load and stress testing
- Cost tracking

### 3. CLI Interface (`benchmark_cli.py`)
Command-line interface for the advanced system:

```bash
python benchmark_cli.py health
python benchmark_cli.py quick-test --requests 5
python benchmark_cli.py load-test --users 10 --duration 60
```

## 📊 Test Results

### Basic Performance Test (10 requests each)
- **Health Check**: 100% success, 1.9ms avg latency (0.8-10.0ms range)
- **Chat Test**: 100% success, 1.4ms avg latency (0.3-5.0ms range)
- **Session Info**: 100% success, 1.3ms avg latency (0.0-4.0ms range)

### Load Test (5 concurrent users, 20 seconds)
- **Total Requests**: 100
- **Success Rate**: 100%
- **Average Latency**: 1.9ms
- **Throughput**: 4.9 requests/second
- **Duration**: 20.3 seconds

## 🔧 Technical Details

### Server Configuration
- **Protocol**: HTTPS (SSL/TLS enabled)
- **Port**: 8000
- **Host**: localhost
- **Status**: All components healthy

### Endpoints Tested
1. `GET /health` - Health check endpoint
2. `POST /chat` - Text chat functionality
3. `GET /session/info` - Session information retrieval

### Benchmark Features
- **SSL Support**: Automatically handles HTTPS connections
- **Concurrent Testing**: Multiple users simulation
- **Error Handling**: Comprehensive error tracking
- **Result Storage**: JSON format with timestamps
- **Real-time Feedback**: Live progress updates

## 🎉 Conclusion

Your Voice Agent MVP is performing exceptionally well:

1. **Excellent Response Times**: All endpoints respond in under 2ms on average
2. **Perfect Reliability**: 100% success rate across all tests
3. **Good Scalability**: Handles co
[truncated — 985 more characters]
```

### SIMPLE_MULTIAGENT_SETUP.md

```markdown
# Simple Multi-Agent Healthcare System

## ✅ Successfully Fixed All Issues!

### **What We Accomplished:**

1. **Fixed JSON Error in env.example**
   - Corrected malformed JSON in `ALLOWED_AUDIO_FORMATS` field
   - This was preventing the main Voice Agent MVP from starting

2. **Created Simple Multi-Agent System**
   - Uses your existing Letta agents directly (no complex creation logic)
   - Connects to agents via REST API calls
   - Runs on safe port 8094 (doesn't interfere with port 8091)

3. **Fixed Letta API Integration**
   - Updated to correct message format: `{"messages": [{"role": "user", "content": "message"}]}`
   - Proper response parsing to extract agent replies
   - Error handling and fallbacks

### **Your Working System:**

#### **Existing Agents Connected:**
- **Vision Agent**: `agent-0cb42f44-1e23-45e4-aaa0-a2ad359e8d8d` (scratch-agent)
- **Health Agent**: `agent-5437f90e-2853-494d-beb4-78a44351967e` (companion-agent)

#### **System Architecture:**
```
┌─────────────────────────────────────────────────────────────┐
│                    Your Complete System                     │
├─────────────────────────────────────────────────────────────┤
│  Port 8091: Voice Agent MVP (UNTOUCHED & WORKING)          │
│  Port 8094: Simple Multi-Agent System (NEW & WORKING)      │
│  Port 8283: Letta Server (EXISTING AGENTS)                 │
└─────────────────────────────────────────────────────────────┘
```

### **How to Use:**

#### **1. Start the Simple Multi-Agent System:**
```bash
python simple_multiagent.py
```

#### **2. Open the Web Interface:**
```
http://localhost:8094
```

#### **3. Test the System:**
```bash
python test_simple_agents.py
```

### **Available Endpoints:**

- `GET /` - Beautiful web interface
- `GET /health` - Health check
- `GET /agents/status` - Check agent connectivity
- `POST /chat` - Chat with agents
- `POST /assessment/quick` - Quick health assessment
- `POST /vision/analyze` - Vision analysis

### **Key Features:**

✅ **No Disruption**: Your original Voice Agent MVP on port 8091 remains untouched  
✅ **Direct Integration**: Uses your existing Letta agents directly  
✅ **Simple Architecture**: No complex agent creation or validation  
✅ **Error Handling**: Graceful fallbacks when agents are unavailable  
✅ **Modern UI**: Beautiful healthcare-themed interface  
✅ **REST API**: Full API for programmatic access  

### **Test Results:**
```
🧪 Simple Multi-Agent System Test Suite
✅ Health check passed
✅ Agent status retrieved
   vision_agent: connected
   health_agent: connected
✅ Health agent chat successful
✅ Vision agent chat successful  
✅ Quick assessment successful
🎉 Test suite completed!
```

### **Files Created:**

1. `simple_multiagent.py` - Main application
2. `requirements_simple.txt` - Dependencies
3. `test_simple_agents.py` - Test suite
4. `test_letta_api.py` - API format testing

### **Next Steps:**

1. **Use the Web Interface**: Open http://localhost:8094 in your browser
2. **Chat with Agents**: Test bo
[truncated — 723 more characters]
```

### Dockerfile

```
# Use Python 3.9 slim image
FROM python:3.9-slim

# Set working directory
WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements first to leverage Docker cache
COPY requirements*.txt ./
RUN pip install --no-cache-dir -r requirements.txt

# Copy application code
COPY . .

# Create necessary directories
RUN mkdir -p temp uploads

# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=/app

# Expose ports
EXPOSE 8080 8091 8093

# Default command (will be overridden by docker-compose)
CMD ["python", "home_server.py"] 
```

### docker-compose.yml

```yaml
version: '3.8'

services:
  home-server:
    build: .
    command: python home_server.py
    ports:
      - "8080:8080"
    environment:
      - OPENAI_API_KEY=${OPENAI_API_KEY}
      - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
      - LETTA_API_KEY=${LETTA_API_KEY}
    volumes:
      - .:/app
    depends_on:
      - letta-server

  voice-agent:
    build: .
    command: python main.py
    ports:
      - "8091:8091"
    environment:
      - OPENAI_API_KEY=${OPENAI_API_KEY}
      - LETTA_API_KEY=${LETTA_API_KEY}
    volumes:
      - .:/app
    depends_on:
      - letta-server

  vision-system:
    build: .
    command: python simple_vision_server.py
    ports:
      - "8093:8093"
    environment:
      - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
    volumes:
      - .:/app

  letta-server:
    image: letta/server:latest
    ports:
      - "8283:8283"
    environment:
      - LETTA_API_KEY=${LETTA_API_KEY}
    volumes:
      - letta_data:/data

volumes:
  letta_data: 
```

### requirements.txt

```
��#   C o r e   D e p e n d e n c i e s  
 f a s t a p i = = 0 . 1 0 4 . 1  
 u v i c o r n = = 0 . 2 4 . 0  
 p y t h o n - m u l t i p a r t = = 0 . 0 . 6  
 p y d a n t i c = = 2 . 5 . 2  
 h t t p x = = 0 . 2 6 . 0  
  
 #   A u d i o   P r o c e s s i n g  
 o p e n a i - w h i s p e r = = 2 0 2 3 1 1 1 7  
 o p e n a i = = 1 . 3 . 5  
 p y d u b = = 0 . 2 5 . 1  
  
 #   V i s i o n   P r o c e s s i n g  
 a n t h r o p i c = = 0 . 3 . 1 1  
 p i l l o w = = 1 0 . 1 . 0  
  
 #   M e m o r y   &   S t a t e   M a n a g e m e n t  
 l e t t a - c l i e n t = = 0 . 1 . 0  
 p y t h o n - d o t e n v = = 1 . 0 . 0  
  
 #   U t i l s  
 n u m p y = = 1 . 2 6 . 2  
 p y t h o n - j o s e [ c r y p t o g r a p h y ] = = 3 . 3 . 0  
 p a s s l i b [ b c r y p t ] = = 1 . 7 . 4  
 a i o f i l e s = = 2 3 . 2 . 1  
 w e b s o c k e t s = = 1 2 . 0  
 p y t e s t = = 7 . 4 . 3  
 r e q u e s t s = = 2 . 3 1 . 0  
 a i o h t t p = = 3 . 9 . 1  
 
```

### main.py

```python
"""
Voice Agent MVP - Main FastAPI Application
Provides REST API endpoints for voice conversation with Letta agent
"""
import logging
import os
import tempfile
import uuid
from typing import Optional, Dict, Any, List
from datetime import datetime, timezone
import asyncio
from pathlib import Path

from fastapi import FastAPI, File, UploadFile, HTTPException, Form, Depends
from fastapi.responses import FileResponse, JSONResponse, HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel, Field

from src.voice import WhisperHandler, TTSHandler, AudioUtils
from src.memory import ConversationHandler
from src.config import settings

# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# Initialize FastAPI app
app = FastAPI(
    title="Voice Agent MVP",
    description="A voice conversation agent with persistent memory using Letta and Whisper",
    version="1.0.0",
    docs_url="/docs",
    redoc_url="/redoc"
)

# Add CORS middleware
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],  # In production, specify exact origins
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# Mount static files
app.mount("/static", StaticFiles(directory="static"), name="static")

# Initialize global components
whisper_handler: Optional[WhisperHandler] = None
tts_handler: Optional[TTSHandler] = None
audio_utils: Optional[AudioUtils] = None
conversation_handler: Optional[ConversationHandler] = None

# Startup event
@app.on_event("startup")
async def startup_event():
    """Initialize all components on startup."""
    global whisper_handler, tts_handler, audio_utils, conversation_handler
    
    try:
        logger.info("Initializing Voice Agent MVP...")
        
        # Initialize voice components
        whisper_handler = WhisperHandler()
        tts_handler = TTSHandler()
        audio_utils = AudioUtils()
        
        # Initialize conversation handler
        conversation_handler = ConversationHandler(
            agent_name="voice_agent_mvp",
            db_path="voice_agent_mvp.db"
        )
        
        # Initialize conversation handler
        await conversation_handler.initialize()
        
        logger.info("Voice Agent MVP initialized successfully!")
        
    except Exception as e:
        logger.error(f"Failed to initialize Voice Agent MVP: {e}")
        raise

# Shutdown event
@app.on_event("shutdown")
async def shutdown_event():
    """Clean up resources on shutdown."""
    global conversation_handler
    
    try:
        if conversation_handler:
            conversation_handler.cleanup()
        logger.info("Voice Agent MVP shutdown complete")
        
    except Exception as e:
        logger.warning(f"Error during shutdown: {e}")

# Root endpoint - serve the main interface
@app.get("/", response_class=HTMLResponse)
async def root():
    """Serve the main web interface."""
    return FileResponse("static/index.html")

# Health check endpoint
@app.get("/health")
async def health_check():
    """Check the health status of all components."""
    try:
        # Check all critical components
        components_status = {
            "whisper": whisper_handler is not None,
            "tts": tts_handler is not None,
            "audio": audio_utils is not None,
            "memory": conversation_handler is not None and conversation_handler._initialized
        }
        
        # Overall health is good only if all components are healthy
        is_healthy = all(components_status.values())
        
        return {
            "status": "healthy" if is_healthy else "degraded",
            "timestamp": datetime.now(timezone.utc).isoformat(),
            "components": components_status
        }
        
    except Exception as e:
        logger.error(f"Health check failed: {e}")
        return {
            "status": "unhealthy",
            "timestamp": datetime.now(timezone.utc).isoformat(),
            "error": str(e)
        }

# Session info endpoint
@app.get("/session/info")
async def get_session_info():
    """Get current session information."""
    try:
        if not conversation_handler:
            raise HTTPException(status_code=503, detail="Conversation handler not initialized")
            
        session_info = await conversation_handler.get_session_info()
        return session_info
        
    except Exception as e:
        logger.error(f"Failed to get session info: {e}")
        raise HTTPException(status_code=500, detail=str(e))

# Voice chat endpoint
@app.post("/voice-chat")
async def voice_chat(
    audio: UploadFile = File(..., description="Audio file with user message"),
    user_id: Optional[str] = Form(None, description="Optional user identifier"),
    voice_name: str = Form("alloy", description="Voice to use for TTS response")
):
    """Process voice input and return voice response."""
    try:
        # Step 1: Validate audio file
        if not audio.filename:
            raise HTTPException(status_code=400, detail="No audio filename provided")
        
        # Step 2: Transcribe audio
        try:
            audio_data = await audio.read()
            
            # Validate audio file
            is_valid, audio_info = audio_utils.validate_audio_data(audio_data, audio.filename)
            if not is_valid:
                raise HTTPException(status_code=400, detail=f"Invalid audio file: {audio_info.get('error', 'Unknown error')}")
            
            # Transcribe audio
            transcription_result = whisper_handler.transcribe_audio(audio_data, audio.filename)
            user_message = transcription_result["text"]
            
            if not user_message.strip():
                raise HTTPException(status_code=400, detail="No speech detected in audio")
            
        except Exception as e:
            logger.error(f"Audio processing failed: {e}")
            raise HTTP
[truncated — 4969 more characters]
```

### static/app.js

```javascript
/**
 * Voice Agent MVP - Frontend JavaScript
 * Handles audio recording, file upload, chat interface, and API communication
 */

// Configuration
const API_BASE_URL = ''; // Use same origin (FastAPI serves both frontend and API)

class VoiceAgentApp {
    constructor() {
        // Audio recording state
        this.mediaRecorder = null;
        this.audioChunks = [];
        this.isRecording = false;
        this.recordingTimer = null;
        this.recordingStartTime = null;
        
        // Application state
        this.sessionId = null;
        this.userId = null;
        this.messageCount = 0;
        this.isConnected = false;
        
        // DOM elements
        this.elements = {};
        
        // Initialize the application
        this.init();
    }
    
    /**
     * Initialize the application
     */
    async init() {
        console.log('Initializing Voice Agent MVP...');
        
        // Cache DOM elements
        this.cacheElements();
        
        // Set up event listeners
        this.setupEventListeners();
        
        // Check initial health status
        await this.checkHealth();
        
        // Load session info
        await this.loadSessionInfo();
        
        console.log('Voice Agent MVP initialized successfully!');
    }
    
    /**
     * Cache frequently used DOM elements
     */
    cacheElements() {
        this.elements = {
            // Status elements
            connectionStatus: document.getElementById('connection-status'),
            statusText: document.getElementById('status-text'),
            sessionId: document.getElementById('session-id'),
            messageCount: document.getElementById('message-count'),
            userId: document.getElementById('user-id'),
            
            // Recording elements
            recordBtn: document.getElementById('record-btn'),
            stopRecordBtn: document.getElementById('stop-record-btn'),
            recordingStatus: document.getElementById('recording-status'),
            recordingTimer: document.getElementById('recording-timer'),
            
            // Upload elements
            uploadArea: document.getElementById('upload-area'),
            audioFile: document.getElementById('audio-file'),
            uploadBtn: document.getElementById('upload-btn'),
            
            // Voice settings
            voiceSelect: document.getElementById('voice-select'),
            autoPlay: document.getElementById('auto-play'),
            
            // Chat elements
            chatMessages: document.getElementById('chat-messages'),
            textInput: document.getElementById('text-input'),
            sendTextBtn: document.getElementById('send-text-btn'),
            
            // Session controls
            newSessionBtn: document.getElementById('new-session-btn'),
            clearHistoryBtn: document.getElementById('clear-history-btn'),
            
            // Audio player
            audioPlayer: document.getElementById('audio-player'),
            responseAudio: document.getElementById('response-audio'),
            
            // Loading and error modals
            loadingOverlay: document.getElementById('loading-overlay'),
            loadingText: document.getElementById('loading-text'),
            errorModal: document.getElementById('error-modal'),
            errorMessage: document.getElementById('error-message'),
            errorClose: document.getElementById('error-close'),
            errorOk: document.getElementById('error-ok')
        };
    }
    
    /**
     * Set up all event listeners
     */
    setupEventListeners() {
        // Recording controls
        this.elements.recordBtn.addEventListener('click', () => this.startRecording());
        this.elements.stopRecordBtn.addEventListener('click', () => this.stopRecording());
        
        // File upload
        this.elements.uploadArea.addEventListener('click', () => this.elements.audioFile.click());
        this.elements.uploadArea.addEventListener('dragover', (e) => this.handleDragOver(e));
        this.elements.uploadArea.addEventListener('drop', (e) => this.handleDrop(e));
        this.elements.audioFile.addEventListener('change', (e) => this.handleFileSelect(e));
        this.elements.uploadBtn.addEventListener('click', () => this.uploadAudioFile());
        
        // Text chat
        this.elements.textInput.addEventListener('keypress', (e) => {
            if (e.key === 'Enter' && !e.shiftKey) {
                e.preventDefault();
                this.sendTextMessage();
            }
        });
        this.elements.sendTextBtn.addEventListener('click', () => this.sendTextMessage());
        
        // Session controls
        this.elements.newSessionBtn.addEventListener('click', () => this.createNewSession());
        this.elements.clearHistoryBtn.addEventListener('click', () => this.clearChatHistory());
        
        // User ID changes
        this.elements.userId.addEventListener('change', () => this.handleUserIdChange());
        
        // Error modal
        this.elements.errorClose.addEventListener('click', () => this.hideError());
        this.elements.errorOk.addEventListener('click', () => this.hideError());
        
        // Audio player events
        this.elements.responseAudio.addEventListener('ended', () => {
            this.elements.audioPlayer.style.display = 'none';
        });
        
        // Keyboard shortcuts
        document.addEventListener('keydown', (e) => this.handleKeyboardShortcuts(e));
    }
    
    /**
     * Handle keyboard shortcuts
     */
    handleKeyboardShortcuts(e) {
        // Ctrl/Cmd + R for recording
        if ((e.ctrlKey || e.metaKey) && e.key === 'r') {
            e.preventDefault();
            if (!this.isRecording) {
                this.startRecording();
            } else {
                this.stopRecording();
            }
        }
        
        // Escape to stop recording
        if (e.key === 'Escape
[truncated — 19731 more characters]
```

### start.sh

```shell
#!/bin/bash

# Start Letta server
letta serve --port 8283 &

# Wait for Letta to start
sleep 5

# Start Home Server
python home_server.py &

# Start Voice MVP
python main.py &

# Start Vision System
python simple_vision_server.py &

# Wait for any process to exit
wait -n

# Exit with status of process that exited first
exit $? 
```

### check_agents.py

```python
#!/usr/bin/env python3

import requests
import json

def check_letta_agents():
    """Check what agents exist in your Letta server"""
    try:
        print("🔍 Checking existing Letta agents...")
        response = requests.get('http://localhost:8283/v1/agents/')
        print(f"Status: {response.status_code}")
        
        if response.status_code == 200:
            agents = response.json()
            print(f"\n✅ Found {len(agents)} agents:")
            
            for i, agent in enumerate(agents, 1):
                print(f"\n{i}. Agent Details:")
                print(f"   ID: {agent.get('id', 'N/A')}")
                print(f"   Name: {agent.get('name', 'N/A')}")
                print(f"   Description: {agent.get('description', 'N/A')[:100]}...")
                if 'tags' in agent:
                    print(f"   Tags: {agent.get('tags', [])}")
                    
            return agents
        else:
            print(f"❌ Error: {response.status_code}")
            print(f"Response: {response.text}")
            return []
            
    except Exception as e:
        print(f"❌ Error connecting to Letta: {e}")
        return []

if __name__ == "__main__":
    agents = check_letta_agents()
    
    if agents:
        print(f"\n📋 Agent IDs you can use:")
        for agent in agents:
            print(f"   - {agent.get('name', 'unnamed')}: {agent.get('id')}") 
```

### clear_cache.py

```python
#!/usr/bin/env python3
"""
Clear Python cache files to ensure latest code is running
"""
import os
import shutil
import sys
from pathlib import Path

def clear_python_cache():
    """Clear all Python cache files and directories"""
    cache_patterns = [
        "__pycache__",
        "*.pyc",
        "*.pyo",
        "*.pyd",
        ".pytest_cache"
    ]
    
    current_dir = Path(".")
    cleared_count = 0
    
    print("🧹 Clearing Python cache files...")
    
    # Remove __pycache__ directories
    for pycache_dir in current_dir.rglob("__pycache__"):
        if pycache_dir.is_dir():
            print(f"  Removing: {pycache_dir}")
            shutil.rmtree(pycache_dir, ignore_errors=True)
            cleared_count += 1
    
    # Remove individual .pyc files
    for pyc_file in current_dir.rglob("*.pyc"):
        if pyc_file.is_file():
            print(f"  Removing: {pyc_file}")
            pyc_file.unlink(missing_ok=True)
            cleared_count += 1
    
    # Remove .pytest_cache directories
    for pytest_cache in current_dir.rglob(".pytest_cache"):
        if pytest_cache.is_dir():
            print(f"  Removing: {pytest_cache}")
            shutil.rmtree(pytest_cache, ignore_errors=True)
            cleared_count += 1
    
    print(f"✅ Cleared {cleared_count} cache files/directories")
    print("🚀 Cache cleared! You can now restart the server with fresh code.")

if __name__ == "__main__":
    clear_python_cache() 
```

[66 more indexed source files omitted to keep this export small. The full file list is in the Codebase structure section above.]