How agents use memory
During a conversation, agents can call two built-in tools automatically:save_memory(content)— stores a new fact extracted from the conversation.search_memory(query)— performs a semantic vector search over stored facts to retrieve relevant context.
save_memory. When it needs context from past interactions, it calls search_memory. Both happen transparently as part of the agent’s reasoning loop.
Long-term memory is distinct from session history. Session history records the raw message transcript for a single conversation. Memory stores distilled facts that travel with the user indefinitely.
Adding a memory
You can add facts programmatically usingPOST /api/memories. This is useful for seeding initial context—for example, onboarding information from your CRM—before a user’s first conversation.
The fact to store. Write facts as plain prose sentences. The content is embedded as a vector, so descriptive natural-language phrasing improves retrieval accuracy.
Searching memories
GET /api/memories performs a semantic vector search and returns the facts most relevant to your query. This is the same mechanism agents use internally when calling search_memory.
Deleting memories
To remove specific memories, send aDELETE /api/memories request with a JSON array of memory IDs in the body.
204 No Content on success.
Optimizing memory
Over time, a user’s memory store can accumulate redundant or outdated facts.POST /api/memories/optimize triggers an LLM-based consolidation pass that deduplicates overlapping facts, resolves contradictions, and improves overall memory quality.
Memory statistics
GET /api/memories/stats returns usage statistics for a given user’s memory store. Use this to monitor memory growth and decide when to run optimization.
Memory topics
GET /api/memories/topics returns high-level topic clusters derived from a user’s stored facts. Use this to build summary views in your UI or to understand what the agent knows about a user at a glance.
Memory vs. session history
| Long-term memory | Session history | |
|---|---|---|
| Scope | All sessions, all time | A single conversation |
| Storage | Vector database | Relational database |
| Retrieval | Semantic similarity search | Chronological message replay |
| Managed by | save_memory / search_memory tools | Automatic per-session context |
| Deleted with | DELETE /api/memories | DELETE /api/sessions/{sessionId} |