Giving AI Agents Long-Term Memory

Yesterday a clever build shipped that fixes AI “amnesia” in large codebases. We all hate watching an agent burn tokens just looking for files or asking for context it should already have. The original poster, u/K_Kolomeitsev, realized the problem wasn’t the model, but the lack of persistent memory in standard repositories.

The Twist

Instead of stuffing more into the context window or hoping for better recall, this innovator moved the project memory to the disk. They created a structural index called the Data Structure Protocol (DSP) that sits right in the repo. This allows the agent to query the structure before it ever touches the code.

The Workflow

The system models the repository as a graph of entities. Here is how the author structured the .dsp/ folder:

  • Description: A text file explaining where a module lives, what it does, and why it exists.
  • Imports: A list of what the module depends on.
  • Exports: A reverse index showing who uses the module and a short note explaining why.

Pro Tip

The creator emphasized that the “why” note on dependencies is the killer feature. A standard dependency graph tells you what imports what, but knowing why something is imported tells the agent exactly what is safe to change and what will break.

The Catch

This isn’t an instant fix for legacy code. The expert admitted that bootstrapping this on a big system takes time and effort. They suggest starting with the services you touch the most and expanding the map from there.

Check out the full discussion and the GitHub link in the original thread to see the skeleton code.

How I stopped an AI agent from getting lost in a 100+ microservice repo
by u/K_Kolomeitsev in PromptEngineering

Scroll to Top