a3s-memory
Pluggable memory storage for A3S.
Provides the MemoryStore trait and two default implementations. Agents that need to persist and recall knowledge across sessions depend on this crate directly — nothing else required.
Design
The crate follows a minimal core + external extensions pattern:
Core (stable, non-replaceable):
MemoryStore— storage backend traitMemoryItem— the unit of memoryMemoryType— episodic / semantic / procedural / workingRelevanceConfig— scoring parameters
Extensions (replaceable via MemoryStore):
InMemoryStore— default, ephemeral (testing and non-persistent use)FileMemoryStore— persistent, atomic writes, in-memory index
Three-tier session memory (AgentMemory) and context injection (MemoryContextProvider) live in a3s-code, not here. This crate only owns the storage layer.
Usage
[]
= { = "0.1", = "../memory" }
Store and retrieve
use ;
use Arc;
let store = new;
let item = new
.with_importance
.with_tag
.with_type;
store.store.await?;
let results = store.search.await?;
Persistent storage
use ;
let store = new.await?;
// Directory layout:
// memory/
// index.json ← in-memory index, persisted atomically
// items/{id}.json ← one file per memory item
Custom backend
Implement MemoryStore to use any storage system (SQLite, vector DB, etc.):
use ;
Relevance scoring
score = importance × importance_weight + decay × recency_weight
decay = exp(−age_days / decay_days)
Default: importance_weight = 0.7, recency_weight = 0.3, decay_days = 30.
use ;
let config = RelevanceConfig ;
let score = item.relevance_score_at;
What this crate does NOT own
| Concern | Lives in |
|---|---|
| Three-tier session memory (working / short-term / long-term) | a3s-code |
MemoryConfig (max_short_term, max_working) |
a3s-code |
MemoryStats |
a3s-code |
| Context injection into agent prompts | a3s-code |
Tests
32 tests covering MemoryItem, RelevanceConfig, InMemoryStore, and FileMemoryStore (including persistence, index rebuild, and path traversal prevention).
License
MIT