Hello! My name is Ildar, and I'm developing an AI assistant for programmers in the BayLang AI project. Today I want to tell you how I came to the memory architecture for AI agents.
When I started developing an AI agent, I first stored memory in files. It seemed logical: there is memory.md, there is user_data.md, everything is simple.
But that's not the case.
I came to the conclusion that a database is needed with a separation of memory types and a mechanism for protecting important data.
I realized that the memory of an AI agent should work like a human: there is something that is always "at hand" (contextual memory), and there is something that is stored "in the desk drawer" (notebook).
This is data that is loaded into the context with every request to the AI.
How it works:
- When a user sends a message, the system automatically loads the context memory.
- The AI sees this data "always" — it's like having a note with important reminders always in front of your eyes.
- The volume is limited — you can't load everything at once.
What to store:
- System settings (language, communication style).
- Agent behavior rules.
- Information about the user (name, preferences).
- Current session context.
But if you load ALL of the agent's knowledge into the context, the context will overflow (LLM has a token limit) and the AI will receive too much unnecessary information.
Therefore, another type of memory was invented — the notebook.
This is memory with semantic search. The AI does not see this data "always," but can find it by meaning.
How it works:
- Data is stored in a database with vector embeddings.
- When the AI receives a question, the system searches for relevant notes by meaning (not by keywords!).
- Found notes are added to the context for a specific request.
What to store:
- Project knowledge base.
- Interaction history.
- Notes, instructions, documentation.
- Goals, plans, tasks.
Example: The AI asks "Tell me about BayLang." The system searches the notebook and finds notes with the baylang tag, returns relevant data.
In the notebook, there are categories and tags for better data organization.
Categories define access level and data type:
| Category | Type | Description | Example |
|---|---|---|---|
public_data | Public | General data that can be shown to everyone | Project information, agent styles |
public_docs | Public | Documentation, instructions | Guides, API documentation |
public_goals | Public | Goals and plans | Development plan, roadmap |
public_wiki | Public | Knowledge base | Technical articles, FAQ |
user_data | Private | Personal information about the user | Preferences, communication history |
android_maintain | System | Agent's technical data | Error logs, debugging |
android_preferences | System | Agent settings | Styles, configuration |
Why:
- Security: private user data will not be available to other users or AI assistants.
- Performance: searching only in the desired category is faster.
- Organization: it is easier to find the necessary information.
Tags are labels for quick search and grouping of notes by topic.
Examples of tags:
- ai-agent — everything about AI agents.
- baylang — materials on the BayLang project.
- communication — communication, interfaces.
- important — important notes (do not delete!).
- task — tasks and todos.
- personal — personal notes.
Why:
- Quick search: "show all tasks" → filter by task tag.
- Grouping: all notes on BayLang → baylang tag.
- Prioritization: important notes → important tag.
When a user asks a question, a Discovery occurs — a query to memory.
File memory for AI is a dead end. A database is needed with a separation of contextual memory (always in context) and a notebook (semantic search). Categories and tags help organize knowledge, and Discovery collects everything into the initial context for the AI. This works.
Important conclusions:
If you are developing an AI agent — start with the memory architecture. This is the foundation on which everything else depends.
Next, I plan to develop the system and add more features.