Context as a Tool: Context Management for Long-Horizon SWE-Agents

AuthorsShukai Liu, Jian Yang, Bo Jiang et al.

2025

TL;DR

CAT treats context management as a callable tool inside SWE-Compressor, enabling structured context folding to reach 57.6% Pass@1 on SWE-Bench-Verified (+3.8 over Threshold-Compression).

SharePost on XLinkedIn

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

THE PROBLEM

Long-horizon SWE agents hit context explosion and reasoning collapse

CAT targets long-horizon SWE agents that suffer from context explosion, semantic drift, and degraded reasoning when append-only logs grow over hundreds of steps.

On repository-scale issue resolution like SWE-Bench-Verified, ReAct-style agents exhaust context windows, causing early termination or reasoning collapse instead of stable long-horizon interaction.

HOW IT WORKS

CAT and SWE-Compressor — structured context workspace with toolized compression

CAT builds a structured context workspace with a Fixed Segment, Long-Term Memory Segment, and High-Fidelity Working Memory Segment, and trains SWE-Compressor using CAT-GENERATOR to call a context tool as an action.

You can think of CAT like a computer with RAM and disk: the High-Fidelity Working Memory Segment is RAM, the Long-Term Memory Segment is disk, and the context tool is a DMA controller moving summaries between them.

By turning context management into a first-class tool, CAT lets SWE-Compressor decide when to compress trajectories into structured memory blocks, something a plain context window with passive thresholds cannot coordinate over hundreds of ReAct steps.

DIAGRAM

ReAct interaction with CAT context tool

This diagram shows how SWE-Compressor interleaves ReAct thoughts, environment tools, and the CAT context tool over a long SWE-Bench trajectory.

DIAGRAM

CAT-GENERATOR data construction and training pipeline

This diagram shows the CAT-GENERATOR pipeline that builds CAT-Instruct trajectories and trains SWE-Compressor with injected context-management actions.

PROCESS

How CAT Handles a SWE-Bench Interaction Trajectory

  1. 01

    Structured Context Workspace

    CAT initializes the Fixed Segment with system prompt and issue Q, and empty Long-Term Memory Segment and High-Fidelity Working Memory Segment before SWE-Compressor starts ReAct reasoning.

  2. 02

    Context Management as a First-Class Tool

    During ReAct steps, SWE-Compressor decides whether to invoke the context tool alongside execute_bash and str_replace_editor, treating context folding as a normal action.

  3. 03

    Structured Memory Generation

    When the context tool is called, CAT segments Q, I(k)(t), and compressible history, and uses SWE-Compressor as a summarizer to generate a long-term memory block M(t).

  4. 04

    Supervised Trajectory Construction

    CAT-GENERATOR builds CAT-Instruct by injecting these context tool calls and memory blocks into base ReAct trajectories, then SWE-Compressor is fine-tuned on these trajectories.

KEY CONTRIBUTIONS

Key Contributions

  • 01

    CAT context management paradigm

    CAT turns context management into a callable tool inside SWE-Compressor, integrating it with ReAct decisions instead of relying on passive thresholds or append-only logs.

  • 02

    Structured context workspace with proactive folding

    CAT defines a Fixed Segment, Long-Term Memory Segment, and High-Fidelity Working Memory Segment, enabling stage-wise context folding while keeping average context under 32k tokens over 500 rounds.

  • 03

    CAT-GENERATOR and SWE-Compressor

    CAT-GENERATOR constructs 20k CAT-Instruct trajectories with an average of 87.4 steps and 4.22 context actions, training SWE-Compressor to reach 57.6% Pass@1 on SWE-Bench-Verified.

RESULTS

By the Numbers

Pass@1

57.6%

+3.8 over Threshold-Compression Agent

Pass@1

57.6%

+7.8 over ReAct Agent

Pass@1

57.6%

matches GLM-4.5-Air at 57.6% with 12/106B scale

Pass@1

57.6%

within 1.6 of FrogBoss-32B at 54.6% and 2.4 of Seed-OSS-36B at 55.2%

On SWE-Bench-Verified (500 instances), SWE-Compressor with CAT reaches 57.6% Pass@1 using a 32B Qwen2.5-Coder backbone, showing that toolized context management can close much of the gap to larger 70B–480B systems under the same OpenHands scaffold.

BENCHMARK

By the Numbers

On SWE-Bench-Verified (500 instances), SWE-Compressor with CAT reaches 57.6% Pass@1 using a 32B Qwen2.5-Coder backbone, showing that toolized context management can close much of the gap to larger 70B–480B systems under the same OpenHands scaffold.

BENCHMARK

Performance comparison on SWE-Bench Verified (N=500)

Pass@1 on SWE-Bench-Verified for 32B agents under OpenHands or similar scaffolds.

KEY INSIGHT

The Counterintuitive Finding

SWE-Compressor with CAT maintains average context around 35k tokens yet keeps improving up to 500 interaction rounds, reaching 57.6% Pass@1.

This is surprising because ReAct baselines actually degrade from 53.2% to 48.8% when going from 150 to 500 steps, contradicting the intuition that more steps always help long-horizon agents.

WHY IT MATTERS

What this unlocks for the field

CAT gives SWE-Compressor a learned sense of when and how to compress history, enabling stable reasoning over hundreds of ReAct steps under a fixed 65,536-token budget.

Builders can now design SWE agents that treat context as a controllable tool, not a passive buffer, making repository-scale debugging and multi-stage refactors feasible without relying on ever-larger context windows.

~12 min read← Back to papers

Related papers

Agent MemoryLong-Term Memory

Adaptive Memory Admission Control for LLM Agents

Guilin Zhang, Wei Jiang et al.

· 2026

A-MAC scores candidate memories using Utility, Confidence, Novelty, Recency, and Type Prior combined by a learned linear admission policy with Algorithm 1 A-MAC Memory Admission. On the LoCoMo benchmark, A-MAC achieves F1 0.583 and 2644 ms latency, improving F1 by 0.042 and reducing latency by 1187 ms compared to A-mem.

Long-Term Memory

Advancing Open-source World Models

Robbyant Team, Zelin Gao et al.

arXiv 2026 · 2026

LingBot-World combines a Data Engine, Fundamental World Model, Action-Conditioned World Model, and Post-Training causal adaptation to turn a 28B-parameter video generator into a real-time interactive world simulator. On the VBench benchmark, LingBot-World achieves a dynamic degree of 0.8857 versus 0.7612 for Yume-1.5, while also improving imaging quality to 0.6683.

BenchmarkBenchmarkLong-Term Memory

AgenticAI-DialogGen: Topic-Guided Conversation Generation for Fine-Tuning and Evaluating Short- and Long-Term Memories of LLMs

Manoj Madushanka Perera, Adnan Mahmood et al.

· 2026

AgenticAI-DialogGen chains ChatPreprocessor, KnowledgeExtractor, TopicAnalyzer, KnowledgeGraphBuilder, PersonaGenerator, DuelingChat Agent, ConversationValidator, ConversationRefiner, QAGeneration, and PostProcessing to turn raw multi-session chats into topic-guided, persona-grounded conversations with explicit short- and long-term memories. On the TGC / KG memory QA benchmark, Mistral-7B fine-tuned within AgenticAI-DialogGen achieves 87.36 F1, compared to GPT-4’s 83.77 F1 in a zero-shot setting on the same task.

Questions about this paper?

Paper: Context as a Tool: Context Management for Long-Horizon SWE-Agents

Answers use this explainer on Memory Papers.

Checking…