Skip to content

L2 - Memory

The Memory layer (L2) manages agent state, context, and persistence across different time scales and scopes.


The Memory layer provides structured storage and retrieval mechanisms for agent context, enabling agents to maintain state across interactions and make informed decisions based on past experiences.


Working Memory

Scope: Current request
Persistence: None
Temporary context for ongoing tasks

Short-term Memory

Scope: Session
Persistence: Session duration
Conversation and interaction history

Long-term Memory

Scope: Agent lifetime
Persistence: Persistent
Learned patterns and preferences

Episodic Memory

Scope: Specific events
Persistence: Selective
Important experiences and outcomes


RequirementDescription
Working MemoryImplement in-memory context for current operations
TTL ExpirationSupport time-based automatic cleanup
Vector SearchEnable semantic similarity search for retrieval
Atomic OperationsProvide read-modify-write guarantees
RequirementDescription
No Plaintext SecretsNever store credentials without encryption
Audit LoggingLog all write operations for compliance
Size LimitsImplement eviction policies for memory bounds
Concurrent AccessHandle multi-threaded access safely

{
"id": "memory-uuid",
"type": "short_term|long_term|episodic",
"created_at": "ISO8601",
"expires_at": "ISO8601",
"content": {
"text": "User prefers concise responses",
"embedding": [0.1, 0.2, ...]
},
"metadata": {
"source": "conversation",
"confidence": 0.95,
"tags": ["preference", "style"]
},
"access_count": 42,
"last_accessed": "ISO8601"
}

{
"eviction_policy": {
"type": "lru",
"max_size_mb": 100,
"max_entries": 1000
}
}
{
"eviction_policy": {
"type": "ttl",
"default_ttl_seconds": 3600,
"max_ttl_seconds": 86400
}
}

{
"query": {
"text": "What are the user's preferences?",
"embedding": [0.1, 0.2, ...],
"top_k": 5,
"similarity_threshold": 0.8,
"filters": {
"type": "long_term",
"tags": ["preference"]
}
}
}
{
"results": [
{
"memory_id": "uuid",
"similarity": 0.95,
"content": {...}
}
],
"total_results": 5
}

{
"partitions": {
"user_context": {
"max_size_mb": 50,
"ttl_seconds": 86400
},
"system_context": {
"max_size_mb": 20,
"ttl_seconds": 3600
},
"temporary": {
"max_size_mb": 10,
"ttl_seconds": 300
}
}
}

  1. Use Appropriate Memory Types: Match memory type to data lifespan
  2. Implement Vector Search: Enable semantic retrieval for better context
  3. Set Realistic TTLs: Balance memory usage with context needs
  4. Monitor Memory Usage: Track growth and eviction rates
  5. Secure Sensitive Data: Encrypt PII and use proper access controls
  6. Implement Snapshots: Enable debugging and rollback capabilities


© 2026 IbIFACE — CC BY 4.0