|
| 1 | +# Voice Agent with Real-time Web Form Filling |
| 2 | + |
| 3 | +This project demonstrates an advanced voice agent that conducts phone questionnaires while automatically filling out web forms in real-time using Stagehand browser automation. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Voice Conversations**: Natural voice interactions using Cartesia Line |
| 8 | +- **Real-time Form Filling**: Automatically fills web forms as answers are collected |
| 9 | +- **Browser Automation**: Uses Stagehand AI to interact with any web form |
| 10 | +- **Intelligent Mapping**: AI-powered mapping of voice answers to form fields |
| 11 | +- **Async Processing**: Non-blocking form filling maintains conversation flow |
| 12 | +- **Auto-submission**: Submits forms automatically when complete |
| 13 | + |
| 14 | +## Architecture |
| 15 | + |
| 16 | +``` |
| 17 | +Voice Call (Cartesia) → Form Filling Node → Records Answer |
| 18 | + ↓ |
| 19 | + Stagehand Browser API |
| 20 | + ↓ |
| 21 | + Fills Web Form Field |
| 22 | + ↓ |
| 23 | + Continues Conversation |
| 24 | + ↓ |
| 25 | + Submits Form on Completion |
| 26 | +``` |
| 27 | + |
| 28 | +## Setup |
| 29 | + |
| 30 | +1. Install dependencies: |
| 31 | +```bash |
| 32 | +pip install -r requirements.txt |
| 33 | +``` |
| 34 | + |
| 35 | +2. Set up environment variables: |
| 36 | +```bash |
| 37 | +cp .env.example .env |
| 38 | +# Add your GEMINI_API_KEY |
| 39 | +``` |
| 40 | + |
| 41 | +3. Run the agent: |
| 42 | +```bash |
| 43 | +python main.py |
| 44 | +``` |
| 45 | + |
| 46 | +## Components |
| 47 | + |
| 48 | +### StagehandFormFiller |
| 49 | +- Manages browser automation |
| 50 | +- Opens and controls web forms |
| 51 | +- Maps conversation data to form fields |
| 52 | +- Handles form submission |
| 53 | + |
| 54 | +### FormFillingNode |
| 55 | +- Voice-optimized reasoning node |
| 56 | +- Integrates Stagehand browser automation |
| 57 | +- Manages async form filling during conversation |
| 58 | +- Provides status updates |
| 59 | + |
| 60 | +### FormFieldMapping |
| 61 | +- Maps YAML questions to web form fields |
| 62 | +- Transforms voice answers to form-compatible formats |
| 63 | +- Handles different field types (text, select, checkbox, etc.) |
| 64 | + |
| 65 | +## Configuration |
| 66 | + |
| 67 | +The system can be configured through: |
| 68 | + |
| 69 | +- `form.yaml`: Define questionnaire structure |
| 70 | +- `FORM_URL`: Target web form to fill |
| 71 | +- `headless`: Run browser in background (True) or visible (False) |
| 72 | +- `enable_browser`: Toggle browser automation on/off |
| 73 | + |
| 74 | +## Example Flow |
| 75 | + |
| 76 | +1. User calls the voice agent |
| 77 | +2. Agent asks: "What type of voice agent are you building?" |
| 78 | +3. User responds: "A customer service agent" |
| 79 | +4. System: |
| 80 | + - Records the answer |
| 81 | + - Opens browser to form (if not already open) |
| 82 | + - Fills "Customer Service" in the role selection field |
| 83 | + - Takes screenshot for debugging |
| 84 | +5. Agent asks next question |
| 85 | +6. Process continues until all questions answered |
| 86 | +7. Form is automatically submitted |
| 87 | + |
| 88 | +## Advanced Features |
| 89 | + |
| 90 | +- **Background Processing**: Form filling happens asynchronously |
| 91 | +- **Error Recovery**: Continues conversation even if form filling fails |
| 92 | +- **Progress Tracking**: Monitor form completion status |
| 93 | +- **Screenshot Debugging**: Captures screenshots after each field |
| 94 | +- **Flexible Mapping**: AI interprets answers for different field types |
| 95 | + |
| 96 | +## Testing |
| 97 | + |
| 98 | +Test with different scenarios: |
| 99 | +- Complete questionnaire flow |
| 100 | +- Interruptions and corrections |
| 101 | +- Various answer formats |
| 102 | +- Multi-page forms |
| 103 | +- Form validation errors |
| 104 | + |
| 105 | +## Production Considerations |
| 106 | + |
| 107 | +- Set `headless=True` for production |
| 108 | +- Configure proper error logging |
| 109 | +- Add retry logic for form submission |
| 110 | +- Implement form validation checks |
| 111 | +- Consider rate limiting for API calls |
0 commit comments