Index
memory
¶
Native persistent long-term memory for OpenJarvis.
This package provides the automatic memory service that extracts durable facts
from conversations in the background and persists them across sessions. It is
started and stopped as part of the jarvis serve / jarvis chat lifecycle
and configured via the [memory] section of config.toml.
Classes¶
FactExtractor
¶
FactExtractor(engine: Any, model: str, *, temperature: float = 0.0, max_tokens: int = 512, max_facts_per_turn: int = 10, max_fact_chars: int = 200, system_prompt: Optional[str] = None)
Extract memory-worthy facts from a conversation turn via an engine.
Source code in src/openjarvis/memory/extractor.py
Functions¶
extract
¶
Return durable facts from the exchange. Never raises.
Source code in src/openjarvis/memory/extractor.py
MemoryService
¶
MemoryService(store: FactStore, extractor: FactExtractor, *, event_bus: EventBus | None = None, scanner: Any = None, max_queue: int = 256)
Background long-term-memory extraction and persistence service.
Source code in src/openjarvis/memory/service.py
Functions¶
start
¶
Start the background worker thread (idempotent).
Source code in src/openjarvis/memory/service.py
stop
¶
Signal the worker to drain and stop, then join it (idempotent).
Source code in src/openjarvis/memory/service.py
submit
¶
Queue an exchange for extraction. Non-blocking; never raises.
Returns True if the job was enqueued, False if the service is not running or the queue is full (in which case the exchange is dropped rather than blocking the caller — extraction is best-effort).
Source code in src/openjarvis/memory/service.py
Fact
dataclass
¶
A single durable memory entry.
FactStore
¶
Bases: ABC
Abstract persistent store for extracted memory facts.
Functions¶
add
abstractmethod
¶
set_trust
¶
Set the provenance tier of the index-th fact (0-based) as returned
by :meth:list. Returns True if a fact was updated.
add_many
¶
Store several facts, returning the count of newly stored ones.
add_with_trust
¶
Store a provenance-aware fact without breaking legacy backends.
Third-party stores implementing the original add(text, source)
contract inherit this adapter. Recallable facts are stored normally;
quarantined or unknown tiers are dropped because a backend that cannot
persist provenance cannot safely retain them for model-facing recall.
Provenance-aware stores should override this method.
Source code in src/openjarvis/memory/store.py
add_many_with_trust
¶
Store several provenance-aware facts.
Source code in src/openjarvis/memory/store.py
promote_reviewed
¶
Promote the reviewed fact at index when it still matches.
The default preserves compatibility with third-party implementations; stores with concurrent writers should override this with an atomic identity check.
Source code in src/openjarvis/memory/store.py
clear
abstractmethod
¶
LocalFactStore
¶
Bases: FactStore
Append-only JSONL fact store on the local filesystem.
Facts are kept human-readable (one JSON object per line) so they can be
inspected or edited by hand. Writes are atomic (temp file + rename) and
guarded by a lock, so concurrent add calls from the extraction worker
and list/clear from the CLI never corrupt the file.
Source code in src/openjarvis/memory/store.py
Attributes¶
Functions¶
promote_reviewed
¶
Atomically promote exactly the fact a user reviewed.
Source code in src/openjarvis/memory/store.py
Functions¶
build_memory_service
¶
build_memory_service(config: Any, engine: Any, default_model: str = '', *, event_bus: EventBus | None = None) -> Optional[MemoryService]
Build a :class:MemoryService from config, or None if disabled.
Reads the [memory] section (config.memory / config.tools.storage)
for enabled, backend, extraction_model, max_facts and
facts_path. Returns None when memory is disabled or no engine /
extraction model is available, so callers can simply do::
svc = build_memory_service(config, engine, model)
if svc is not None:
svc.start()
Source code in src/openjarvis/memory/service.py
publish_completed_exchange
¶
publish_completed_exchange(bus: EventBus | None, user_text: str, assistant_text: str = '', *, source: str = '') -> bool
Publish a completed chat exchange for lifecycle subscribers.
Source code in src/openjarvis/memory/service.py
create_fact_store
¶
create_fact_store(backend: str = 'local', *, path: str | Path | None = None, max_facts: int = 1000) -> FactStore
Construct a fact store for the configured backend.
Only the "local" (on-disk JSONL) backend is supported today; the
registry-backed constructor exists so additional backends can be added
without changing the service or CLI wiring.
Source code in src/openjarvis/memory/store.py
load_configured_facts
¶
load_configured_facts(config: Any) -> List[Fact]
Load automatic-memory facts from config when the service is enabled.
Context injection is also used by short-lived commands such as
jarvis ask, where no :class:MemoryService instance exists. This
helper gives those callers the same configured fact-store view without
coupling them to the service lifecycle.