Skip to content
reaatech

Files · After-Hours Pet Emergency Triage Agent for Small Vet Practices

75 (1 binary, 648.5 kB total)attempt 2

README.md·3539 B·markdown
markdown
# After-Hours Pet Emergency Triage Agent for Small Vet Practices
 
> Automate urgency assessment and reduce after-hours call burden on vets
 
A 24/7 AI-powered voice agent that answers after-hours calls, asks structured veterinary triage questions, assigns an urgency level, and provides spoken guidance — reducing false-alarm emergency visits and protecting veterinarians' rest.
 
## How it works
 
1. Call arrives via Twilio → Media Streams WebSocket
2. Deepgram STT transcribes caller speech in real-time
3. Agent-mesh classifier categorises the urgency (critical/urgent/routine/advice)
4. Confidence gate routes the call: high confidence → direct response, low confidence → clarification question
5. OpenAI LLM generates a structured triage assessment
6. Guardrails validate input (PII redaction, topic boundaries) and output (toxicity, hallucination checks)
7. ElevenLabs TTS speaks the triage response back to the caller
8. Langfuse traces the entire flow for observability
 
## Tech stack
 
- **Framework:** Next.js 16 (App Router) + Hono
- **LLM provider:** Agnostic (OpenAI SDK with configurable base URL)
- **Voice pipeline:** `@reaatech/voice-agent-core`, `@reaatech/voice-agent-telephony`, `@reaatech/voice-agent-stt`
- **Classification + routing:** `@reaatech/agent-mesh-classifier`, `@reaatech/agent-mesh-confidence`
- **Guardrails:** `@reaatech/guardrail-chain-guardrails`
- **TTS:** ElevenLabs (`@elevenlabs/elevenlabs-js`)
- **Observability:** Langfuse
 
## Getting started
 
```bash
pnpm install
# Copy .env.example to .env and fill in your API keys
pnpm dev
```
 
Twilio webhook URL: `https://your-domain/api/twilio/webhook`
Health check: `http://localhost:3000/api/health`
 
## Configuration
 
Copy `.env.example` to `.env` and fill in the required values:
 
| Variable | Description |
|----------|-------------|
| `OPENAI_API_KEY` | API key for the LLM provider (agnostic — works with OpenAI or any OpenAI-compatible endpoint) |
| `OPENAI_BASE_URL` | Base URL for the LLM API |
| `OPENAI_MODEL` | Model identifier (default: gpt-5.2) |
| `TWILIO_ACCOUNT_SID` | Twilio account SID for webhook signature validation |
| `TWILIO_AUTH_TOKEN` | Twilio auth token |
| `DEEPGRAM_API_KEY` | API key for Deepgram speech-to-text |
| `ELEVENLABS_API_KEY` | API key for ElevenLabs text-to-speech |
| `ELEVENLABS_VOICE_ID` | Voice ID for triage TTS responses |
| `LANGFUSE_PUBLIC_KEY` | Langfuse public key for LLM observability |
| `LANGFUSE_SECRET_KEY` | Langfuse secret key |
| `LANGFUSE_BASE_URL` | Langfuse endpoint URL |
| `SESSION_TTL` | Session time-to-live in seconds |
| `TRIAGE_BUDGET_TOTAL_MS` | Total latency budget for the voice pipeline |
| `TRIAGE_BUDGET_HARD_CAP_MS` | Hard latency cap |
| `TRIAGE_BUDGET_STT_MS` | STT stage budget |
| `TRIAGE_BUDGET_MCP_MS` | MCP/triage-LLM stage budget |
| `TRIAGE_BUDGET_TTS_MS` | TTS stage budget |
| `CONFIDENCE_THRESHOLD` | Minimum confidence for direct routing |
 
## Testing
 
```bash
pnpm test        # vitest run with coverage
pnpm typecheck   # TypeScript type checking
pnpm lint        # ESLint
```
 
## Deployment
 
Requires:
- A Twilio phone number configured to POST to your webhook URL
- WebSocket-capable hosting (Node.js server)
- API keys for OpenAI, Deepgram, ElevenLabs, and Langfuse
 
## Medical disclaimer
 
> **IMPORTANT:** This is an AI-assisted triage tool and is not a substitute for professional veterinary care. In case of emergency, contact your veterinarian or the nearest animal emergency hospital immediately.
 
## License
 
MIT — see [LICENSE](./LICENSE).