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.| Type | Default | Adjustment Guidance |
|---|---|---|
| Episodic | 0.92 | Lower if events feel redundant |
| Semantic | 0.95 | Lower if facts don’t consolidate |
| Emotional | 0.88 | Raise if nuanced feelings are lost |
| Procedural | 0.97 | Keep high—patterns must be precise |
| Reflection | 0.90 | Raise if self-insights feel repetitive |
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:| Provider | Dimensions | Model |
|---|---|---|
| Gemini | 768 | text-embedding-004 |
| OpenAI | 1536 | text-embedding-3-small |
| Variable | Description |
|---|---|
GEMINI_API_KEY | Google AI API key |
OPENAI_API_KEY | OpenAI API key |
EMBEDDING_PROVIDER | ”gemini” or “openai” |
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