ContextWeaver: Selective and Dependency-Structured Memory Construction for LLM Agents
ContextWeaver is a memory framework for LLM agents that improves long-context reasoning by organizing interaction history into a dependency-structured graph of reasoning steps, allowing for selective, summarized, and validated context retrieval.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
Imagine you are a detective trying to solve a massive, complex mystery in a giant mansion.
As you move from room to room, you find clues: a muddy footprint in the kitchen, a broken vase in the library, and a mysterious note in the attic.
The Problem: The "Goldfish" Detective
Current AI "agents" (the digital detectives) have a problem called "Context Window" limits. Think of this like the detective having a very small notebook. As they find more clues, they run out of pages. To keep going, they usually do one of two things:
- The Sliding Window (The "Forgetful" Method): They simply rip out the oldest pages to make room for new ones. The problem? They might rip out the page containing the first clue (the muddy footprint), forgetting that the footprint is the only reason they are looking in the attic in the first place!
- The Summarizer (The "Lazy" Method): They try to write a tiny summary of everything they've seen so far. But in their rush, they might write "Found some clues in the kitchen," forgetting the crucial detail that the footprint was left-footed.
When the detective forgets the "why" behind their actions, they start walking in circles, repeating mistakes, or looking in the wrong rooms entirely.
The Solution: ContextWeaver (The "Web of Clues")
The researchers created ContextWeaver. Instead of a simple notebook, imagine the detective now has a giant, glowing spiderweb hanging in the center of the mansion.
Every time the detective finds a new clue, they don't just write it down; they tie a string from that new clue back to the specific old clues that led them there.
ContextWeaver works using three clever tricks:
1. The Dependency Web (The "Why" String)
Instead of just remembering things in the order they happened (First, Second, Third...), ContextWeaver remembers them by logic.
- Example: "I am looking at this broken vase (New Clue) because I saw the muddy footprint in the kitchen (Old Clue)."
The AI builds a "map" of connections. If it needs to solve a problem in the attic, it doesn't just look at the last thing it did; it follows the strings back to the most important "root" clues.
2. The Smart Summarizer (The "Highlight Reel")
Since the AI can't remember everything in high detail, ContextWeaver creates "mini-stories" along the strings. Instead of a messy pile of notes, it creates a streamlined narrative: "Started at the kitchen found footprint traced to library found broken vase." This keeps the "story" of the investigation short and easy to read, saving precious space.
3. The Reality Check (The "Truth Filter")
The AI also has a built-in "Fact Checker." If the detective tries to pick a lock and fails, ContextWeaver marks that attempt as "FAILED." When building the web, the AI is told: "Don't tie your new ideas to failed attempts; only tie them to things that actually worked or gave us real information." This prevents the AI from getting stuck in a loop of repeating its own mistakes.
Does it actually work?
The researchers tested this on "SWE-Bench," which is basically a high-level exam where AI agents have to fix real-world computer code (a very messy, "mansion-sized" task).
The results showed:
- Better Success: The AI was better at solving complex problems that required connecting dots across different files.
- Less Wandering: The AI didn't repeat the same mistakes as often.
- More Efficient: It reached the solution using fewer "steps" and less "brain power" (tokens) because it wasn't wasting time re-reading things it already knew or following dead ends.
In short:
ContextWeaver turns an AI from a forgetful worker who only cares about what happened just now, into a strategic thinker who understands how every single step is connected to the big picture.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.