← All Projects
APPClient Project

I built an AI sales agent that qualifies, computes ROI, and books demos — by phone and chat.

A SaaS company needed to scale sales qualification without hiring more SDRs. I built a voice and chat agent that handles inbound leads 24/7 — qualifying prospects through natural conversation, computing personalized ROI with their real numbers, and booking demos on the calendar.

Next.js 14Claude APITwilioDeepgramElevenLabsPostgreSQLTypeScript
AI Sales Agent welcome screen
AI agent mid-discovery conversation
Mid-discovery — extracting business data through conversation
Personalized ROI computation
Live ROI computation with the prospect's own numbers
24/7
Inbound handling
13
Qualification slots
5
Safety guardrails
<400ms
Voice response target

Good leads were waiting. Or worse, leaving.

Inbound prospects called in and waited on hold. Outbound calls went unanswered because the team was stretched thin. By the time a human SDR got back to a lead, the buying window had often closed.

The company needed to qualify more leads faster without hiring more people — and the qualification had to be good enough to compute real ROI and book directly with an AE.

Six capabilities, one agent

01

Dual-Channel Qualification

Same qualification engine serves both a web chatbot and a voice phone agent. Chat gets rich formatting and SVG charts. Voice gets concise 1-2 sentence responses optimized for natural conversation flow.

02

13-Slot State Machine

Extracts order volume, average order value, commission rates, number of locations, and growth signals through natural conversation. Auto-stages through discovery, implication, ROI presentation, and close phases.

03

Live ROI Computation

Computes personalized ROI with real dollar figures mid-conversation using the prospect's own business data. Not a generic calculator — the numbers reflect their specific operation.

04

Automated Demo Booking

Claude uses tool calling to check Google Calendar availability and book demos during the conversation. Race-condition-safe with PostgreSQL FOR UPDATE locks to prevent double-booking.

05

Brain-Injected Playbook

Loads winning phrases, call patterns, objection handlers, and ROI stories from a knowledge database. The AI uses language that has actually closed deals before, not generic sales scripts.

06

Dynamic System Prompts

400+ lines of context injection that rebuilds per-turn based on qualification state, brain knowledge, and conversation stage. Haiku handles early discovery; Sonnet takes over for closing and tool use.

Five problems that made this harder than a chatbot

Dead air kills phone calls

If Claude takes more than 400ms to respond, the prospect hears silence and thinks the line dropped. I pre-cache 8 context-aware filler phrases on startup. If the model is still thinking, a natural filler plays instantly — "Let me pull that up for you" or "That's a great question" — while the real response generates. The prospect never hears dead air.

Prospects interrupt mid-sentence

When someone talks over the AI, you can't just keep playing audio. The system detects barge-in, immediately stops TTS playback, captures what the prospect said via Deepgram, and passes the interrupted context to Claude so it can resume coherently. It knows what it was saying and what got cut off.

Matching conversational pace

A fast talker getting slow, deliberate responses feels patronizing. A slow talker getting rapid-fire feels aggressive. The system measures prospect speaking speed via Deepgram word timings and dynamically adjusts ElevenLabs TTS speed between 0.85x and 1.1x to mirror their pace.

Keeping the AI on-script without sounding robotic

A 683-line guardrail system with five fences: PII fence hard-rejects credit card and SSN patterns. Topic fence redirects off-topic tangents. Pricing fence escalates to a human. Competitor fence reframes to value. Promise fence softens guarantees. Each fence has different handling behavior — some block, some redirect, some escalate.

Strategic silence as a sales technique

After presenting a big ROI number, the system inserts a deliberate 1.5-second pause. Silence after impact lets the number land psychologically. It also monitors connection quality via STT confidence and automatically shortens responses on poor connections.

Voice is a different beast than chat

The chat agent and voice agent share the same qualification engine and knowledge base, but the voice path adds an entire real-time audio pipeline. Twilio Media Streams deliver raw audio over WebSocket. Deepgram transcribes in real-time. Claude generates the response. ElevenLabs synthesizes speech. The voice agent runs as a separate PM2 process to isolate the WebSocket connection from the web server.

The system evolved from a single-tenant tool into a multi-tenant SaaS architecture with row-level security, org isolation, auth, and usage tracking — reflected in 22 database migrations across 6 schema versions.

Full Stack

FrontendNext.js 14 (App Router), React 19, Tailwind CSS 4, TypeScript
AIClaude Sonnet + Haiku (model routing by conversation stage), 400+ line dynamic prompt engine
VoiceTwilio Media Streams (WebSocket), Deepgram Nova-2 (real-time STT), ElevenLabs Turbo v2.5 (TTS)
BackendPostgreSQL, 22 migrations, Google Calendar API (OAuth2 + FreeBusy)
InfraDocker, PM2 (voice agent as separate process), Sentry monitoring

What changed

Before: Inbound leads waited for a callback. SDRs manually qualified over multiple touchpoints. ROI conversations happened late in the funnel, if at all.

After: Every inbound lead gets immediate, intelligent conversation — by phone or chat. Qualification happens in minutes, not days. Prospects see their personalized ROI before they ever talk to a human. Demos land on the calendar automatically.

Scope Touched

Full-stack app (Next.js, API routes, PostgreSQL, Google Calendar)
Real-time voice pipeline (Twilio, Deepgram, ElevenLabs)
Production AI (Claude model routing, dynamic prompts, guardrails)
Sales domain (13-slot qualification, ROI engine, playbook injection)
Multi-tenant SaaS (row-level security, org isolation, auth)
Infrastructure (Docker, PM2, Sentry monitoring)

Need an AI agent that actually sells?

Let's Talk