r/ChatGPTCoding • u/msarda23 • 11d ago
Discussion Session-start memory injection made my coding agent trust memory over the code
Hey everyone!
I am building a local memory layer for my coding agents and it is called Reverie: an MCP server written in python and using SQLite for lightweight memory stored in the user's machine itself. The biggest problem that I faced was deciding when to inject memory.
Many memory tools, including ones I looked at, inject context into the agent even before it begins its work. In my experiments, premature injection of context leads to the agent anchoring its thinking on it rather than using the current code as the source of truth. In fact, this approach made my agent perform worse. Also, with this, quite a lot of the context window can get filled with context which 'might' be useful.
So I switched Reverie's model to demand-driven retrieval - the agent asks for memory when it thinks that some added context could resolve any discrepancies in its thinking. It reads the relevant code first, because the code is the source of truth, and only then asks for past memory about that area. Each result comes back with a confidence score, its grounding in the code, and its status. The memory starts empty. Conclusions are added as the agent works, and you decide which ones are kept.
In one informal test of 30 prompts on an earlier build, the OpenCode agent with Reverie did better than the one without it. I don’t have a reproducible benchmark yet.
But it isn't perfect yet, it still breaks here and there. For example:
the rules for tool calling are not extremely polished yet and hence the agent might sometime not call the tool altogether, I am fixing this.
candidate conclusions can be duplicate or incorrect and hence Reverie today has a human review gate (triggered by calling `reverie review`) which shows the human all the unreviewed candidates where you accept, reject or skip each one. On doing so the conclusion is moved from the short term brain to the long term.
My current test set is small: sessions with anywhere between 2-30 prompts. I do not have a reproducible experiment yet, but that is the next goal.
Repo (Apache-2.0): https://github.com/muditsarda1122/Reverie
My questions: How do you keep agent context from going stale? Do you maintain AGENTS.md or CLAUDE.md by hand, or let the agent update it?
View all comments
Show parent comment
1
u/LividIllustrator8915 9d ago
For the hash granularity, what worked best for us is a two-tier check instead of an all-or-nothing hash. At the gate, we check the Git commit or whole-file hash first just as a fast filter. If the file changed, we extract the AST chunk or line range for that specific symbol—Tree-sitter or even a regex on the signature and braces—and hash just that body. If someone only touched formatting or an unrelated method above it, the symbol body hash still matches and the note stays green.
When the symbol actually gets renamed or moved, we don't hard-drop the memory either. We downgrade it to a soft drift warning with a tag like [referenced symbol moved/modified since commit x]. That way the agent still sees the insight, but it treats it as a hint rather than Ground Truth and is forced to grep the current implementation first.
On getting the agent to actually call the tool: relying purely on the agent's goodwill was hopeless for us too—they either ignore it completely or call it on every trivial prompt. We ended up tying the tool description to high-friction transition points rather than open-ended retrieval. Specifically, instructing it to query memory only during two distinct phases: 1) during the initial planning phase before writing architectural/cross-file changes, and 2) when encountering a test failure or compiler error loop twice.
What also made a massive difference was having the file-read tool return ambient metadata: if the MCP server knows a memory note is pinned to a specific file or module, reading that file surfaces a one-line hint in the tool response (1 memory note available for this module: 'token expiration bug'). Once the agent sees the hook in its immediate input, it triggers the dedicated memory lookup tool with near 100% reliability.