Skip to main content

The Mind's Eye - Engineering a CLI for Intelligent AI Interaction

8 min read

We’ve reached the end of the journey. The AI system has a dual-memory architecture, a dynamic context engineering core, and autonomous learning capabilities. It can remember, reason across conversations, and self-improve.

Here are the previous articles in the series:

But a brilliant mind with no interface is useless. For the finale, we’re looking at the Command-Line Interface (CLI), the user’s window into this system. It’s about engineering an interface that provides control, clarity, and direct access to the AI’s memory-driven features.

I could have built a full UI for this project, but that would pile on complexity for now. If you fancy building one yourself, go for it and share your work.

The CLI as an AI Interaction Layer

The interface isn’t just a wrapper; it’s an integral part of how users experience intelligence. A well-designed CLI (text-based as it is) can offer precise control, particularly when managing something as nuanced as AI memory.

Our CLI is deliberately minimal yet powerful. Users converse naturally while having clear commands to manipulate the AI’s conversational state and retrieve specific memories.

The commandHandler.js file acts as a router, splitting natural language input (for the AI) from specific commands (for the memory management system).

// cli/commandHandler.js

// ... various imports for readline, ConversationManager, display modules ...

export class ChatCLI {
  constructor(conversationManager) {
    this.conversationManager = conversationManager;
    this.rl = readline.createInterface({
      input: process.stdin,
      output: process.stdout,
    });
    this.conversationId = null; // Currently active conversation ID
  }

  async handleUserInput() {
    const input = await this.rl.question('You: ');

    if (input.startsWith('/')) {
      // If it starts with '/', it's a command for the CLI, not the AI.
      await this.handleCommand(input);
    } else if (this.conversationId) {
      // If there's an active conversation, send the message to the AI.
      await this.sendMessage(input);
    } else {
      // No active conversation and not a command, so start a new chat.
      await this.startNewConversation(input);
    }
  }

  // ... handleCommand, sendMessage, startNewConversation methods ...
}

Clear separation of concerns: the AI handles natural language processing for conversation, the CLI handles meta-level management of those conversations and the underlying memory systems.

Commander of Context: CLI Commands for Memory Management

The CLI ships with a suite of commands engineered to give users direct control over the AI’s memory. These are the levers and buttons for managing the contextual boundaries of every interaction.

1. /new [optional message], Resetting the AI’s Workbench

Does precisely what it says on the tin: initiates an entirely new conversation. From the AI’s perspective, it’s a fresh, empty workbench (a new Short-Term Conversational Memory, or STCM).

  • AI Implications: This ensures context isolation. If you’re discussing holiday plans and then want to switch to a coding problem, /new guarantees the AI won’t accidentally try to book a flight to your code repository. Prevents irrelevant context from polluting the prompt, which improves LLM accuracy and trims token costs. Any message provided directly after /new becomes the first message of the new conversation.

2. /list, Peering into Past Discussions

Provides an overview of all previously engaged conversations. Retrieves unique IDs and creation timestamps from the STCM.

  • AI Implications: An organisational aid that lets users visually inspect the AI’s short-term conversational history. The first step towards re-engaging with a past context.

3. /load <conversationId>, Time-Travelling the AI’s Memory

Here’s where re-engaging with past context happens. Provide a conversationId from the /list command, and the AI loads all associated summaries and recent messages back into its active STCM.

  • AI Implications: Directly manipulates the AI’s operational context. When a conversation is loaded, the SessionManager constructs prompts using the stored summaries and messages from that specific historical thread. The AI picks up exactly where it left off. Critical for long-running projects or complex discussions.

4. /memories <query>, Direct Semantic Access to Enduring Knowledge

Arguably the most powerful user-facing feature. It lets users bypass the conversational flow and directly query the AI’s enduring knowledge base using natural language.

  • AI Implications:
    • Semantic Search in Action: The user’s <query> input gets converted into a vector embedding, then used to perform a semantic search against the entire LTSM (summaries and critical facts from all past conversations).
    • Beyond Keywords: The AI isn’t searching for literal keywords; it’s searching for concepts and meanings. If you type /memories book recommendations, it might surface a summary about a discussion you had weeks ago about “great reads for summer,” even if the word “book” never appeared in that summary.
    • User Empowerment: Turns the AI’s vast memory into a personal, intelligent search engine. Users can recall specific facts or past discussions without remembering which conversation they occurred in.
$

The AI serves as a personal knowledge manager, pulling out semantically relevant information that you yourself might have forgotten.

5. /delete <id>, Removing Conversations

Lets users remove a conversation by its ID or list position number. Provides control over the STCM for cleaning up unwanted or irrelevant conversation history.

6. /summary, Viewing the Current Conversation Summary

Displays the AI-generated summary of the active conversation, including message count and last update time. Also indicates when the next summary will be generated.

  • AI Implications: Provides transparency into how the AI is compressing and understanding the current conversation. Users can see what context the LLM is actually working with.

7. /extract, Extracting Critical Information

Analyses current conversation messages for critical facts and stores extracted information with importance and confidence scores.

  • AI Implications: Gives users manual control over the autonomous learning process from Part 5. Useful when you know a conversation contains important information that should be preserved in long-term memory.

8. /stats, Memory Statistics

Displays both short-term (SQLite) and long-term (Firestore) memory statistics. Gives users visibility into the system’s storage state.

9. /info, Session Information

Shows details about the current conversation session, providing context about the active state.

10. /help & /exit, The Essentials

/help provides a quick reminder of all available commands. /exit gracefully terminates the application, handling proper resource cleanup.

$

The Repo

The source code is hosted on GitHub at https://github.com/tpiros/the-chat. Setup instructions are in the README.

Wrapping Up

That’s the complete journey: from the fundamental challenges of LLM statelessness to a self-improving AI system that remembers, learns, and engages. We’ve seen how Context Engineering (dual-memory architecture, dynamic prompt construction, autonomous memory enrichment) transforms a stateless model into a genuinely intelligent conversational agent.

The future of AI isn’t just about bigger models. It’s about smarter systems bolted around those models. By understanding token economies, prompt structures, and AI-driven memory management, we can build applications with real coherence, personalisation, and enduring utility.

Thanks for following along. I hope this series has shown not just how these systems get built, but why these engineering choices matter for shaping intelligent interactions.

Happy engineering!