AI Agent with Persistent Memory
The Problem
AI agents lose all context when a conversation ends. Every new session starts from scratch — the user has to re-explain their preferences, past decisions, and ongoing projects. For agents that users interact with daily, this is a major friction point.
The Solution
Store important context in Memsolus at the end of every conversation. At the start of the next one, retrieve the compiled knowledge profile for that user. Your agent gets full context without relying on a growing context window.
How It Works
Implementation
Install the SDK
Initialize the client
Load context at conversation start
Before sending the first message to the LLM, retrieve the user's knowledge profile:
The merged: true flag returns a single compiled document that combines all knowledge entries for that user — no need to stitch multiple results together.
Search for relevant memories
For every user message, search for memories specifically relevant to it:
Build the system prompt
Combine the knowledge profile and relevant memories into a system prompt:
Store new facts after the conversation
At the end of each turn, store facts that should be remembered:
Put it all together
Here is a complete agent turn: