Introduction¶
Many Agents treat “memory” as equivalent to the context within the current session: once the conversation ends, user preferences, entity relationships, and historical facts are all lost. The next round can only start from scratch with follow-up questions, or rely on manual repetition. Solutions such as vector RAG, knowledge graphs, and temporal knowledge graphs are increasingly common, but the selection often becomes “just deploy Mem0 / Zep / Cognee first,” rather than first aligning the retrieval form and persistence layer.
The following introduces the memory-systems Agent Skill. It comes from the Agent Skills for Context Engineering collection, using a structured guide to cover cross-session semantic memory, entity tracking, graph/vector retrieval, and memory consolidation, and explains the boundaries with skills such as filesystem-context and context-compression in the same collection, to avoid mistaking file drafts, session compression, and token optimization for “long-term memory” design.
What Is This¶
memory-systems is a Memory System Design specification (SKILL.md) for production Agents, not an executable framework itself. It is maintained by the Agent Skills for Context Engineering Contributors; the official path is:
https://github.com/muratcankoylan/Agent-Skills-for-Context-Engineering/tree/main/skills/memory-systems
The positioning in the Skill metadata is: to handle persistent semantic memory in Agent systems—cross-session knowledge retention, entity tracking, temporal validity, graph or vector retrieval, memory consolidation, and memory benchmark selection. File-based scratchpads should be handled by filesystem-context, human-readable handoff summaries by context-compression, and token strategies within a single trajectory by context-optimization.
Core Features¶
When to Activate¶
Load this Skill in an Agent under the following conditions:
- Need to persist knowledge across sessions
- Need to choose among frameworks such as Mem0, Zep/Graphiti, Letta, LangMem, Cognee
- Need to maintain entity identity consistency across multiple dialogue turns
- Need to reason over accumulated knowledge or design scalable production memory architecture
- Need to evaluate memory systems using benchmarks such as LoCoMo, LongMemEval, DMR
- Need automatic entity/relation extraction and self-improving dynamic memory (e.g., Cognee)
Do not use this Skill for: file drafts and tool output offloading (filesystem-context), session compression and human-readable handoffs (context-compression), masking, prefix caching, and retrieval scope (context-optimization), RDF-based BDI mental states (bdi-mental-states).
Core Concept: A Spectrum from Context to Persistence Layer¶
Memory is a spectrum from a volatile context window to persistent storage. The default choice is the shallowest layer that can satisfy retrieval needs; the documentation notes that for some memory workloads, tool complexity is less important than reliable retrieval (claim-memory-locomo-filesystem-baseline). Only when retrieval quality degrades, or when multi-hop reasoning, relationship traversal, or “time travel” queries are needed, should graph structures or temporal validity be added.
Production Framework Comparison¶
Narrow down candidates by the dominant retrieval mode, then validate expectations with benchmark data (no single benchmark can settle it):
| Framework | Architecture | Best For | Trade-off |
|---|---|---|---|
| Mem0 | Vector store + graph memory, pluggable backends | Multi-tenant systems, broad integrations | Less specialized for multi-agent |
| Zep/Graphiti | Temporal knowledge graph, bi-temporal model | Enterprise requiring relationship modeling + temporal reasoning | Advanced features cloud-locked |
| Letta | Self-editing memory with tiered storage (in-context/core/archival) | Full agent introspection, stateful services | Complexity for simple use cases |
| Cognee | Multi-layer semantic graph via customizable ECL pipeline | Evolving agent memory; multi-hop reasoning | Heavier ingest-time processing |
| LangMem | Memory tools for LangGraph workflows | Teams already on LangGraph | Tightly coupled to LangGraph |
| File-system | Plain files with naming conventions | Simple agents, prototyping | No semantic search, no relationships |
Selection key points (excerpted from the official documentation): when bi-temporality is needed (event time and write time), lean toward Zep/Graphiti; when quick deployment and managed infrastructure are needed, lean toward Mem0; when deep agent introspection and tiered storage are needed, lean toward Letta; when customizable ECL pipelines and dense multi-layer semantic graphs are needed, lean toward Cognee.
Memory Layers¶
Choose the shallowest layer that satisfies persistence needs, then deepen as required:
| Layer | Persistence | Implementation | When to Use |
|---|---|---|---|
| Working | Context window only | Scratchpad in system prompt | Always present; pay attention to attention-friendly placement |
| Short-term | Session-scoped | File-system, in-memory cache | Intermediate tool results, session state |
| Long-term | Cross-session | Key-value store → graph DB | User preferences, domain knowledge, entity registry |
| Entity | Cross-session | Entity registry + properties | Same entity identity across sessions |
| Temporal KG | Cross-session + history | Graph with validity intervals | Facts that change over time, point-in-time queries, avoiding context conflicts |
Retrieval Strategies¶
Match strategies to query forms; adopt hybrid retrieval when accuracy is prioritized and the budget allows:
| Strategy | Use When | Limitation |
|---|---|---|
| Semantic (embedding similarity) | Direct fact queries | Multi-hop reasoning tends to degrade |
| Entity-based (graph traversal) | “Everything about X” | Requires graph structure |
| Temporal (validity filter) | Facts change over time | Requires validity metadata |
| Hybrid | Overall accuracy | Heaviest infrastructure |
Memory Consolidation and Practical Path¶
Perform consolidation periodically to avoid retrieval degradation caused by unbounded memory growth; the principle is Invalidate but do not discard—mark invalidated entries, but retain history for temporal reconstruction. It can be triggered by memory count thresholds, retrieval quality degradation, or scheduled tasks.
Architecture upgrade path (official Practical Guidance):
- Prototype: File system + timestamped structured JSON, validate behavior before deploying infrastructure.
- Scale: When semantic retrieval and multi-tenant isolation are needed, migrate to Mem0 or a vector store with metadata.
- Complex reasoning: When relationship traversal, temporal validity, or cross-session synthesis is needed, introduce Zep/Graphiti or Cognee.
- Full self-control: When memory operations need to be first-class Agent actions, consider Letta or Cognee.
When integrating with context: use just-in-time loading, do not pre-load all memory; place retrieval results in attention-friendly positions such as the beginning or end of the context. On retrieval failure, degrade in sequence: loosen filters → check valid_until → on conflict, prefer the newer valid_from → if write fails, queue for retry without blocking the reply.
Installation and Activation¶
This Skill is a general SKILL.md textual instruction; there is no separate installation script in the repository. Common loading methods (consistent with the community index awesome-agent-skills, choose one based on the Agent used):
Claude Code—add the Skill directory or collection repository to the skill list:
/skills add https://github.com/muratcankoylan/Agent-Skills-for-Context-Engineering
If the platform supports sub-paths, you can point to the skills/memory-systems directory; refer to the Claude Code documentation for specifics.
Vercel skills CLI—search, install, and manage:
npx skills find memory-systems
npx skills add muratcankoylan/Agent-Skills-for-Context-Engineering
npx skills list
Claude.ai / Other clients: You can paste the raw SKILL.md address into a new conversation, or have the Agent read that URL when needed (community documentation says “just describe the task to trigger it,” with no additional configuration items).
Cursor: After placing the Skill content into the project or user-level Skills configuration, when building cross-session memory, selecting frameworks, or designing consolidation strategies, explicitly request adherence to the memory-systems guide in the conversation.
No code changes are required after activation; the Agent should load the full text when scenarios matching “When to Activate” occur, and can refer to references/implementation.md in the same directory (vector stores, property graphs, temporal queries, and consolidation logic) for implementation details when needed.
Typical Usage¶
The official SKILL.md provides three categories of examples with reference implementations (the following is the original structure; the corresponding SDK and environment must be prepared).
Example 1: Mem0 write and preference retrieval
from mem0 import Memory
m = Memory()
m.add("User prefers dark mode and Python 3.12", user_id="alice")
m.add("User switched to light mode", user_id="alice")
# Retrieves current preference (light mode), not outdated one
results = m.search("What theme does the user prefer?", user_id="alice")
Example 2: Point-in-time query with validity period
# Track entity with validity periods
graph.create_temporal_relationship(
source_id=user_node,
rel_type="LIVES_AT",
target_id=address_node,
valid_from=datetime(2024, 1, 15),
valid_until=datetime(2024, 9, 1), # moved out
)
# Query: Where did user live on March 1, 2024?
results = graph.query_at_time(
{"type": "LIVES_AT", "source_label": "User"},
query_time=datetime(2024, 3, 1)
)
Example 3: Cognee ingestion and graph retrieval
import cognee
from cognee.modules.search.types import SearchType
await cognee.add("./docs/")
await cognee.add("any data")
await cognee.cognify()
await cognee.memify()
results = await cognee.search(
query_text="Any query for your memory",
query_type=SearchType.GRAPH_COMPLETION,
)
When designing conversations, you can first have the Agent self-check using the Guidelines checklist in the Skill: start with a file system, record temporal validity for mutable facts, use hybrid retrieval, perform regular consolidation, have fallbacks for retrieval failures, pay attention to privacy and retention policies, use LoCoMo or LongMemEval for before/after comparison, monitor volume and latency.
Applicable Scenarios and Cautions¶
Who it is for
- Backend and platform engineers designing or refactoring the Agent persistence layer
- Teams needing to make technical selections among Mem0 / Graphiti / Cognee, etc.
- Product scenarios that need to solve cross-session entity consistency, facts changing over time, and multi-hop reasoning retrieval
Limitations and common pitfalls (excerpted from the official Gotchas)
- Stuffing all memory into the prompt: costly and harmful to attention; should use JIT retrieval and filtering.
- Ignoring temporal validity: expired facts pollute the context.
- Over-engineering too early: simple file memory may still perform well on some benchmarks; should deepen structures only after actual testing failures.
- No consolidation strategy: unbounded memory growth will drag down retrieval.
- Using different embedding models for reads and writes: vector space incompatibility, need to fix the model or fully re-embed on changes.
- Graph schema too rigid: fragile when the domain evolves; favor generic relationship types and flexible properties.
- Memory that is related but contextually wrong (e.g., Python language vs. python snake): should carry session/domain metadata in entries and filter during retrieval.
Integration with skills in the same collection: filesystem-context manages drafts and logs; context-compression manages summary handoffs; context-optimization manages loading and budget within a single trajectory; multi-agent-patterns manages shared memory across multiple Agents; evaluation manages memory quality and benchmark selection.
Conclusion¶
Cross-session memory is often one of the watersheds between Agent products and “single-use chatbots.” memory-systems does not provide code to replace frameworks, but writes the layers, retrieval forms, framework comparisons, consolidation, and evaluation constraints into a reusable design checklist, and clearly defines the division of labor with other Context Engineering Skills. For implementation, it is recommended to start with the shallowest layer to validate retrieval quality, then deepen according to the official escalation path; benchmark numbers are only dated evidence, and product claims need to be re-verified before publication.
Official Skill directory:
https://github.com/muratcankoylan/Agent-Skills-for-Context-Engineering/tree/main/skills/memory-systems
Full instruction original (raw):
https://raw.githubusercontent.com/muratcankoylan/Agent-Skills-for-Context-Engineering/main/skills/memory-systems/SKILL.md