work.jackmann.xyz
← Work

Software & Engineering · 2026

Sawtooth Memory

Author & Maintainer

A high-performance memory framework that eliminates main-thread blocking during conversation compression. Messages ingest instantly to L1 while a background worker summarizes to L2 — critical facts are extracted into an immutable entity ledger (L1.5) via deterministic NER before the LLM can hallucinate them away.

Python · LLM · LangGraph

Standard LLM memory systems (like LangChain's ConversationSummaryMemory) process conversation history sequentially on the main thread — the application freezes for 5–10 seconds while an LLM generates a new summary on every turn. These summaries suffer from the "Lost in the Middle" effect, frequently deleting UUIDs, names, and rules to save tokens.

  • Designed a four-layer memory stack (L0 system, L1 working, L1.5 entity ledger, L2 archive) stitched by ContextManager at prompt-build time.
  • Offloaded summarization to an async background worker — messages append to L1 instantly and control returns in milliseconds.
  • Extracted critical facts into an immutable entity ledger via deterministic regex NER before LLM compression runs.
  • Built dual compression backends (Ollama local, Cloud with OpenAI/Anthropic/Gemini) with turn-based batching and graceful hard-limit truncation.
  • Shipped native integrations for LangGraph (ToolMessage sanitization), LangChain LCEL, and a sync wrapper for Flask/Django.
  • 11.3× faster main-thread execution on 20-message conversations (5.7s vs 64.15s, RTX 5060 / phi4-mini).
  • 100% UUID and fact retention via L1.5 entity ledger vs variable recall with summary-only memory.
  • 10% lower final prompt token cost (454 vs 506 tokens) while preserving more context.
  • Published to PyPI with Redis and Postgres distributed storage adapters for horizontal scaling.
11.3×
Faster than standard summary memory (20-msg benchmark)
100%
UUIDs retained via L1.5 entity ledger
-10%
454 vs 506 tokens in final prompt
Instant
Non-blocking write, async compression
Agent LoopLangGraph · LangChain · custom
ContextManageradd_message · build_prompt
L1 WorkingInstant message ingest
L1.5 Entity LedgerDeterministic NER · conflict history
Background WorkerAsync LLM compression
L2 ArchiveCompressed narrative memory
  • Compression

    Async background worker

    Inline LLM summarization on main thread

    Async compression keeps the main thread responsive. Inline summarization blocks the user for 5–10 seconds per turn.

  • Fact retention

    Entity ledger with deterministic NER

    LLM-only summarization

    Regex extraction guarantees UUIDs and IDs survive compression. Summarization alone hallucinates and drops critical identifiers.

  • Storage default

    In-memory with pluggable Redis/Postgres

    Mandatory distributed store

    Zero-config for development. Redis and Postgres adapters enable multi-container deployments without API changes.

Loading demo…

0%