Building a Custom Memory System for AI Assistants: Solving the Identity Awareness Problem

    AI coding assistants lack persistent memory across sessions, forcing developers to rebuild context every time they start a new conversation. This article presents a lightweight, file-based memory system for AI assistants, built around a three-tier architecture: working memory (daily timestamped journals), project memory (structured project profiles), and long-term preferences (decision principles). It explains how instruction injection lets the assistant load memory at session start, walks through three practical scenarios including automated daily standups, data-driven weekly reviews, and a decision "braking" mechanism, and covers maintenance routines such as daily compression and weekly archiving to keep memory accurate. The approach requires no fine-tuning or vector databases, costs almost nothing, and keeps all data local.

    Background: When Your AI Assistant Has No “Yesterday”

    When using AI coding assistants (referred to as AI assistants below) for daily development and project collaboration, a frequent and frustrating problem emerges: the model itself has no persistent memory across sessions. Every new conversation window is like meeting a colleague for the first time. The assistant knows nothing about who you are, what project you are working on, the technical decisions made yesterday, or your coding style.

    The direct cost is a high “context reconstruction cost.” At the start of each workday, developers spend ten to twenty minutes patiently re-explaining to the assistant: “who I am,” “what project I’m working on,” and “where things stand.” This repetitive background briefing not only breaks flow state, but also often leads the assistant to give off-track suggestions due to information loss during handoff.

    During long-term use, I drew inspiration from the memory management approach of an open-source crawler framework, which maintains contextual continuity through layered storage of recent interactions, user profiles, and task states. Inspired by this, I built a lightweight memory system for my own AI assistant. The system relies neither on complex fine-tuning nor on vector databases. Instead, it uses the file system and structured templates to achieve the goal of “making the AI remember me” at minimal cost. After more than two weeks of real-world use, the results have been significant. This article shares the full design and implementation details.

    System Design: A Three-Tier Memory Architecture

    The core design philosophy mirrors human memory classification, divided into three layers: working memory (short-term), project memory (mid-term), and long-term preferences (long-term).

    1. Working Memory Layer: Timestamped Session Snapshots

    This layer records the concrete work details of recent days. The implementation is straightforward: in a dedicated local directory, create Markdown files named by date (for example, journal/2025-03-20.md). At the end of each workday, I append concise entries covering key progress, problems encountered, code changes, and next-day to-dos.

    2. Project Memory Layer: Structured Project Profiles

    For long-lived codebases, maintain a dedicated project_profile.md file with fixed fields: tech stack versions, core business logic descriptions, a list of known technical debt, current iteration goals, inter-module dependencies, and commonly used frontend-backend integration commands.

    3. Long-Term Preferences Layer: Decision Principles and Retrospective Conclusions

    A global file named preferences.md captures personal preferences around technology selection, coding standards, and work rhythm. Examples include: “prefer composition over inheritance,” “any data migration must be validated in a staging environment first,” and “before committing to a new opportunity, evaluate how well it aligns with the current path of building influence.”

    Data Injection: How the AI Accesses Memory

    The key to enabling memory is instruction injection at session start. I wrote a custom memory retrieval instruction into the configuration file so that the AI assistant executes it automatically at the beginning of every session.

    The instruction logic looks like this:

    1. [System instruction prefix]
    2. First read the following local files to understand the user's context:
    3. 1. Open the journal/ directory, find the records from the last three days, and extract unfinished items.
    4. 2. Read project_profile.md in the project root (if it exists) to understand the project architecture and constraints.
    5. 3. Read the global preferences.md to understand the user's decision-making preferences.
    6. If any of these files do not exist, ask the user whether to initialize the memory directory structure.

    During interactions, I require the assistant to follow a “confirm memory first, then answer” principle. Whenever a new topic or requirement change is introduced, it must first check for conflicts with the decision principles already stored in the memory base.

    Core Scenarios: Practice and Validation

    Scenario 1: Automatic To-Do Retrieval and a Zero-Cost Start to the Day

    Before the memory system, the daily startup routine was full of uncertainty. Now, a simple prompt like “What are we doing today?” is enough. Within seconds, the assistant digests yesterday’s records and generates today’s task list from working memory: which files need refactoring, which API integration is still incomplete, and which pending design proposal from a previous discussion needs finalizing. This mechanism works for general office tasks and coding alike. When working through technical debt, the memory base automatically links back to a FIXME comment recorded three weeks earlier and reminds me to prioritize that risk.

    Scenario 2: Data-Backed (and Brutally Honest) Weekly Reviews

    Another major value of the memory system is generating performance review reports. When I ask the assistant to comment on my recent state from a third-party perspective, it aggregates the past week’s records and extracts behavioral data: the number of meaningful code commits, documentation output frequency, and whether meeting decisions were actually implemented. Compared with human self-assessment, which tends to be overly generous, data-driven reviews are far more objective. For example, by analyzing conversation records, the assistant pointed out that I spent too much time in the “solution research” phase while failing to consolidate the outputs into the project profile, rendering part of that research effectively wasted. This kind of pointed feedback is exactly the insight the memory system provides.

    Scenario 3: A “Braking” Mechanism for Off-Track Decisions

    People are easily distracted by short-term temptations. An AI assistant with long-term memory can play the role of a brake. For instance, three weeks after I established a decision principle—“any new investment must feed back into my existing path of influence”—I tentatively floated the idea of “building a product for overseas markets.” The assistant immediately retrieved that principle and declined to give positive feedback. It even pulled up a conversation from three days earlier showing that I had expressed concerns about my own energy allocation, and used that to generate a targeted counter-recommendation, effectively intercepting an impulsive decision.

    Iteration and Optimization: Keeping Memory Fresh and Accurate

    To prevent the memory system from becoming a formality, you also need regular “forgetting” and update mechanisms:

    • Daily compression: Budget five minutes a day for the assistant to compress conversation records into concise log entries, filtering out background information and temporary parameters using regex or keyword filtering.
    • Weekly archiving: Once a week, move the previous week’s work logs from the journal/ directory into an archive/ directory, and revise the technical debt and progress status in project_profile.md.
    • Core index: For especially important context (such as the optimization logic for a high-performance computing task), extract it into a standalone glossary.md document to prevent it from being diluted by later information.

    Applicability and Further Thoughts

    This approach is well suited to local deployment by individual developers or small teams of three to five people. The cost is extremely low: it depends on no external APIs or cloud services, is implemented purely through the file system and sensible prompt engineering, and keeps all data entirely under your own control. To extend it to multi-person teams, you can manage the memory directory collaboratively with Git version control, but you need to handle the problem of assigning independent memory directories to different collaborators to avoid knowledge base interference. Going further, you could introduce vectorized retrieval to replace the simple “read the last three days of files” logic, enabling knowledge base lookup at larger scale.

    Ultimately, the essence of this memory system is using structured external storage to compensate for the language model’s weakness in long-term dependency. It transforms the AI assistant from a stateless function into a collaborative partner with a genuine “growth” cycle.