🤖

[Project 2a] “JackGPT” - AI Chat Assistant That Specializes in Myself

Conversational AI System (LangChain Orchestration + Shared Guardrails + Admin UI)

notion image
👉🏻
Executive Summary
This project describes a production-grade personal AI chat assistant designed to answer questions about my background, projects, and writing with predictable behavior. The system is built around a single LangChain-based execution path with a guardrail-first pipeline that governs intent routing, token budgeting, and safe fallbacks. Retrieval is supported when appropriate, but the architecture is primarily shaped around consistent conversational UX rather than retrieval complexity. Guardrails act as reliability infrastructure, ensuring that behavior remains deterministic and inspectable across presets and configuration changes. This document focuses on operating the assistant as a real system, emphasizing clarity, control, and long-term maintainability over experimentation.
  • Type: 🧭 Personal Learning & Demo (Non-Commercial)
  • Context: A production feature inside jackhpark.com that provides a consistent, “about me” chat experience backed by curated content and controlled routing.
  • Reference: Built on a customized chat UI + server router that standardizes guardrails, prompt construction, and streaming execution.
 
notion image

🎯 Objective

As a product manager, I wanted to build and operate a personal AI assistant that can reliably answer questions about my background, projects, and writing—without turning the system itself into an experimental playground.
This project helped me explore:
  • Designing a production-oriented conversational assistant with predictable behavior
  • Using LangChain as the primary orchestration layer for prompt construction and streaming execution
  • Applying shared guardrails to control intent routing, token budgets, and fallbacks
  • Operating the assistant end-to-end through presets, diagnostics, and admin controls
This is both a live feature on jackhpark.com and a hands-on exercise in owning an AI system in practice rather than in theory.

⚙️ High-Level System Overview

The assistant is implemented as a single LangChain-based execution path that begins at a unified chat entry point, applies a guardrail-first pipeline, and streams responses back to the UI.
Requests flow through a layered server structure (Entry → Shim → Heavy) to keep routing lightweight while isolating heavier orchestration and dependency logic behind a stable interface.
Retrieval may be invoked when appropriate, but it is treated as a supporting capability; the system is primarily shaped around guardrail-first execution and predictable conversational behavior.

🧠 High-Level Architecture

flowchart TD
  A["💬 User (Chat UI)"]

  subgraph Server["/api/chat"]
    G["<b>Guardrail Pipeline</b><br>Intent routing · Token budgeting\nHistory window · Prompt assembly"]
    L["LangChain Runnable<br>(Streaming)"]
  end

  subgraph LLM["🤖 LLM Provider"]
    M["<b>Admin-configurable</b><br>(Provider-agnostic factory)"]
  end

  A -->|"Query + history"| G
  G -->|"Shaped context & system prompt"| L
  L --> M
  M -->|"<b>Streamed tokens</b>"| A
This architecture reflects a single chat entry, guardrail-first execution, and a Node-based LangChain runtime with streaming output.

🧩 Key Components

  1. Guardrails (Shared Runtime Contract)
      • Message sanitization and normalization
      • Sliding history window with optional summaries
      • Intent routing to determine retrieval vs. prompt-only execution
      • Deterministic token budgeting and context shaping
      • Structured diagnostics surfaced via X-Guardrail-Meta
  1. LangChain Orchestration
      • Runnable-based prompt rendering and streaming execution
      • Clear separation between routing/guardrails and model invocation
  1. Retrieval (Supporting Capability)
      • Retrieval is invoked only when requests are routed as knowledge queries and configuration allows it
      • Retrieved content is compacted and shaped — deduplication, token-budget controls, and per-document quotas applied before reaching the model
      • Optional helpers (e.g., HyDE, auto-trigger logic, deduplication) are treated as tactical enhancements rather than core system identity
  1. Streaming UX
      • Server-side token streaming for responsive conversational interaction
      • “Answer first, metadata after” pattern to preserve reading flow
      • Citations and guardrail diagnostics appended as structured metadata after the streamed answer
  1. Admin Controls
      • Preset-based configuration for behavior tuning without code changes
      • Diagnostics that enable inspection and debugging without exposing secrets

🔧 Technical Architecture

flowchart TD
A["💬 Chat UI<br>(ChatFullPage · useChatSession)"]
subgraph Entry["API Entry"]
  R["/api/chat.ts<br>(thin dispatcher)"]
  LC["langchain_chat.ts<br>(timeout watchdog)"]
  LH["langchain_chat_impl_heavy.ts<br>(<b>lazy-loaded</b>, main handler)"]
