Skip to content

Ayanami1314/swe-pruner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SWE-Pruner: Self-Adaptive Context Pruning for Coding Agents

arXiv GitHub PyPI Hugging Face Bytedance License Blog

Semantic Highlight  ◦  Coding Agent Native  ◦  Flexibly Use  ◦  Long Context Tailored

Make Claude Tokens 40% Saving!

Tokens Cost Reduction

📢 Latest Updates

🔥 Releases:

📑 Introduction to SWE-Pruner

Tokens Cost Reduction

Are you struggling with excessive token costs and latency when using LLM agents for software development? Traditional context compression often relies on fixed metrics like perplexity (PPL) and ignores task-specific code understanding. But generic compression ≠ relevant preservation — we need task-aware context pruning that retains critical implementation details.

Inspired by how human programmers "selectively skim" source code, SWE-Pruner enables agents to formulate explicit goals and uses a lightweight neural skimmer to dynamically select relevant code lines. It operates in two key steps:

  • Formulate task-specific goals to guide the pruning process
  • Dynamically select relevant code lines using a lightweight neural skimmer

🎯 Core Features

🧠 Task-Aware Pruning Understands the intent (e.g., "focus on error handling") and uses it to guide context pruning process, beyond generic metrics.

🤖 Coding Agent Native Built for multi-turn workflows and integrates seamlessly into agent decision loops, providing just-in-time context for complex software engineering tasks.

🎨 Semantic Highlight A lightweight 0.6B model identifies and preserves semantically critical lines of code, keeping logical structures intact.

⚡ Extreme Compression Delivers significant token savings without sacrificing performance: 23-54% token reduction on SWE-Bench Verified and up to 14.84x compression on LongCodeQA, cutting API costs and latency.

🔧 Flexibly Use Adaptable framework for various LLMs and scenarios, from debugging to feature development.

🌲 Project Structure

.
├── data/                      # Experiment trace archives and hyperparameter configurations
├── downstream_eval/           # Downstream evaluation benchmarks
│   ├── multi_turn/            # Includes: SWE-bench, SWEQA (coming soon)
│   └── single_turn/           # Includes: LongCodeQA, LCC (LongCodeCompletion)
├── swe-pruner/                # Inference code and model utilities
│   └── model/                 # Model files for SWE-Pruner
├── examples                   # Examples for integrating with other agents like claude code and openhands

🧰 Prerequisites

This project uses uv for fast and efficient dependency management.

🎮 Quick Start

Go to Inference Tutorial and have a try!

Tips: For easier serving and reproducing, we upload our models in ./swe-pruner/model directory(tracked by git lfs). It make the serving more simple but greatly increase the repo size if you use git clone directly without lfs config (and might failed to download model for traffic limit of github lfs service). However, you can use the methods in the tutorial to download it from HuggingFace.

⚙️ Installation

Since different modules have different dependencies, please refer to the specific README file inside each subfolder for detailed installation instructions.

📖 User Guides

  • For Users, look Inference Tutorial to start a swe-pruner locally and then reading real world examples for agents integration.

  • For Developers, look ./train(coming soon) for training a pruner by yourself!

  • For Researchers, ./downstream_eval has some scripts for reproducing our results. We recommend to use slurm with at least 4 GPU to reuse our scripts.

🧪 Utils Scripts

We provide some utils scripts for continue improving the swe-pruner in ./utils, just look utils/README.md!

🔮 Coming Soon

  • 💻 Update Training Code of SWE-Pruner
  • 📁 Upload full parameters and trajectory files & logs
  • 📁 Upload Training Dataset of SWE-Pruner
  • 📁 Upload SWE-QA evaluation code
  • 🤗 Update HuggingFace model card
  • 🤗 Update HuggingFace blog to introducing our technical approach in detail.
  • 🎮 Update agents integrate demo

📜 Citation

@misc{wang2026sweprunerselfadaptivecontextpruning,
      title={SWE-Pruner: Self-Adaptive Context Pruning for Coding Agents}, 
      author={Yuhang Wang and Yuling Shi and Mo Yang and Rongrui Zhang and Shilin He and Heng Lian and Yuting Chen and Siyu Ye and Kai Cai and Xiaodong Gu},
      year={2026},
      eprint={2601.16746},
      archivePrefix={arXiv},
      primaryClass={cs.SE},
      url={https://arxiv.org/abs/2601.16746},
}

🏆 Acknowledgements

  • Bytedance Douyin Team for advises.
  • Alibaba Qwen Team for open-source models.

⭐ Star History

Star History Chart

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages