Skip to main content

Memory class

Constructor

MemoryConfig | None
A MemoryConfig Pydantic model. If None, uses MemoryConfig() defaults.
str
default:"default-agent"
Unique agent identifier. Memory is namespaced by agent_id.
str | None
default:"None"
Session ID. If None, generates a new UUID. Used to track session-level memory.
Embedder | None
default:"None"
Custom embedder (for advanced use — usually auto-configured).
VectorBackend | None
default:"None"
Custom vector backend (for advanced use — usually auto-configured).
StorageBackend | None
default:"None"
Custom storage backend (for advanced use — usually auto-configured).

remember()

Write to all three memory layers in one call.
str
required
Memory content (1–8000 characters).
float
default:"0.5"
Importance score (0.0–1.0). Higher = more likely to be recalled.
str | None
Optional source identifier (e.g., “user_input”, “tool_output”).
EpisodeEvent
default:"EpisodeEvent.AGENT_RESPONSE"
Event type for episodic record.
str | None
Tool name if this memory came from a tool call.
dict[str, Any] | None
Custom metadata dictionary.
dict

recall()

Search across all three layers and return ranked results.
str
required
Search query (1–500 characters).
int
default:"10"
Maximum results to return (1–100).
list[MemoryLayer] | None
Filter to specific layers. Defaults to all three.
RecallResult
Results object with:
  • results: list of RankedMemory ranked by composite score
  • total_found: total matches before ranking
  • cache_hit: whether result came from semantic cache
  • latency_ms: query time in milliseconds

context_for()

Build a token-budgeted context string for prompt injection.
str
required
Search query.
int | None
Maximum tokens (default from config: 2048). Memories are included until budget is reached.
list[MemoryLayer] | None
Filter to specific layers.
ContextResult
  • content: Formatted string ready for injection
  • token_count: Actual tokens used
  • token_budget: Budget provided
  • memories_used: Number of results included
  • cache_hit: Whether result came from cache

flush()

End current session and flush working memory to episodic.
list[Episode]
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.
str
required
Agent that stored this fact.
str
required
Subject (1–500 characters).
FactRelation
required
Relationship type.
str
required
Object (1–2000 characters).
float
default:"0.8"
Confidence score (0.0–1.0).
float
default:"0.5"
Importance score (0.0–1.0).
str | None
Optional user identifier for multi-user agents.
dict[str, Any]
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 support PLYRA_* environment variables.
str
default:"all-MiniLM-L6-v2"
Embedding model name (from sentence-transformers).
int
default:"384"
Embedding dimensionality.
str
default:"~/.plyra/memory.db"
SQLite database path. Expands ~ to home directory.
str
default:"~/.plyra/memory.index"
ChromaDB vectors path.
int
default:"2048"
Default token budget for context_for().
float
default:"0.5"
Weight for similarity in composite score (0.0–1.0).
float
default:"0.3"
Weight for recency in composite score (0.0–1.0).
float
default:"0.2"
Weight for importance in composite score (0.0–1.0).
bool
default:"true"
Enable semantic cache for recall results.
float
default:"0.92"
Similarity threshold for cache hits (0.0–1.0).
int
default:"1000"
Maximum cached queries.
bool
default:"true"
Enable episodic summarization.
bool
default:"true"
Enable automatic fact promotion from episodic to semantic.
str | None
Groq API key for LLM-based fact extraction (preferred).
str | None
Anthropic API key for LLM-based fact extraction.
str | None
OpenAI API key for LLM-based fact extraction.

MemoryLayer enum

Values: WORKING, EPISODIC, SEMANTIC

Environment variables

All configuration can be set via PLYRA_* env vars: