Agent Memory Systems: From Context to Persistent Storage › Worked Example: A Coding Assistant with Memory

Michael BrenndoerferFebruary 5, 20263 min read
Language AI HandbookAll chapters
Part 48 of 67Tool Use and Agents
Chapter 368Agent Memory Systems: From Context to Persistent Storage › Worked Example: A Coding Assistant with Memory
Reading section 6 of 12 · Worked Example: A Coding Assistant with Memory · 3 minSection 6 of 12 · 3 min

Book contents

Section 6 of 12 · 3 min read

Agent Memory Systems: From Context to Persistent Storage › Worked Example: A Coding Assistant with MemoryOne section · Sections in this chapter6 / 12 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Consider a coding agent helping you refactor a large codebase over several sessions spanning multiple days. Each session builds on the previous one, requiring advanced memory management to maintain continuity and avoid repeating earlier mistakes.

Session 1 starts fresh. The agent analyzes the authentication module, noting the use of JWT tokens with a custom refresh strategy. It stores this in episodic memory with high importance due to security implications. The agent also extracts semantic knowledge as triples: (authentication, uses, JWT) and (JWT, has_property, custom_refresh). This structured extraction allows precise retrieval later when questions arise about authentication specifically, even if the query uses different terminology like "login system" or "session management."

Session 2, three days later: you ask, "How should we handle the API rate limiting?" The agent retrieves memories about the authentication system, recognizing that rate limiting rules often interact with authentication tiers. By recalling the JWT refresh patterns from the previous session, it suggests rate limits that respect the authentication state transitions, avoiding scenarios where aggressive rate limiting interferes with legitimate token refreshes. Without this memory, the agent might suggest naive rate limiting that breaks the authentication flow whenever a client needs to refresh an expired token. The multi-factor scoring here works in favor of the correct retrieval: the authentication memories have high importance scores (security-necessary decisions), and they score well on similarity despite not containing the words "rate limiting," because the embedding model captures the conceptual connection between authentication and API access control.

Session 3: the context window fills with current file contents. The agent summarizes the previous refactoring steps, maintaining only the high-level plan in working memory while storing detailed function signatures in the vector database. This compression ensures that the agent can still see the overall architecture (decoupling the user service from the payment service) without the token overhead of every specific function change. When you ask for details about a specific function modified earlier, the agent retrieves the full signature from the vector store on demand. This gives high fidelity where it matters without burning tokens on information not currently needed.

Session 4: an error occurs during testing. The agent retrieves similar past errors from episodic memory, finds a previous fix involving asynchronous token refresh, and applies the same pattern, avoiding a bug it previously encountered. This shows procedural learning: the agent stores the fact that an error occurred, learns the pattern of the solution, and applies it to a new but structurally related context.

This continuity shows how memory turns isolated tool calls into coherent, learning assistance. Without memory, each session would begin with the agent re-exploring the codebase, re-learning the architecture, and potentially repeating previous mistakes. With memory, the agent accumulates expertise specific to this codebase and this developer's preferences, becoming more effective over time. The improvement is not from retraining the underlying model but from intelligently managing the information available at inference time.