Memory class
Constructor
A
MemoryConfig Pydantic model. If None, uses MemoryConfig() defaults.Unique agent identifier. Memory is namespaced by agent_id.
Session ID. If
None, generates a new UUID. Used to track session-level memory.Custom embedder (for advanced use — usually auto-configured).
Custom vector backend (for advanced use — usually auto-configured).
Custom storage backend (for advanced use — usually auto-configured).
remember()
Write to all three memory layers in one call.Memory content (1–8000 characters).
Importance score (0.0–1.0). Higher = more likely to be recalled.
Optional source identifier (e.g., “user_input”, “tool_output”).
Event type for episodic record.
Tool name if this memory came from a tool call.
Custom metadata dictionary.
recall()
Search across all three layers and return ranked results.Search query (1–500 characters).
Maximum results to return (1–100).
Filter to specific layers. Defaults to all three.
Results object with:
results: list ofRankedMemoryranked by composite scoretotal_found: total matches before rankingcache_hit: whether result came from semantic cachelatency_ms: query time in milliseconds
context_for()
Build a token-budgeted context string for prompt injection.Search query.
Maximum tokens (default from config: 2048). Memories are included until budget is reached.
Filter to specific layers.
content: Formatted string ready for injectiontoken_count: Actual tokens usedtoken_budget: Budget providedmemories_used: Number of results includedcache_hit: Whether result came from cache
flush()
End current session and flush working memory to episodic.Episodic records created from flushed working entries.
close()
Close database connections and cleanup.Layer access
All three layers are available as direct attributes:working
Direct access to working memory layer.episodic
Direct access to episodic memory layer.semantic
Direct access to semantic memory (knowledge graph).Fact
Semantic memory triple: subject–predicate–object.Agent that stored this fact.
Subject (1–500 characters).
Relationship type.
Object (1–2000 characters).
Confidence score (0.0–1.0).
Importance score (0.0–1.0).
Optional user identifier for multi-user agents.
Custom metadata.
FactRelation enum
See Memory layers for complete list and descriptions. Values:PREFERS, DISLIKES, IS, IS_A, HAS, HAS_PROPERTY, KNOWS, USES, WORKS_ON, LOCATED_IN, BELONGS_TO, RELATED_TO, REQUIRES, LEARNED_FROM, CUSTOM
MemoryConfig
Configuration class (Pydantic BaseSettings). All fields supportPLYRA_* environment variables.
Embedding model name (from sentence-transformers).
Embedding dimensionality.
SQLite database path. Expands
~ to home directory.ChromaDB vectors path.
Default token budget for
context_for().Weight for similarity in composite score (0.0–1.0).
Weight for recency in composite score (0.0–1.0).
Weight for importance in composite score (0.0–1.0).
Enable semantic cache for recall results.
Similarity threshold for cache hits (0.0–1.0).
Maximum cached queries.
Enable episodic summarization.
Enable automatic fact promotion from episodic to semantic.
Groq API key for LLM-based fact extraction (preferred).
Anthropic API key for LLM-based fact extraction.
OpenAI API key for LLM-based fact extraction.
MemoryLayer enum
Values:WORKING, EPISODIC, SEMANTIC
Environment variables
All configuration can be set viaPLYRA_* env vars:
| Variable | Type | Default |
|---|---|---|
PLYRA_EMBED_MODEL | str | all-MiniLM-L6-v2 |
PLYRA_EMBED_DIM | int | 384 |
PLYRA_STORE_URL | str | ~/.plyra/memory.db |
PLYRA_VECTORS_URL | str | ~/.plyra/memory.index |
PLYRA_DEFAULT_TOKEN_BUDGET | int | 2048 |
PLYRA_SIMILARITY_WEIGHT | float | 0.5 |
PLYRA_RECENCY_WEIGHT | float | 0.3 |
PLYRA_IMPORTANCE_WEIGHT | float | 0.2 |
PLYRA_CACHE_ENABLED | bool | true |
PLYRA_CACHE_SIMILARITY_THRESHOLD | float | 0.92 |
PLYRA_SUMMARIZE_ENABLED | bool | true |
PLYRA_GROQ_API_KEY | str | — |
PLYRA_ANTHROPIC_API_KEY | str | — |
PLYRA_OPENAI_API_KEY | str | — |
PLYRA_SERVER_URL | str | — |
PLYRA_API_KEY | str | — |