On Day 9, the core challenge was State Management. Standard HTTP protocols are stateless—each request is isolated and holds no memory of previous exchanges. To build a natural conversational AI, the server must persist the history of user queries and bot replies to pass context dynamically to the LLM.

1. State Management: Client Concurrency and Session Isolation

A simple approach is storing history in a global list, but this leaks conversations between active users. A production-grade approach utilizes client-side encrypted cookies or session stores to isolate client chats. This ensures User A never sees User B's conversation log.

2. Prompt Composition: Role-Task-Style (RTS) Matrices

We studied prompt engineering frameworks for system instructions, following the formula: System Instruction = [Role Definition] + [Primary Task] + [Style Rules] (RTS). By designing a mapping dictionary, the chatbot can dynamically recompile its system instructions based on the active personality chosen by the user (StudyBot, CareerBot, FitnessBot).

3. Asynchronous Execution: Single-Page AJAX Interfaces

The curriculum assignment required a basic web template with a form that reload-posts the page on every single message. I rejected this full-page reload design and instead built a stateless backend API route (/api/chat) and wrote a clean, lightweight frontend JavaScript controller using the native browser Fetch API. When I demonstrated my single-page application to the class, they were stunned. The chat updates were instantaneous and fluid. Mentor Rashmi highly praised the AJAX single-page application, explaining to the class that building asynchronous endpoints is the exact industry standard for modern web engineering.

Key Learnings

  • Implementing concurrency-safe session state management to isolate user conversation histories.
  • Designing multi-personality system prompts containing dynamic role, task, and formatting rules.
  • Developing stateless REST API endpoints returning structured JSON data payloads.
  • Refactoring full-page form submissions into dynamic, asynchronous AJAX fetch requests.

Tools & Stack

  • Flask Sessions
  • Fetch API
  • JS
  • JSON Payload
  • Qwen-7B-Instruct
  • Python 3.11

Challenges Overcome

  • Securing session cookies and ensuring they modify state properly on nested object updates.
  • Restricting rolling chat history buffers to prevent context window overflow on long threads.

Task to be Performed

  • Implement session cookie middleware to store rolling lists of conversation turns.
  • Create a REST API route handling JSON input and returning conversational history arrays.
  • Design an interactive frontend script mapping response history to styled screen bubbles without page reloads.

Related Logs

Day 00

Onboarding & Exploration: Mapping the Core AI & Python Blueprint

Onboarding at Virtual Height, introducing the training program, providing an overview of the curriculum, and mapping the 2-week schedule.

May 29, 20264 min readRead Log
Day 01

Day 01: Foundations of AI, Python Lab, and the Velocity of Domain Mastery

Onboarding under Senior AI Trainer Rashmi, mapping the formal pillars of AI from ML to DL, mastering cross-platform Python execution, and demonstrating custom LLM and reverse engineering portfolios to the cohort.

Jun 01, 20264 min readRead Log