Skip to main content

Memory that degrades gracefully — four-tier lifecycle memory for AI agents

Project description

memlife

Memory that degrades gracefully. Not another pile that grows forever.

What

memlife is a four-tier lifecycle memory system for AI agents:

  • Episodes — raw events (what happened)
  • Facts — durable truths (what I know)
  • Journal — reflected beliefs (what I believe)
  • Decay/Prune — confidence fades, stale entries retire, GC cleans up

Every memory has a lifecycle. Facts decay through confidence erosion. Journal entries retire when they fall below the floor. Superseded data is pruned after a retention period. Nothing accumulates forever.

Why

Every other memory system accumulates. Facts never expire. Confidence never decays. Stale conventions become unquestioned truths. Recall quality degrades over time.

memlife solves this. Memory should be like human memory — it fades, it gets revised, it gets pruned. Not a database that grows until it breaks.

Quickstart

pip install memlife
import asyncio
from memlife import MemoryStore, MemoryConfig, DummyEmbedder

async def main():
    store = MemoryStore(
        config=MemoryConfig(db_path="./mem.db"),
        embedder=DummyEmbedder(),  # zero external dependencies
    )

    # Store an episode (something happened)
    store.remember(task="User asked about deployment", outcome="success")

    # Store a fact (durable truth)
    await store.store_fact("User deploys via GitHub Actions", confidence=0.8)

    # Retrieve relevant memories (unified scoring across all layers)
    context = await store.retrieve("deployment")

    print(context)
    store.close()

asyncio.run(main())

No Ollama, no OpenAI, no API key. The DummyEmbedder uses hash-based vectors. The full lifecycle — store, retrieve, decay, GC — works without any LLM.

The Lifecycle

┌───────────┐     reflection      ┌───────────┐
│  EPISODE  │ ──────────────────▶ │  JOURNAL  │
│  (event)  │   LLM synthesises    │ (belief)  │
└─────┬─────┘   observations &    └─────┬─────┘
      │         hypotheses              │
      │                                  │
      │ store_fact()                    │ confidence decay
      ▼                                  │ (30d halflife)
┌───────────┐    recall bumps     ┌─────▼─────┐
│   FACT    │ ◀────────────────   │  RETIRE   │
│  (truth)  │   confidence +0.05  │ (floor)   │
└─────┬─────┘                     └─────┬─────┘
      │                                 │
      │ revise / supersede              │ GC prunes
      ▼                                 ▼
┌───────────┐                      ┌───────────┐
│ SUPERSEDED│   90 days retention  │  PRUNED   │
│ (replaced)│ ───────────────────▶ │ (deleted) │
└───────────┘                      └───────────┘

UNIFIED SCORE = relevance × confidence × recency
Applied across ALL layers before every response.

No-LLM Mode

The store, retrieval, decay, GC, and embedding versioning all work without any LLM. Only the reflection loop needs a model. If you just want durable, decaying memory:

store = MemoryStore(config=MemoryConfig(db_path="./mem.db"))
store.remember(task="something happened", outcome="success")
context = await store.retrieve("something")

With Reflection

from memlife import MemoryStore, MemoryConfig, Reflector, DummyEmbedder, DummyChat

store = MemoryStore(
    config=MemoryConfig(db_path="./mem.db"),
    embedder=DummyEmbedder(),
)
reflector = Reflector(
    memory=store,
    model_chat=DummyChat(),
    critic=False,
)
result = await reflector.reflect()

For real LLMs, implement the Embedder and ChatCallable protocols, or use an adapter (Phase 2).

Features

  • Four-tier lifecycle: Episode → Fact → Journal → Decay/Prune
  • Unified scoring: relevance × confidence × recency across all layers
  • Confidence ceiling (0.99) — facts are never immutable
  • Confidence decay with 30-day halflife — journal entries fade
  • GC with configurable retention (90 days for superseded facts, etc.)
  • Embedding versioning — detect stale vectors when the model changes
  • Episode tool index — search "have I used this tool before?"
  • Incremental contradiction detection — O(new × n), not O(n²)
  • JSONL import/export for backup and migration
  • SQLite-backed, single file, zero external services
  • Works with zero dependencies (DummyEmbedder + DummyChat)

Status

v0.1.0-beta. The API may change before v1.0.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

memlife-0.1.0b0.tar.gz (43.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

memlife-0.1.0b0-py3-none-any.whl (42.4 kB view details)

Uploaded Python 3

File details

Details for the file memlife-0.1.0b0.tar.gz.

File metadata

  • Download URL: memlife-0.1.0b0.tar.gz
  • Upload date:
  • Size: 43.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for memlife-0.1.0b0.tar.gz
Algorithm Hash digest
SHA256 ad4fa3e10f5f9eb245e7b3fb5f2dfe01f4e7e256a6316d30efd99e046d00a928
MD5 26787217a49bce2caeb14b4a42f76ba5
BLAKE2b-256 ab5a960c10fe4765a431f8b3d453e14b5f00490e7163b90d5e3b8f4700cd0d31

See more details on using hashes here.

File details

Details for the file memlife-0.1.0b0-py3-none-any.whl.

File metadata

  • Download URL: memlife-0.1.0b0-py3-none-any.whl
  • Upload date:
  • Size: 42.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for memlife-0.1.0b0-py3-none-any.whl
Algorithm Hash digest
SHA256 e69d1314277b05990c6b99e730b488c383576e610bcc93c9ddead8f5ce33eb1b
MD5 aff01e1c1cdd0e8a667b2fe1a6ebd65d
BLAKE2b-256 dd060b492928594c61737caa28704b1fc22a122c096eccaa893f5ef7b0841ec4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page