DEV Community

IdeaSniper
IdeaSniper

Posted on

I built an open-source Rust memory engine that cuts AI agent tokens by 96% across 1,000+ turns

If you use autonomous coding agents (Cursor, Claude Code, Antigravity, OpenClaw, Hermes, Codex), you've likely hit these long-sprint pain points:

  1. The "Turn 200" Amnesia: You set a database or security rule at step 10. By turn 250, the agent has completely forgotten it and breaks your build.
  2. The "Alert Storm" Doom Loop: A test fails and dumps 100 lines of error logs. Recency bias drowns out the real root cause that happened 50 turns ago.
  3. Runaway Token Costs: Re-sending full conversation history on turn 500+ burns 100k+ input tokens per prompt, quickly draining your wallet.

To solve this, I built and open-sourced Continuum — an ultra-lightweight, zero-dependency continuous temporal memory engine written in 100% pure standard library Rust.


Real Hardware Benchmarks (Apple M4)

Instead of stuffing 100k+ histories or spinning up heavy 2GB vector databases, Continuum maintains a strictly bounded physical memory manifold (750 slots, < 75 KB RAM).

We benchmarked Continuum using OpenAI tiktoken (cl100k_base) on an Apple M4 across real coding sessions:

Continuum Hardware-Verified Benchmarks

Metric Full Context Appending Standard Sliding Window (10 turns) Continuum (Native Rust Engine)
100-Turn Cumulative Tokens 148,522 tokens 26,450 tokens 5,896 tokens (96.03% slash)
Multi-Depth Needle Recall 5/5 (100%) 0/5 (0% - Forgotten) 5/5 (100% at Rank #1)
Rule Override & Contradiction Ambiguous prompt conflict ❌ 0% (Forgotten) 100% (Latest override at Rank #1)
Task Success / Build Pass 100% (High cost) ❌ 0% (Broken config) 100% (Tests pass, 96% token cut)
Engine Retrieval Overhead 1.2 ~ 2.5s (full history scan) N/A (truncated) 60.46 µs (< 0.0001s, 16,540 QPS)
End-to-End Prompt Latency 12 ~ 18s (100k token load) 1.1s (shallow window) 1.2s (compact 256-token prompt)
100,000-Step Stress Test Process Crash (OOM) Memory leaks Flat 750 slots (< 75 KB RAM, 0 leaks)

The Takeaway: Sliding windows save tokens but destroy outcomes (0% task success). Continuum cuts token usage by 96%~99% while guaranteeing 100% multi-depth recall and contradiction resolution.


How It Works in 4 Bullets

  • Physical $O(K)$ Bounded Memory: Exactly 750 slots (< 75 KB contiguous RAM). Memory usage stays a flat line forever across 100,000 steps.
  • Subspace Diversity Deduplication: Eliminates alert storms without naive FIFO eviction. 500 repetitive errors collapse into minimal slots, protecting ancient root causes.
  • Retrospective Causal Revision & Supersession: Bypasses decay for genuine anchors, while actively suppressing stale predecessors when rules are updated/contradicted.
  • Zero External Dependencies: 100% pure Rust std — single standalone binary, zero GC pauses, microsecond startup.

1-Minute Quickstart (MCP)

Continuum comes with a built-in Model Context Protocol (MCP) server for Cursor, Claude Desktop, and Antigravity:


bash
# 1. Install standalone CLI
curl -fsSL https://raw.githubusercontent.com/reacherwu/continuum/main/install.sh | bash

# 2. Init in any repo (< 75 KB memory manifold)
continuum-cli init .
Enter fullscreen mode Exit fullscreen mode

Top comments (3)

Collapse
 
_firelinks profile image
Mike Dabydeen

Bounded memory with a fixed slot count is the right shape for this. The part of the table I would rework is the retention row, because it carries the whole claim and it is the weakest measurement there.

"Did it remember Step 10 root cause" is one fact. A hundred percent on a single planted item is a demo rather than an accuracy. What would turn it into a number is a set of facts planted at a spread of depths, reported as a recall rate with a denominator.

The bigger gap is that the interesting failure of a bounded memory with dedup and causal anchoring is not forgetting a rule. It is serving one that was superseded. Set a rule at turn 10, change it at turn 300, and a design where ancient anchors defeat recent noise is doing the exact thing that hands back the old rule with high confidence. That is the case worth benchmarking, it is the one that costs real money in a long session, and a run that only tests the true positive cannot see it. Plant a contradiction and report what comes back.

The other missing axis is whether the agent still finished the job. Token reduction is easy to win on its own, and your sliding window row is the proof: it cuts tokens and destroys the outcome. Without a task success column next to the token column, 96% is optimising the cheap axis and reporting it as the result.

Smaller point on the latency row. Twelve to eighteen seconds for full context appending is model inference, and sixty microseconds is a local lookup. Those are different operations, so putting them in one column implies a speedup the engine does not claim and does not need.

Collapse
 
reacherwu profile image
IdeaSniper

Thanks for the sharp critique, Mike. This is genuinely high-signal feedback, and you’ve pinpointed the exact blind spots of the current benchmark.

A few quick thoughts on your points:

Superseded Rules / Contradictions: This is spot on. Rewriting or deprecating an earlier rule (e.g., step 10 vs. step 300) without letting stale causal anchors poison the context is indeed the hardest edge case for bounded memory. I’m currently designing a "contradiction / revocation" test suite to explicitly evaluate how well Continuum detects invalidation versus blind retention.

Recall Rate & Task Completion: Fair point on the single-fact demo. I plan to introduce a multi-depth needle/fact benchmark with an explicit recall denominator, alongside an end-to-end task completion rate (e.g., passing repo-level test suites) to prove token reduction doesn't degrade final outcomes.

Latency Apples-to-Oranges: Completely agree. Putting local Rust lookup (µs) in the same row as remote LLM inference (seconds) was misleading framing. I'll update the table to clearly distinguish retrieval overhead from inference latency.

Really appreciate you taking the time to write such a thoughtful review. It gives me a clear roadmap for the v0.2 benchmark!

Some comments may only be visible to logged-in visitors. Sign in to view all comments.