end
subgraph Guardrail["Guardrail Pipeline (chat-guardrails.ts)"]
  G1["Sanitize & Normalize<br>(whitespace · language detect)"]
  G2["<b>Intent Router</b><br>knowledge · chitchat · command"]
  G3["History Window<br>(applyHistoryWindow · summarization)"]
  G4["<b>Token Budgeting</b><br>ragContextTokenBudget · historyTokenBudget<br><b>safeMode</b> halves budgets"]
  G5["Prompt Assembly<br>buildFinalSystemPrompt()<br>base → preset → session layers"]
end
subgraph Retrieval["LangGraph StateGraph · Retrieval"]
  C1["Rewrite · if enabled"] --> C2["HyDE · if enabled"] --> C3["Retrieve"] --> C4["Rerank · if enabled"] --> C5["Select context"]
end
subgraph Answer["RunnableSequence · Answer streaming"]
  C6["Format prompt"] --> C7["Stream answer"]
end
subgraph LLM["LLM Provider<br>(Admin-configurable allowlist)"]
  M["Provider-agnostic factory<br>(cloud · local · OpenAI-compatible)"]
end
A -->|"POST messages[]"| R
R --> LC --> LH
LH --> G1 --> G2 --> G3 --> G4
G4 -->|"knowledge · retrieval allowed"| C1
G4 -->|"chitchat · skip retrieval, fallback prompt"| G5
G4 -->|"command · skip retrieval, fallback prompt"| G5
G4 -->|"safeMode · skip retrieval"| G5
C5 --> G5
G5 --> C6
C7 --> M
M -->|"<b>Streaming tokens</b> + citations JSON"| A

🔒 Unified Guardrail System

The assistant relies on a shared guardrail pipeline that executes before any model call, ensuring deterministic and inspectable behavior across sessions and presets.
Key properties:
  • Deterministic routing: every request is classified before execution
  • Token discipline: history and context are clipped predictably
  • Stable prompt construction: prompts follow a consistent contract
  • Safe fallbacks: prompt-only execution when retrieval is unavailable or inappropriate
  • Inspectable diagnostics: X-Guardrail-Meta exposes intent, retrieval usage, and budget decisions to the UI
Guardrails function as UX reliability infrastructure, ensuring consistent and inspectable behavior as presets or model configurations evolve. The assistant executes through a unified guardrail pipeline that standardizes message sanitization, intent routing, context shaping, and token budgeting, ensuring consistent behavior regardless of underlying model configuration.

🔑 Core Features

  • Unified chat entry and routing driven by a guardrail-first execution model
  • Streaming responses for low-latency conversational UX
  • Configurable presets for safe iteration without code churn
  • Optional retrieval support with metadata-based citations
  • UI-surfaced diagnostics via X-Guardrail-Meta
  • Admin-facing controls for operational tuning and inspection

🧠 PM Learning Outcomes

  • Learned to prioritize predictable behavior over maximal capability
  • Gained appreciation for guardrails and token budgets as core UX levers
  • Developed stronger intuition around trade-offs in latency, complexity, and debuggability
  • Shifted focus from experimentation to system ownership and operability
  • Improved communication with engineers by grounding discussions in real execution constraints

🔧 Tech Stack

Layer
Technology
Frontend
Next.js 15, React 19, streaming chat UI
Routing Model
Primarily Pages Router, with a small App Router API surface for internal endpoints
Language / UI
TypeScript, Tailwind CSS, repo-level design-token contracts
Retrieval & Storage
Supabase + pgvector
LLM Orchestration
LangChain plus custom guardrail and RAG runtime code
Telemetry
Langfuse and PostHog
Local LLM Support
Optional local backends through Ollama or LM Studio

👉 Scope & Links

  • Repository: Unified with the site codebase, maintained as a distinct chat module
  • Purpose: A production-focused personal AI assistant that emphasizes behavioral consistency, inspectable decisions, and operational restraint, with deeper retrieval and telemetry systems intentionally deferred to follow-up projects.

🗺️ How This Fits Into the Larger System

  • Project 2a: AI Chat Assistant ← here — experience and orchestration
Together, these projects demonstrate an end-to-end view of building, operating, and improving AI systems through a product lens.