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.