Overview
This guide covers strategies for managing memory in production agents—deduplication tuning, retrieval optimization, and understanding the memory lifecycle.Memory Lifecycle
- Input — Raw content arrives
- Embedding — Vector generated for semantic search
- Deduplication — Checked against existing memories
- Store — Persisted with metadata
- Retrieve — Loaded during tick context building
- Consolidate — Periodically merged into core memories
Deduplication Tuning
The SDK uses type-specific thresholds. Lower thresholds allow more merging; higher thresholds preserve uniqueness.
Reference:
DEDUP_THRESHOLDS in src/memory/deduplication.ts
Custom Thresholds
Override defaults when checking duplication:Finding Similar Memories
UsefindSimilarMemories() to locate related content without strict deduplication:
findSimilarMemories() in src/memory/deduplication.ts
Salience and Confidence
Two automatic scoring functions help prioritize memories: Salience — How attention-grabbing is this content?- Boosted by: exclamation marks, caps, urgency words
- Lowered by: routine phrasing, generic content
- Boosted by: API sources, verified data
- Lowered by: user input, opinions
src/memory/deduplication.ts
Embedding Providers
The SDK supports multiple embedding providers:
Configuration is loaded from environment variables:
Reference:
embeddingConfigFromEnv() in src/llm/embeddings.ts
Retrieval Patterns
Filter by Type
Semantic Search
Get Statistics
MemoryStore interface in src/memory/store.ts
Memory Consolidation (Roadmap)
Consolidation groups related memories into summarized “core memories.” This reduces retrieval overhead while preserving knowledge. The process:- Cluster similar memories by embedding
- Extract common themes
- Generate summary content
- Link core memory to sources
Memory Linking (Roadmap)
The architecture supports 7 relationship types between memories:caused_by— Causal relationshiprelated_to— General associationcontradicts— Conflicting informationelaborates— Adds detailsupersedes— Replaces old infotemporal_before/temporal_after— Time ordering
Best Practices
- Tune thresholds for your domain using real data
- Monitor storage growth and implement pruning if needed
- Use metadata effectively—tags, sources, context
- Cache embeddings to reduce API costs
- Batch operations when storing many memories
Next Steps
Memory SDK
Complete memory store reference.
Testing
Test memory operations.