A minimal, real-time voice agent that answers a basic support inquiry (case status) and conditionally allows escalation based on explicit decision rules. The goal is to demonstrate how voice interaction, AI reasoning, and policy-based decisioning can be cleanly separated in a minimal, easy-to-understand setup.
This PoC showcases policy-aware Voice AI for customer support in fintech, healthtech, and education, where real-time conversations must remain safe, auditable, and governed as complexity grows.
This system demonstrates default-deny execution for Voice AI by:
- Answering simple customer support inquiries ("Why is my case still open?")
- Applying explicit decision rules using LangGraph
- Conditionally escalating live calls to human agents
- Maintaining strict separation between LLM interpretation, policy decision-making, and voice delivery
- Real-time voice interaction via Twilio and Pipecat
- Policy-driven decision making using LangGraph with default-deny execution
- Live call escalation to human agents when policies allow
- Intent extraction without execution authority (LLMs interpret only)
- Minimal architecture designed for clarity and auditability
flowchart TB
subgraph "Twilio"
TC[Incoming Call]
TW[Twilio WebSocket]
end
subgraph "FastAPI Server"
WH[Webhook Handler<br/>POST /]
WS[WebSocket Endpoint<br/>/ws]
end
subgraph "Pipecat Voice Pipeline"
direction LR
IN[WebSocket Input]
STT[STT Service<br/>Deepgram]
CTX[Context Aggregator]
LLM[Bot LLM<br/>OpenAI GPT-4o-mini]
TTS[TTS Service<br/>Cartesia]
OUT[WebSocket Output]
IN --> STT
STT --> CTX
CTX --> LLM
LLM --> TTS
TTS --> OUT
end
subgraph "Background Monitor Task"
MON[monitor_messages<br/>Runs every 2s]
EXTRACT[Extract Case Number<br/>Regex + Spoken Numbers]
ROUTE[Route to LangGraph]
end
subgraph "LangGraph Decision Plane"
direction TB
START[run_graph]
INTENT[extract_intent<br/>LLM extracts intent only]
POLICY[evaluate_policy<br/>Check auth level]
ROUTER{route_decision}
STATUS[status_node<br/>Read-only]
ESCALATE[escalate_node<br/>Side effect]
DENY[deny_node]
START --> INTENT
INTENT --> POLICY
POLICY --> ROUTER
ROUTER -->|allow_status| STATUS
ROUTER -->|allow_escalate| ESCALATE
ROUTER -->|deny| DENY
STATUS --> END_NODE[END]
ESCALATE --> END_NODE
DENY --> END_NODE
end
subgraph "Tools & Actions"
GET_STATUS[get_case_status<br/>Read-only tool]
FORWARD[forward_call_to_agent<br/>Twilio API]
end
subgraph "Response Flow"
RESP[Response Text]
TEXT_FRAME[TextFrame]
end
TC -->|POST /| WH
WH -->|TwiML| TW
TW <-->|WebSocket| WS
WS <-->|Audio Stream| IN
OUT -->|Audio Stream| WS
CTX -.->|Monitor Messages| MON
MON --> EXTRACT
EXTRACT --> ROUTE
ROUTE -->|user_input, case_number, call_sid| START
START -.->|response_text, escalated| RESP
RESP --> TEXT_FRAME
TEXT_FRAME -->|Queue Frame| TTS
STATUS --> GET_STATUS
ESCALATE --> FORWARD
FORWARD -->|Call Transfer| TW
style START fill:#e1f5ff
style INTENT fill:#fff4e1
style POLICY fill:#ffe1f5
style STATUS fill:#e1ffe1
style ESCALATE fill:#ffe1e1
style DENY fill:#ffcccc
style MON fill:#f0f0f0
style ROUTE fill:#f0f0f0
- Call Initiation: Twilio receives call → FastAPI webhook returns TwiML → WebSocket connection established
- Voice Pipeline: Audio flows through Pipecat: STT → Context → Bot LLM → TTS
- Background Monitoring: Monitor task watches conversation, extracts case numbers, routes to LangGraph
- Policy Decision: LangGraph extracts intent → evaluates policy → routes to appropriate action node
- Execution: Tools execute (read-only status lookup or call escalation)
- Response: LangGraph response injected as TextFrame → TTS → spoken to user
LLMs interpret.
Graphs decide.
Voice delivers.
The system enforces strict boundaries:
- LLMs extract intent only (no execution authority)
- LangGraph evaluates policies and routes execution
- Voice pipeline delivers responses
- Tools are only accessible through explicit LangGraph routing
Two distinct LLM instances:
- Bot LLM (
bot.py): Handles conversation flow and natural language responses. No execution authority. - LangGraph LLM (
graph.py): Extracts intent only (returns structured JSON). No decisions or actions.
Policy decisions and tool execution are handled exclusively by LangGraph's state machine.
- Python 3.10 or higher
- Twilio account with Voice API access
- OpenAI API key
- Deepgram API key
- Cartesia API key (optional, for alternative TTS)
- ngrok or similar tunneling service (for local development with Twilio webhooks)
# Clone the repository
git clone <repository-url>
cd policy-aware-voice-ai-customer-support
# Install dependencies
pip install -e .# Build the image
docker build -t policy-aware-voice-ai .
# Run the container
docker run -p 8000:8000 --env-file .env policy-aware-voice-ai-
Copy the example environment file:
cp env.example .env
-
Fill in your API keys and configuration:
# Twilio Configuration TWILIO_ACCOUNT_SID=your_account_sid TWILIO_AUTH_TOKEN=your_auth_token # Pipecat Voice Services DEEPGRAM_API_KEY=your_deepgram_key OPENAI_API_KEY=your_openai_key CARTESIA_API_KEY=your_cartesia_key # Optional # Optional Configuration WEBSOCKET_URL=wss://your-domain.com/ws # Auto-detected if not set SUPPORT_PHONE_NUMBER=+1234567890 COMPANY_NAME=YourCompany
-
Start the FastAPI server:
uvicorn main:app --host 0.0.0.0 --port 8000
-
Expose your local server to Twilio (required for webhooks):
ngrok http 8000
-
Configure your Twilio phone number webhook URL:
- Set the webhook URL to:
https://your-ngrok-url.ngrok.io/ - Ensure the URL is accessible via HTTPS/WSS
- Set the webhook URL to:
-
Make a test call to your Twilio phone number
The application is stateless and container-friendly. Deploy using:
- Docker containers
- Cloud platforms (AWS ECS, Google Cloud Run, etc.)
- Serverless platforms (with WebSocket support)
Ensure:
- HTTPS/WSS endpoints are configured
- Environment variables are securely managed
- WebSocket connections are properly proxied
- FastAPI - Web framework and WebSocket server
- Pipecat (v0.0.63) - Real-time audio processing pipeline (API Reference)
- Twilio - Call webhooks, audio streaming, and live call forwarding
- Deepgram - Speech-to-Text (STT)
- OpenAI - Bot LLM (conversation) and LangGraph LLM (intent extraction)
- Cartesia - Alternative Text-to-Speech provider
- LangGraph - Explicit decision & execution plane for policy enforcement
- LangSmith (optional) - Tracing and debugging
main.py- FastAPI server with webhook and WebSocket endpointsbot.py- Pipecat voice pipeline and conversation managementgraph.py- LangGraph state machine for policy enforcementpolicies.py- Decision rules and policy definitionstools.py- Backend actions (including call escalation)prompts.py- LLM system prompts for intent extractiondocs/- Comprehensive documentation
For detailed documentation, see the docs/ directory:
- Architecture Overview - System architecture and components
- API Reference - Complete API endpoint documentation
- High-Level Flow - Detailed workflow and process flows
- Incoming Call: Customer calls the Twilio phone number
- Webhook: Twilio sends a POST request to
/, server responds with TwiML pointing to/ws - WebSocket Connection: Twilio establishes WebSocket connection for bidirectional audio
- Case Collection: Agent asks for case number (required for any actions)
- Intent Extraction: User asks "Why is my case still open?" → LangGraph LLM extracts intent only (structured JSON)
- Policy Evaluation: LangGraph evaluates policy rules (default-deny)
- Execution: Routes to appropriate outcome:
- Read-only case status (spoken)
- Escalation denied (spoken explanation)
- Escalation allowed → call forwarded to human agent
- In-memory storage only (no database)
- One case per session
- One inquiry per session
- No persistence (data lost on restart)
- No background jobs or retries
- Simulated authentication levels
- Use HTTPS/WSS in production
- Store secrets in environment variables
- Implement proper authentication for production use
- Review and secure Twilio webhook endpoints
See LICENSE for details.