Free · WaitlistJoin the waitlist for the free 2-day Vibecoding & AI Agents Intensive (autonomous Hermes + DeepSeek agent · led by Jemal Hamidun, Head of AI at Alpina Digital & MIPT)Join the waitlist →
ReleaseCode / SDK · ActionableHabr AI→ original

A 40-Line Catalog Instead of Dozens of Instructions: How the SagaAI Agent Memory Works

An agent without memory is like Dory the fish: every time, it has to work out again who it is and what it was doing. Stuff every rule into the system prompt, and the agent drowns in text. The author of the open-source SagaAI platform kept only the core in the system prompt and replaced dozens of instructions with a catalog of roughly 40 lines: a name, a short description, and an identifier. The agent requests the full text of an instruction itself when a task matches its description. As a result, the context stays compact, and the rule set can grow indefinitely.

AI-processed from Habr AI; edited by Hamidun News
A 40-Line Catalog Instead of Dozens of Instructions: How the SagaAI Agent Memory Works
Source: Habr AI. Collage: Hamidun News.
Listen to article
Article Fact Sheet & Key Figures
ParameterDetails
Primary sourceHabr AI ↗
Editor-in-Chief
Working memorya map, a registry, a journal, and task cards in the agent's folder
Limitsup to 12 files, 16 columns, and 200 lines of mandatory reading
Key metric #3A subagent is not allowed to write to the registries and journals of the agent that launched it

An agent that forgets the user's settings and the details of a task is like Dory from Finding Nemo: it keeps swimming but doesn't remember where or why. Developers know this problem well. You keep adding new rules to the system prompt, and after a hundred edits it becomes a wall of text that the model gets lost in just as much as a human would.

The author of the open-source multi-agent platform SagaAI (the code is on GitHub) described how he solved this for his agents: instead of one huge prompt, he has a 40-line catalog from which the agent pulls what it needs on its own. This is not a review of other solutions like Claude Code or Codex, but a personal engineering path, and it contains techniques you can take into your own project.

A prompt as a shelf of book spines

The author splits agent memory into long-term ("who I am and how I should work") and short-term. The core principle of the long-term part: the prompt holds only what is needed all the time. At first he stuffed everything in: rules for different file types, instructions for subject areas, tool quirks. After a hundred edits the text became unreadable for both humans and the model.

Now the system prompt keeps the core: who the agent is, what stages its work goes through, when it must stop and ask, and when it should act on its own. Everything else is moved into separate entities:

  • Instructions are text rules. Only a table of contents gets automatically placed into the prompt: a name, a short description, and an identifier. The author has dozens of instructions, and in the context they hang as a catalog of roughly 40 lines. The agent doesn't need to remember how to work with a remote server if today it is making a presentation. When a task matches a description, the agent requests the full text itself.
  • Skills are folders with scripts, templates, and sample data for a whole class of tasks: "build a presentation," "create a RAG database," "create an infographic." The prompt contains only the name, the description, and the path to the folder.
  • Knowledge bases are documentation and methodologies that run to hundreds of megabytes. They can't fit into the prompt, so search over an index (RAG) is connected instead. The base can be created by the developer agent itself if it has the appropriate skill.

Working memory: map, registry, journal

The author spent the longest getting to working memory. The agent has its own folder in the platform's shared storage, where it keeps records: what has been done, which decisions were made and why, which constraints came to light in practice. Inside are a memory map (what is where and the order in which to read it), a registry of projects and tasks, a decision journal, and cards for units of work.

The writing rules are strict. Registry rows are never deleted: the status is updated, and a correction is recorded as a separate dated entry with a reason. A month later the agent sees the discrepancy and checks the date rather than guessing which version is the "real" one. The journal is append-only; when it grows, the old part is moved to an archive file so that reading always costs the same. A task gets a card with a passport and its own journal only when it accumulates three or more artifacts; otherwise memory turns into a graveyard of empty directories.

An important detail: the composition of memory is now declared in a short separate list, and the platform assembles the agent's instructions from it automatically. Previously the description lived in the prompt text and drifted from what was actually on disk. Each file has a reading mode: mandatory (at the start of work, within a line limit), on demand, or search-only. The limits are: no more than twelve files, sixteen columns, two hundred lines of mandatory reading, and four hundred lines of on-demand reading. The logic is simple: declaring memory also takes up memory, so the declaration itself has to be small.

Tools and the boundary for subagents

The author didn't rely on the agent's good faith for writing. When an agent opens a file on its own and looks for a place to insert a line, three problems arise: half the file is lost in a failed write, a journal gets re-read in full just to add one line, and a line doesn't match the table header. So there are five tools: show what is in memory; read a file within the budget (he refuses to let the agent read the whole search journal); append an entry with column validation; find matches in the journal with a couple of lines of context around them; and move the old part to the archive.

A separate boundary concerns multi-agent chains. A child agent has no memory levels of its own and no right to write to the registries and journals of the agent that launched it. Previously this was only a request in the task text, and a subagent diligently appending "what was done" could corrupt someone else's memory. Now such a write is rejected mechanically, and the result is returned to the launching agent.

What to take away

The scheme is elaborate, and the author admits as much. The material contains no quality measurements: it is an account of engineering practice, not a benchmark. But the principles transfer easily. Keep a catalog in the prompt, not full texts. Declare the memory structure explicitly and assemble instructions from it automatically. Don't give subagents write access to other agents' journals. Limit the size of everything the agent reads at startup, including the description of the memory itself.

Story

Key Questions Answered

What are the key details on A prompt as a shelf of book spines?

The author splits agent memory into long-term ("who I am and how I should work") and short-term. The core principle of the long-term part: the prompt holds only what is needed all the time. At first he stuffed everything in: rules for different file types, instructions for subject areas, tool quirks. After a hundred edits the text became unreadable for both humans and the model.

What are the key details on Working memory: map, registry, journal?

The author spent the longest getting to working memory. The agent has its own folder in the platform's shared storage, where it keeps records: what has been done, which decisions were made and why, which constraints came to light in practice. Inside are a memory map (what is where and the order in which to read it), a registry of projects and tasks, a decision journal, and cards for units of work. The writing rules are strict.

What are the key details on Tools and the boundary for subagents?

The author didn't rely on the agent's good faith for writing. When an agent opens a file on its own and looks for a place to insert a line, three problems arise: half the file is lost in a failed write, a journal gets re-read in full just to add one line, and a line doesn't match the table header.

ZK
Zhemal Khamidun — CPO at Alpina Digital, product manager of AlpinaGPT. Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Unified AI Workspace · Nomad

Test Frontier LLMs & Autonomous Agents in One Workspace

Run Claude Opus 5.5, GPT-6, Gemini 3.1, and DeepSeek side-by-side in Nomad AI (nomadnet.ai) — unified model routing, deep research, and multimodal workflows under one subscription.

Try Nomad AI →Launch Nomad Agent
What do you think?
Loading comments…