ContextWeaver: Selective and Dependency-Structured Memory Construction for LLM Agents

AuthorsYating Wu, Yuhao Zhang, Sayan Ghosh et al.

2026

TL;DR

ContextWeaver uses a dependency-structured memory graph with compact dependency summaries and a validation layer to reach 66.0% pass@1 on SWE-Bench Verified vs 63.2% for a sliding window.

SharePost on XLinkedIn

Read our summary here, or open the publisher PDF on the next tab.

THE PROBLEM

LLM agents lose crucial dependencies in long contexts

ContextWeaver targets long-context interactions where sliding windows and prompt compression omit earlier structured information that later steps rely on.

When these dependencies are lost, tool-using LLM agents break ongoing plans, repeat exploration, and produce steps that no longer match the earlier context.

HOW IT WORKS

ContextWeaver: Dependency-Structured Memory for Tool-Using Agents

ContextWeaver centers on Dependency-Aware Context Construction, Dependency Summarizer, and a Validation and Test Layer to build a dependency graph over reasoning steps.

You can think of ContextWeaver like a card catalog plus margin notes, where each card cites earlier cards it depends on and marks whether its evidence held up.

This explicit dependency structure lets ContextWeaver preserve only validated, causally relevant paths for the next action, instead of blindly feeding a flat recency-based context window.

DIAGRAM

Step-by-step dependency-aware context weaving

This diagram shows how ContextWeaver processes each new reasoning step into a node, selects parents, builds ancestry, and weaves the final context.

DIAGRAM

Evaluation setup on SWE-Bench with ContextWeaver

This diagram shows how ContextWeaver is evaluated with different LLMs, baselines, and SWE-Bench splits.

PROCESS

How ContextWeaver Handles a Tool-Using Agent Trajectory

  1. 01

    Dependency-Aware Context Construction

    ContextWeaver converts each tool-use step into a node via Dependency-Aware Context Construction, linking it to earlier steps through LLM-based parent selection.

  2. 02

    Ancestry Dependency Construction

    ContextWeaver performs Ancestry Dependency Construction with a breadth-first traversal to collect supporting ancestors up to the warmup bound W.

  3. 03

    Dependency Summarizer

    The Dependency Summarizer incrementally builds a dependency summary for each node using parent dependency summaries and the node summary.

  4. 04

    Validation and Test Layer

    The Validation and Test Layer tracks test results, assigns validation status, and filters failed or superseded nodes before ContextWeaver weaves the final context.

KEY CONTRIBUTIONS

Key Contributions

  • 01

    Dependency-Aware Context Construction

    ContextWeaver introduces Dependency-Aware Context Construction that builds a directed acyclic graph over reasoning steps and weaves context from validated ancestors under a fixed warmup W=5.

  • 02

    Dependency Summarizer

    ContextWeaver adds a Dependency Summarizer that incrementally composes dependency summaries from parents, avoiding repeated full-history summarization while preserving reasoning paths.

  • 03

    Validation and Test Layer

    ContextWeaver integrates a Validation and Test Layer that labels nodes as passed, failed, unknown, or superseded so new steps never depend on failed or superseded states.

RESULTS

By the Numbers

Verified

66.0%

+2.8 over Sliding Window with Claude Sonnet 4

Lite

53.7%

+1.4 over Sliding Window with Claude Sonnet 4

Pass@1 (%)

68.0%

+0.8 over Sliding Window on 100-instance subset

Avg Steps

55.8

3.4 fewer steps than Sliding Window on 100-instance subset

On SWE-Bench Verified and Lite, which test repository-level bug fixing with real GitHub issues, ContextWeaver improves pass@1 over a Sliding Window baseline while using similar tokens. The 66.0% vs 63.2% pass@1 on Verified with Claude Sonnet 4 shows that dependency-structured memory yields more successful fixes under the same context budget.

BENCHMARK

By the Numbers

On SWE-Bench Verified and Lite, which test repository-level bug fixing with real GitHub issues, ContextWeaver improves pass@1 over a Sliding Window baseline while using similar tokens. The 66.0% vs 63.2% pass@1 on Verified with Claude Sonnet 4 shows that dependency-structured memory yields more successful fixes under the same context budget.

BENCHMARK

Performance Comparison Across Settings

Pass@1 on SWE-Bench Verified for different memory strategies with Claude Sonnet 4.

KEY INSIGHT

The Counterintuitive Finding

On a 100-instance SWE-Bench Verified subset, ContextWeaver and Sliding Window have similar mean Pass@1 (68.0% vs 67.2%), but ContextWeaver cuts average steps from 59.2 to 55.8.

This is surprising because a more complex dependency graph might seem slower, yet ContextWeaver actually reduces steps for 73% of instances compared to 27% for Sliding Window.

WHY IT MATTERS

What this unlocks for the field

ContextWeaver shows that explicitly modeling logical and causal dependencies can stabilize long-horizon tool use without increasing context size or token usage.

Builders can now design agents that keep only the validated reasoning backbone instead of raw recency, making long debugging sessions and complex multi-file fixes more reliable.

~12 min read← Back to papers

Related papers

BenchmarkAgent Memory

Active Context Compression: Autonomous Memory Management in LLM Agents

Nikhil Verma

· 2026

Focus Agent adds start_focus, complete_focus, a persistent Knowledge block, and an optimized Persistent Bash plus String-Replace Editor scaffold to actively compress context during long software-engineering tasks. On five hard SWE-bench Lite instances against a Baseline ReAct agent, Focus Agent achieves 22.7% token reduction (14.9M → 11.5M) while matching 3/5 = 60% task success.

Questions about this paper?

Paper: ContextWeaver: Selective and Dependency-Structured Memory Construction for LLM Agents

Answers use this explainer on Memory Papers.

Checking…