Skip to content

OpenClaw's Memory Problem: How Two Open Source Projects Cut Token Costs by 96%

Recently, I've heard countless complaints from people running OpenClaw locally. It's a love-hate relationship.

At first, when you're writing code or running tasks, it's brilliant—like a senior architect. But as tasks drag on, it starts exposing two fatal engineering pain points.


The Two Fatal Flaws

1. The Goldfish Memory

Anyone who understands the basics knows: large models are stateless. They have no real long-term memory.

How does an Agent like OpenClaw remember your requirements? It can only simulate short-term memory by stuffing historical conversations and project-specific Memory files (memory.md) back into the Prompt every single time.

But as the timeline extends, this lobster starts going crazy.

2. The Token Bill Explosion

Traditional Agent frameworks maintain this so-called "memory" by continuously re-splicing historical conversations and tool call logs into the next Prompt request.

Many outsiders think this is just a matter of word count. But anyone who truly understands Agent engineering knows: the real killer here is information density.

Think about it: you ask the lobster to fix a bug, it runs a shell command, and suddenly you're hit with 5,000 tokens of verbose error logs. Then it runs a grep search, and another 2,000 tokens of code snippets flood in.

After all this unrefined, noisy output gets stuffed into the context, the truly effective information might be less than 5%.

As tasks progress, invalid context expands rapidly, and the signal-to-noise ratio plummets. This not only drowns the model in noise—leading to misjudgments and hallucinations—but your API billing statement skyrockets to heart-attack levels.

Without deep additional engineering optimization, this default mechanism is nearly impossible to deploy directly into real enterprise production environments.


The Solution: A Memory Mechanism Overhaul

To evolve your lobster into a super-agent capable of long-term planning, we must perform major surgery—reconstructing its memory mechanism from the ground up.

I recently spent several days diving deep into two god-tier open source projects on GitHub:

  • claude-mem
  • OpenViking

After studying them, I can only say: absolutely mind-blowing.

They provide textbook-level solutions for single-agent memory compression and multi-agent coordination systems, respectively.

Today, let's hardcore dissect these two open source artifacts that can skyrocket your lobster's IQ and slash token consumption by 96%.


Artifact 1: claude-mem — The Ultimate Progressive External Brain for Single Agents

Let's first solve the memory problem when a single lobster operates alone.

When people think about adding memory to a单体 Agent, the first reaction is usually RAG (Retrieval-Augmented Generation) with a vector database.

But traditional RAG has a fatal flaw: it's too flat.

It recalls massive amounts of noise-filled废弃 code and chit-chat records, which only further reduces information density and makes the lobster even more confused.

claude-mem provides an extremely elegant engineering solution. Although it was originally a plugin for Claude Code, its core mechanism perfectly addresses our pain points when tuning OpenClaw.

Why It's Amazing

1. Extremely Restrained Progressive Context Disclosure

To save those extremely expensive tokens, claude-mem adopts a sophisticated "Three-Tier Retrieval Workflow".

When the lobster needs to recall the past, the system never dumps tens of thousands of words of history directly in its face. Instead, it first searches out an extremely concise index directory (consuming very few tokens per entry).

Then, if needed, it pulls the timeline. Finally, only when the lobster explicitly determines that a certain record has core value for the current task, it fetches the complete details via a specific ID.

This "table of contents first, then flip to the chapter" mechanism blocks 90% of无效废话 right at the door, compressing token costs by a full 10x.

2. Unconscious Automatic Lifecycle Listening

Under the hood, it intercepts 5 key lifecycle events. While you focus on coding, its background Worker service silently captures all of the lobster's operations.

Then, it calls the large model to distill lengthy operation flows into high-density semantic summaries, storing them in a SQLite + Chroma dual-database hybrid storage.

You can even open its Web UI console locally and watch, like scrolling through a social media feed, how your single lobster forms a high-quality memory stream in real time.


Artifact 2: OpenViking — The OS Base for a Swarm of Lobsters

If claude-mem installs a super external brain for a single lobster, then when you try to use a swarm of lobsters (multi-agent cluster) to collaborate on a large project, things go completely out of control.

Lobster A's output gets passed to Lobster B. If the traditional approach is still hard-stuffing Prompts or dumping everything into the same flat database, then after multiple rounds of interaction, not only does context overflow随时, but when errors occur, you can't even Debug which lobster's memory got polluted. The entire chain becomes a giant black box.

This is where OpenViking enters the stage. It's a monster-level project open-sourced by Volcano Engine, specifically designed as an enterprise-grade context database for AI Agents.

OpenViking made an extremely unconventional decision: it completely abandons the fragmented vector storage of traditional RAG and pioneers the File System Paradigm.

It transforms the Memories, Resources, and Skills that this swarm of lobsters needs into a tree-structured directory system!

This means you can manage this AI swarm's brain just like managing your computer's hard drive, using paths like viking://resources/Agent_A_logs/.

The Dimensionality Strike It Delivers

1. Physically Isolated Yet Logically Interconnected Workspaces

In multi-lobster collaboration, you can easily define private directories and public directories.

The lobster responsible for research dumps scraped data into the public directory, and the lobster responsible for coding only reads from that directory. This completely isolates useless tool execution logs and终结 s memory pollution between multi-agents.

2. Passing Pointers Instead of Full Text

This is its most terrifying feature. It supports L0/L1/L2 hierarchical context loading.

When lobsters hand off tasks, they no longer need to transmit tens of thousands of words in full. Instead, they directly pass a context path or directory summary. The receiving lobster recursively fetches only the 5% of details it truly needs by following the tree-structured directory.

3. Black Box Terminator: Visualized Retrieval Traces

What if a swarm of lobsters collaborating reports an error? In OpenViking, retrieval traces are fully visualized. You can clearly see, like reading system logs, exactly how Lobster C traced back and pulled a piece of erroneous code from which specific directory. Debugging becomes extremely smooth.


The Numbers Don't Lie

Here's a set of official benchmark data based on OpenClaw:

After integrating OpenViking, OpenClaw's task completion rate on long-conversation test sets skyrocketed from a pathetic 35.65% to 51%~52%!

Even more exaggerated: compared to using traditional memory banks, thanks to this awesome file paradigm and hierarchical loading mechanism, input token costs dropped by approximately 96%!


Final Thoughts

After studying these two projects, I have deep reflections.

In the past two years of AI explosion, we've always been accustomed to solving problems with a "brute force wins miracles" mindset: context gets truncated? Stuff in more Prompts. Can't find accurate data? Switch to a more expensive vector database.

But this logic is absolutely unworkable in the face of truly complex engineering, especially with something like lobsters.

claude-mem and OpenViking point us toward a completely different path. They no longer use string-processing thinking to handle AI. Instead, they use the engineering mindset of building an OS base to manage Agent state and information density.

Whether it's a single lobster or a swarm, fine-grained context lifecycle management is the hallmark of AI truly maturing.

If you're still bleeding from your large model API bills, or being tortured to death by your amnesiac lobsters, take my advice: go clone these two projects from GitHub and study them thoroughly, right now.

They'll not only save you real money, but more importantly, they'll show you what a truly enterprise-grade AI workflow should look like.


That's all for today.

If this hardcore technical breakdown inspired you, feel free to drop a like, comment, or share. If you want to stay updated on AI engineering frontier discussions, give this blog a star ⭐

Thanks for reading. See you next time.


References:

Have ideas? Email me cnyfdr@gmail.com