A real-time AI-powered phone call agent that provides postpartum care support to new mothers.
Built with: FastAPI · Twilio Media Streams · ElevenLabs Conversational AI
POST /call/outbound {"to": "+1234567890"}
│
▼
Twilio initiates outbound call
│
▼ (recipient answers)
Twilio fetches TwiML from POST /twiml/answer
│
▼
TwiML opens Media Stream WebSocket to /twiml/ws
│
▼
FastAPI bridges audio in real time:
Phone ──mulaw 8kHz──► Twilio ──WS──► FastAPI ──WS──► ElevenLabs AI
Phone ◄─mulaw 8kHz── Twilio ◄─WS── FastAPI ◄─WS── ElevenLabs AI
│
STT → LLM (Claude) → TTS
The AI agent, Bloom, asks about physical recovery, emotional wellbeing, infant feeding, and postpartum mental health — providing warm, evidence-based guidance and escalating to professional care when needed.
git clone <repo>
cd hackathon
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txtcp .env.example .envEdit .env and fill in:
| Variable | Where to find it |
|---|---|
TWILIO_ACCOUNT_SID |
Twilio Console → Account Info |
TWILIO_AUTH_TOKEN |
Twilio Console → Account Info |
TWILIO_FROM_NUMBER |
Your Twilio phone number (must have Voice enabled) |
ELEVENLABS_API_KEY |
ElevenLabs → Profile → API Keys |
ELEVENLABS_VOICE_ID |
Optional — defaults to Rachel (warm, calm voice) |
ELEVENLABS_AGENT_ID |
Leave empty on first run — auto-created! |
PUBLIC_BASE_URL |
Your ngrok/tunnel URL (see step 3) |
Twilio requires a publicly accessible URL — it cannot reach localhost.
# Install ngrok: https://ngrok.com/download
ngrok http 8000Copy the https://xxxx.ngrok-free.app URL and set PUBLIC_BASE_URL in .env.
uvicorn app.main:app --reloadOn first run, the app will automatically create the ElevenLabs agent and print its ID:
========================================================
✅ ElevenLabs agent created!
Agent ID: agent_xxxxxxxxxxxxxxxxxx
👉 Add this to your .env file:
ELEVENLABS_AGENT_ID=agent_xxxxxxxxxxxxxxxxxx
========================================================
Copy this ID into .env so it isn't recreated on every restart.
curl -X POST http://localhost:8000/call/outbound \
-H "Content-Type: application/json" \
-d '{"to": "+14155552671"}'Response:
{
"call_sid": "CA...",
"status": "queued",
"to": "+14155552671",
"message": "📞 Call initiated to +14155552671. Bloom will speak when the call is answered."
}Visit http://localhost:8000/docs for the interactive Swagger UI.
Bloom, the AI agent, will:
- Greet the mother warmly and ask how she's feeling overall
- Physical check — bleeding, pain, wound healing, sleep, appetite
- Emotional check — mood, anxiety, baby bonding, baby blues vs. PPD screening
- Infant feeding — breastfeeding support or formula feeding guidance
- Newborn care — answer any care questions
- Close — summarize advice, reaffirm support, invite further questions
If the mother describes:
- Heavy bleeding, fever, severe pain → Bloom advises immediate medical attention
- Thoughts of self-harm → Bloom firmly redirects to emergency services
hackathon/
├── app/
│ ├── main.py # FastAPI app entrypoint
│ ├── config.py # Settings from .env
│ ├── prompts/
│ │ └── postpartum.py # AI agent system prompt & first message
│ ├── routers/
│ │ ├── calls.py # POST /call/outbound
│ │ └── twiml.py # POST /twiml/answer + WebSocket /twiml/ws
│ └── services/
│ ├── twilio_service.py # Twilio client wrapper
│ └── elevenlabs_service.py # ElevenLabs agent lifecycle + signed URLs
├── .env.example # Credentials template
├── requirements.txt
└── README.md
Browse ElevenLabs Voice Library and update ELEVENLABS_VOICE_ID in .env.
| Voice | ID | Character |
|---|---|---|
| Rachel (default) | 21m00Tcm4TlvDq8ikWAM |
Warm, calm |
| Domi | AZnzlk1XvdvUeBnXmlld |
Strong, confident |
| Bella | EXAVITQu4vr4xnSDxMaL |
Soft, gentle |
Edit app/prompts/postpartum.py. The agent is recreated each time ELEVENLABS_AGENT_ID is cleared from .env.
In app/services/elevenlabs_service.py, change the "llm" field in _create_agent():
"claude-3-5-sonnet"(default, best quality)"claude-3-5-haiku"(faster, lower cost)"gpt-4o"(OpenAI alternative)
- Python 3.10+
- Twilio account with Voice-capable phone number
- ElevenLabs account (Starter plan or above for Conversational AI)
- ngrok (or another tunnel) for local development