Back to guides
5
4 min

Support App

Building the Chat Interface

Why the Interface Matters

The best AI pipeline is useless without a good interface. The chat UI needs to accomplish three things: build customer trust (fast responses, accurate answers), enable agent visibility (classification details, escalation reasons), and handle edge cases gracefully (errors, escalation, handoff).

Key Concepts

SSE Streaming

The chat uses Server-Sent Events (SSE) — the same protocol ChatGPT uses. The server sends events as they happen:

data: {"type":"metadata","intent":"password_reset","confidence":0.9}

data: {"type":"token","content":"I understand "}
data: {"type":"token","content":"you're having "}
data: {"type":"token","content":"trouble..."}

data: [DONE]

Why streaming? Two reasons:

  • Perceived speed — The customer sees the response building word-by-word. A 3-second response that streams feels faster than a 2-second response that appears all at once.
  • Early metadata — Classification results arrive before the response, so the UI can show "Analyzing your question..." → "Searching knowledge base..." → response text.
  • Quick Actions

    Pre-written buttons for the 5 most common issues. These serve dual purpose:

  • Reduce friction — One click instead of typing a sentence
  • Improve classification — Pre-written queries are well-formed, giving the classifier high-confidence input
  • Quick actions should cover the issues that represent 60-70% of ticket volume. For most SaaS products: login issues, billing questions, data export, integration problems, cancellation.

    Metadata Bar

    Below each AI response, a metadata bar shows:

  • Intent — What the AI thinks the customer wants
  • Confidence — How sure the AI is (percentage)
  • Topic — Product area affected
  • Escalation status — Orange badge when confidence is too low
  • This is primarily for internal use — support agents monitoring the AI's responses. In a customer-facing deployment, you might hide this behind a toggle or only show it to admin users.

    The Request Pipeline

    Each message goes through the full pipeline:

    User message
        │
        ├─ 1. Classify (intent, priority, topic, entities)
        │
        ├─ 2. Search (FAQ fast path → hybrid search)
        │
        ├─ 3. Extract snippet from best result
        │
        ├─ 4. Score confidence (intent + search + diversity)
        │
        ├─ 5. Check escalation rules
        │
        ├─ 6. Select and fill template
        │
        └─ 7. Stream response via SSE

    Agent Handoff

    When escalation triggers, the UI needs to:

  • Show a clear message: "Let me connect you with a specialist"
  • Display the escalation reason (for agents)
  • Preserve full conversation history for the receiving agent
  • Show estimated wait time
  • Optionally collect additional context ("Is there anything else that would help?")
  • The handoff should feel seamless. The customer shouldn't have to repeat their issue.

    Conversation Memory

    The chat maintains history between messages so the AI can reference previous context. "You mentioned earlier that you're on the Business plan" makes interactions feel continuous rather than stateless.

    History is passed with each API request and used for:

  • Context continuity ("As I mentioned...")
  • De-duplication ("I already tried that")
  • Entity accumulation (account ID mentioned in message 1 is available in message 3)
  • Architecture Pattern

    ┌──────────────────────────────┐
    │  Chat UI (React Client)       │
    │  ┌────────────────────────┐  │
    │  │ Messages + Metadata     │  │
    │  │ Quick Action Buttons    │  │
    │  │ Input + Send            │  │
    │  │ Escalation Badge        │  │
    │  └────────────────────────┘  │
    └──────────┬───────────────────┘
               │ POST /api/chat (SSE)
               ▼
    ┌──────────────────────────────┐
    │  API Route (Server)           │
    │  classify → search → respond  │
    │  → stream via SSE             │
    └──────────────────────────────┘

    What You'll Build

  • Start the Next.js dev server and explore the pre-seeded chat UI
  • Wire the chat API to the real classification, retrieval, and response pipeline
  • Add ticket context panel, suggested follow-ups, and agent handoff
  • Polish with conversation memory, CSAT collection, or rich formatting
  • Glossary

    TermMeaning
    SSEServer-Sent Events — streaming protocol for real-time text
    Quick actionsPre-written buttons for common support queries
    Metadata barUI element showing classification details
    Agent handoffSeamless transfer from AI to human agent
    Conversation memoryMaintaining context across multiple messages

    This is chapter 5 of AI Customer Support Agent.

    Get the full hands-on course — free during early access. Build the complete system. Your projects become your portfolio.

    View course details