Preprint

2026

ContextWeaver

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

Yating Wu, Yuhao Zhang, Sayan Ghosh, Sourya Basu, Anoop Deoras, Jun Huan, Gaurav Gupta

Preprint · 2026

Overview

A coding agent may need an observation made many steps earlier. ContextWeaver links each step to the observations and decisions it depends on, then uses those links to choose what to keep in the next context. Execution feedback tracks steps that have failed or been superseded.

We evaluate ContextWeaver on five software-engineering and terminal benchmarks, with a fixed budget per task. It improves the resolve rate over a sliding window on all five and needs fewer agent steps. The largest gains are on long repository tasks. On SWE-Bench Pro Python tasks with Claude Sonnet 4.5, the resolve rate rises from 66.5% to 72.6%. The gains hold with two open-weight backbones and, with Kimi-K2.5, against a sliding window given the same total budget.

Paper

How context is built

Pipeline diagram. The latest message of the growing agent context is summarized into a node n_t and linked into a dependency graph rooted at n_0. On the right, a sliding window keeps only the most recent messages, while ContextWeaver serializes earlier messages selected through the graph.
The latest message is summarized into a node and linked to the earlier steps it depends on. Following these dependencies, ContextWeaver keeps a few earlier observations in full alongside the most recent steps and replaces the others with their node summaries (bottom right). A sliding window keeps only the most recent observations (top right). Figure 1

After each step, ContextWeaver updates the dependency graph and prepares the context for the next action.

  1. Add a node

    Represent the latest history entry as a node in the graph.

  2. Choose its parents

    Rank earlier steps by dependency likelihood and keep up to m parents. Exclude nodes marked Failed or Superseded.

  3. Follow the dependencies

    After warmup, collect the selected parents and their ancestors, up to the W-node limit.

  4. Build the context

    Keep the selected entries in full and compress the others. Preserve their original order.

During warmup, the agent receives the full history. Algorithm 1 gives the complete procedure.

The experiments use a lower-cost configuration. Parents are scored by shared files, shared identifiers, and recency instead of an LLM call. Observations outside the selected set are replaced by their node summaries.

Preprint
Method, experiments, comparisons with other context management, and case studies.

Results

Every method runs in SWE-agent with the same prompt, tools, and budget per task. Unless noted, the agent model is Claude Sonnet 4.5 with a $3 cap per task.

72.6%

SWE-Bench Pro Python resolve rate, up from 66.5% with a sliding window

5 of 5

benchmarks where ContextWeaver resolves more tasks than a sliding window

13–18%

fewer agent steps than a sliding window on each benchmark

Higher resolve rates on all five benchmarks

With the same budget, ContextWeaver resolves more tasks than a sliding window on every benchmark. The largest gains are on the SWE-Bench Pro large-change subset and SWE-EVO, the longest tasks.

Resolve rate (%), Claude Sonnet 4.5, mean of three runs
Sliding windowContextWeaver
SWE-Bench Pro, Python186 tasks
66.5
72.6 +6.1***
SWE-Bench Pro, large change22 tasks
60.6
71.2 +10.6
SWE-Bench Pro, Go/JS/TS175 tasks
37.5
41.3 +3.8
SWE-Bench Multilingual262–289 tasks
43.2
46.7 +3.5*
SWE-EVO42 tasks
23.8
31.7 +7.9
SWE-rebench212 tasks
27.2
30.3 +3.1*
Terminal-Bench 2.061 tasks
43.2
44.8 +1.6

Tasks graded in every run of both methods. Large change: the gold patch touches at least 4 files or 150 lines. * p < 0.05, *** p < 0.001, exact McNemar test pooled over runs.

Show table
BenchmarkSliding windowContextWeaverΔ
SWE-Bench Pro, Python (186 tasks)66.572.6+6.1***
SWE-Bench Pro, large change (22 tasks)60.671.2+10.6
SWE-Bench Pro, Go/JS/TS (175 tasks)37.541.3+3.8
SWE-Bench Multilingual (262–289 tasks)43.246.7+3.5*
SWE-EVO (42 tasks)23.831.7+7.9
SWE-rebench (212 tasks)27.230.3+3.1*
Terminal-Bench 2.0 (61 tasks)43.244.8+1.6

Consistent across backbones

On SWE-Bench Pro Python, the gain is significant with all three backbones. The summaries add cost, so we also gave the sliding window the same total budget with Kimi-K2.5. It resolves 53.4%, still below ContextWeaver.

Resolve rate (%) on 186 SWE-Bench Pro Python tasks, mean of three runs
Sliding windowContextWeaver
Claude Sonnet 4.5$3.00 cap per task
66.5
72.6 +6.1***
Kimi-K2.5$0.60 cap per task
54.1
62.7 +8.6***
GLM-5$1.00 cap per task
61.6
69.5 +7.9***

The caps give each backbone the same token budget. *** p < 0.001, exact McNemar test pooled over runs.

Show table
BackboneSliding windowContextWeaverΔ
Claude Sonnet 4.5 ($3.00 cap per task)66.572.6+6.1***
Kimi-K2.5 ($0.60 cap per task)54.162.7+8.6***
GLM-5 ($1.00 cap per task)61.669.5+7.9***

Against other context management

We also compare with keeping the full history, LLM summarization, BM25 retrieval, and a hybrid of summarization and a sliding window. On the large-change tasks, ContextWeaver resolves 71.2%, and the next best method resolves 63.6%. On the Pro sample, it ties with the sliding window.

Resolve rate (%) on two SWE-Bench Pro task sets, same budget for every method

Large change 22 tasks

ContextWeaver
71.2
Sliding window
60.6
Full history
63.6
LLM summarization
62.1
Retrieval (BM25)
62.1
Hybrid
59.1

Pro sample 26 tasks

ContextWeaver
72.3
Sliding window
72.3
Full history
67.9
LLM summarization
64.1
Retrieval (BM25)
71.8
Hybrid
67.9

Mean of three runs; five for the sliding window and ContextWeaver on the Pro sample. Hybrid: a sliding window with periodic LLM summarization (Lindenbauer et al., 2025).

Show table
MethodLarge change (22 tasks)Pro sample (26 tasks)
ContextWeaver71.272.3
Sliding window60.672.3
Full history63.667.9
LLM summarization62.164.1
Retrieval (BM25)62.171.8
Hybrid59.167.9
Source

Table 1 · Table 2 · Table 7 · Table 11. Values are taken from these tables; Δ is ContextWeaver minus the sliding window.

Citation

Download BibTeX
View BibTeX
@misc{contextweaver2026,
  title={{ContextWeaver: Selective and Dependency-Structured Memory Construction for LLM Agents}},
  author={Wu, Yating and Zhang, Yuhao and Ghosh, Sayan and Basu, Sourya and Deoras, Anoop and Huan, Jun and Gupta, Gaurav},
  year={2026},
  eprint={2604.23069},
  archivePrefix={arXiv},
  primaryClass={cs.CL},
  url={https://arxiv.org/abs/2604.23069}
}