# AI Support Chatbot — PRD (v1)

**Status:** Draft for team alignment · **Teams:** App team, AI team, Product, Coaches

---

## 1. What we are building
An in-app AI support assistant. The user taps the chat icon and talks to the AI first. The AI
answers support and program questions instantly from our approved knowledge. When it cannot answer
(or the user asks for a person), it hands off to a human coach in Freshchat, passing along the full
conversation so the coach has context and the user never repeats themselves.

## 2. Why
Today every support question goes to 7-8 human coaches via Freshchat. The AI answers the common ones
instantly and 24/7, so coaches only handle what actually needs a human. Better for users (instant
answers), lighter for coaches (less volume).

## 3. Scope for v1 (kept deliberately small)
- **Entry:** chat icon opens the AI only. No "AI vs human" choice screen.
- **Human is always one tap away:** a persistent "Talk to a coach" button in the AI screen.
- **Same brain as today:** the current approved knowledge base (~487 answers). No content scope change.
- **Handoff:** on escalation, a coach is assigned in Freshchat and a short AI summary paragraph is
  attached for the coach (in their agent view); the user just gets connected.
- **AI chat history lives in our database:** a single continuous thread per user, fetched by the app
  via `GET /history` to show past AI chats. Coach conversations live in Freshchat (as today). The
  same store also powers the improvement loop; because it is user-facing it is kept verbatim and
  secured (restricted access + retention) rather than redacted.

---

## 4. User journey

### New chat (user has no open coach conversation)
1. User taps the chat icon.
2. The **AI screen opens fresh** with a greeting.
3. User asks questions; the AI answers instantly.
4. One of two things happens:
   - The AI resolves it. Done.
   - The AI escalates (it cannot answer, or it is medical/crisis/frustration, or the user taps
     "Talk to a coach").
5. On escalation: a **coach is assigned in Freshchat**, the AI transcript + summary is posted into
   that thread, and the screen moves to Freshchat. The coach replies (as they do today).

### Returning chat (user taps the icon again later)
The app makes one check: **is there an open coach conversation?**
- **Yes (a coach thread is still open):** open that **Freshchat thread** directly so they continue
  with the coach where they left off.
- **No (never escalated, or the coach has closed the thread):** open a **fresh AI screen**. If they
  need a human again, the AI escalates and a **new** coach conversation is created.

So: **open coach thread -> Freshchat. Otherwise -> AI.** A closed chat simply means the next visit
starts fresh with the AI. New issue = new AI chat = (if needed) new coach assignment.

### Crisis (any point)
If a user types self-harm content, the AI immediately shows the helpline response and escalates to a
human. This never stays inside the AI.

---

## 5. What each team needs to do (outline)

### App team (the bulk of the work)
- Build the native AI chat screen (message bubbles, input, typing indicator, formatted text).
- Entry routing: on tapping the chat icon, resume an open coach thread if one exists, else open the
  AI screen.
- Persistent "Talk to a coach" button that triggers the handoff.
- Call our `/chat` API (send message, history, program, platform, current day, subscription status).
- On escalation: assign a coach in Freshchat and post the AI transcript + summary into the thread,
  routed to the right coach team (coaching vs technical).
- Thumbs up/down on answers, sent to our `/feedback` API.
- Hide the AI for LeanSure (P11) users (the knowledge base is smoking-only).
- Map the app's current day value to the day number our API expects.
- Two quick checks (spikes): does Freshchat tell us if a thread is open or closed (for routing), and
  confirm posting the transcript into the Freshchat thread reads as one continuous conversation.

### AI team (our part, small)
- Provide the API (done and live) and keep the knowledge base updated.
- Lock the escalation-reason values so an unexpected value cannot mis-route.
- Move chat logging to a restricted production database, strip obvious personal info (email, phone)
  before storing, use a hashed user id, and set a retention window.
- Add production auth (a token check) for the full rollout; a shared key is fine for the pilot.

### Product
- Confirm the v1 scope (AI-first entry, human always available).
- Provide the program content later (day-wise summaries of the 6-day, 42-day, and post-quit programs)
  to make answers deeper and stage-aware. Not needed for the pilot.
- Decide the data-retention window and what the coach sees on handoff (summary + full transcript).

### Coaches / Ops
- Nothing changes in how they work: escalations arrive in the existing Freshchat channels, now with
  an AI summary and transcript attached.

---

## 6. Out of scope for v1 (do later)
- A unified in-app history that merges the AI thread with coach chats in one view (AI history is in
  our DB via `/history`; coach chats stay in Freshchat).
- Production-grade auth (token-based), full PII redaction/retention automation, dedicated production
  hosting with alerting. These harden in parallel and do not block the pilot.
- Bringing the AI into deeper program/coaching content (phase 2, after Product shares the program material).

---

## 7. Pilot definition (what "live to see the UX" means)
App builds the AI screen + `/chat` wiring + handoff-with-transcript + entry routing + LeanSure gating.
AI team runs the current service with logging on a non-shared database. Ship on the current host,
watch real usage and thumbs feedback, then harden and widen.
