# Day 7 - Jan 30 2026

Build a persistent, interactive AI application that runs outside the web browser.

### 1. The "Chat Loop" Architecture

Every AI agent, from Siri to Jarvis, runs on a simple infinite loop.

1. Wait for Input.
2. Process (Send to LLM).
3. Act (Print output).
4. Repeat.

In my code, I implemented this using `while True`, which creates a continuous session until a "break" condition (`exit`) is met.

### 2. State Management (Memory)

An LLM is stateless—it doesn't remember the previous question unless you send it back.

* The List Technique: I created a list called `conversation_history`.
* The Trick: Every time the user speaks OR the AI replies, I append that message to the list.
* The Result: When I send the 3rd question, I am actually sending the *entire* list of previous messages too. This gives the AI "Short-Term Memory."

### 3. Persistence (Logging)

Memory in RAM is lost when the program closes. To solve this, I built a simple Logger.

* File I/O: Using `open(filename, "a")` (Append Mode) ensures I don't delete old chats.
* Value: This allows me to audit the AI's performance later or build a dataset for fine-tuning in the future.

### Status:

* [x] Built CLI Interface (Terminal-based)
* [x] Implemented Conversation History (Context aware)
* [x] Implemented File Logging (Persistence)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://shankar-lab.gitbook.io/mylearning/15-days-genai-learning-challenge/day-7-jan-30-2026.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
