Papers
Topics
Authors
Recent
Search
2000 character limit reached

SWE-Pruner: Adaptive Code & Robotic Pruning

Updated 26 January 2026
  • SWE-Pruner is a context-aware framework that reduces unnecessary information in both large code bases and tree canopies using goal-specific hints.
  • In software engineering, it employs a neural skimmer with a CRF-based pruning head to selectively trim code while preserving syntax and agent performance.
  • In horticulture, an autonomous robotic system uses perception, geometric heuristics, and RL-driven motion planning to achieve efficient, precise tree pruning.

SWE-Pruner denotes two distinct research systems: a self-adaptive context pruning framework for coding agents (Wang et al., 23 Jan 2026) and an autonomous robotic platform for tree pruning in agricultural environments (You et al., 2022). Both leverage context-driven selection mechanisms but operate in different application domains—software engineering and precision horticulture, respectively. The term “SWE-Pruner” thus refers to context-aware reduction techniques, either for source code as consumed by LLM agents, or for automated actuation in tree canopies.

1. Self-Adaptive Context Pruning for Coding Agents

SWE-Pruner (Wang et al., 23 Jan 2026) introduces a framework for adaptive reduction of long code contexts in LLM-driven software engineering tasks. The approach is motivated by the inefficiency and high cost associated with large, undifferentiated code windows provided to agentic systems during activities such as bug fixing, refactoring, and code completion.

Formally, the coding agent receives retrieved code context C={x1,,xn}C = \{x_1,\ldots,x_n\} and a natural-language goal hint qq. Context CC is line tokenized into L={l1,,lm}L = \{l_1,\ldots,l_m\}, with each ljl_j containing tokens TjT_j. The pruning operation is governed by a binary mask M{0,1}mM \in \{0,1\}^m, determining which lines to retain for subsequent agent actions. The optimization seeks to minimize total token count CM1\|C_M\|_1 while maintaining agent performance above a threshold δ\delta:

minMCM1s.t.Perf(Agent(CM,q))δ.\min_M \|C_M\|_1 \quad \mathrm{s.t.} \quad \mathrm{Perf}(\mathrm{Agent}(C_M, q)) \geq \delta.

A Lagrangian relaxation expresses this trade-off:

L(M)=j=1mMjlj+αmax{0,δPerf(Agent(CM,q))}\mathcal{L}(M) = \sum_{j=1}^m M_j |l_j| + \alpha \max\{0,\, \delta - \mathrm{Perf}(\mathrm{Agent}(C_M, q))\}

2. Goal Hint Generation and Skimmer Mechanism

Before file inspection, the agent issues a “context_focus_question”—a concise, task-specific query expressing the information need, e.g., “focus on error handling logic.” This hint is passed along with the raw code to SWE-Pruner. The central component is a lightweight, 0.6B-parameter neural skimmer backbone (Qwen3-Reranker-0.6B) that encodes (C,q)(C, q), fusing activations from selected transformer layers via self-attention and multi-head attention blocks.

The skimmer yields two outputs:

  • A CRF-based pruning head, which assigns binary token-level retain/prune labels via structured decoding.
  • A reranker head, predicting relevance scores at the document level.

Scoring for each token xix_i proceeds as si=F(q,xiC;θ)s_i = \mathcal{F}(q, x_i|C; \theta), aggregated per line as sˉj=1TjtTjst\bar{s}_j = \tfrac{1}{|T_j|}\sum_{t \in T_j} s_t. CRF negative log-likelihood drives the sequence labeling:

LCRF=[score(x,y)logZ(x)].\mathcal{L}_{CRF} = -[\mathrm{score}(x,y) - \log Z(x)].

The overall training objective blends CRF and reranker losses:

Ltotal=(1λ)LCRF+λLrerank.\mathcal{L}_{total} = (1-\lambda)\, \mathcal{L}_{CRF} + \lambda\, \mathcal{L}_{rerank}.

3. Adaptive Pruning Algorithm and Training Data

The inference pipeline decodes token-level labels using Viterbi over the CRF, computes average line scores, and applies a threshold τ\tau (default 0.5) to determine retention:

1
2
3
4
5
6
7
8
9
function SWE_Prune(raw_context C, goal q, threshold τ=0.5):
    # Tokenize
    # Encode via skimmer model
    # CRF/Viterbi decode
    for each line:
        avg_score = mean(P(y_t=retain) for t in line)
        if avg_score > τ:
            keep line
    return concatenated kept lines
Dataset construction employed 200K Python code snippets from “GitHub Code 2025” (≈1.5M repositories), filtered and annotated by large LLMs (Qwen3-Coder-30B-A3B, Qwen3-Next-80B) over nine query categories (summarization, debugging, localization, etc.), with the final corpus comprising 61,184 high-quality samples.

4. Empirical Evaluation and Results

SWE-Pruner was evaluated on multi-turn agentic (SWE-Bench Verified, SWE-QA) and single-turn benchmarks (Long Code Completion, Long Code QA), supporting various agent models (Claude Sonnet 4.5, GLM 4.6, OpenHands).

Selected quantitative findings:

Benchmark Token Reduction Compression Ratio Success/Accuracy Impact
SWE-Bench Verified (Claude Sonnet 4.5) −23.1% 70.6% → 70.2%
SWE-Bench Verified (GLM 4.6) −38.3%
SWE-QA (repo QA) 29–54% ≤0.2 point change
Long Code Completion (4× constraint) 5.56× ES: 58.63, EM: 31.5
Long Code QA (8× constraint) 14.84× 58.71% accuracy

The system demonstrated minimal degradation in outcome metrics, even under substantial context reduction.

5. Task Sensitivity, Syntax Preservation, and Limitations

SWE-Pruner’s efficacy depends on precise goal hints. Ablation studies revealed that absence of a goal eliminates compression benefits, and imprecise hints reduce label accuracy by approximately 3–5%. The 0.6B skimmer model offers a balance between capacity and inference latency; larger rerankers yield only marginal improvements at the cost of higher computational burden.

Line-level pruning, in contrast to token-centric approaches, preserves code syntax: measured abstract syntax tree (AST) validity reaches 87.3%, whereas token-level pruning methods achieve only 12.4% according to Tree-sitter analysis. Over-pruning or ambiguous hints remain risks for context loss and agent failure.

6. Robotic Pruning: SWE-Pruner in Horticulture

SWE-Pruner also references a three-stage robotic pruning system for planar sweet cherry trees (You et al., 2022). The platform integrates perception, pruning-point determination, and manipulation, orchestrated via ROS. The manipulator (UR5e + prismatic slide, 7 DoF) scans canopies at 28 waypoints. Perception deploys an “eye-in-hand” RGB camera and fuses optical flow (SegFlow2) with RGB via a pix2pix GAN, with Mask R-CNN instance segmentation specialized to leaders and side branches.

Pruning points emerge from geometric heuristics (PCA-fitted mask segments, intersection logic, pixel offset), lifted into 3D under a fixed plane (Z=0.30Z=0.30 m) and mapped to the robot base frame. Manipulation uses RRT-Connect (OMPL) motion planning and a closed-loop PPO-trained RL controller in PyBullet, modulating the end-effector’s velocity vector V=[svx,svy,s]TV = [s v_x, s v_y, s]^T, with admittance control engaging if contact force exceeds 1.5 N.

Field trials in a commercial orchard yielded a cutting success rate of 58% over 10 trees, with significant contributions from perception and planning errors. Throughput reached 35.1 s per cut on first-try approaches. Limitations include fixed plane model depth errors, conservative hardware kinematics, and GAN misclassification effects.

7. Extensions, Open Problems, and Future Directions

Potential short-term enhancements for SWE-Pruner's coding agent application encompass dynamic thresholding (budget-aware pruning), multilingual model training, integration with agentic history compression (e.g., joint optimization with ACON or AgentFold), and distillation for improved latency. RL fine-tuning of the end-to-end pruning policy is posited for direct cost-performance optimization.

For the robotic pruning domain, expansion involves leveraging true depth for 3D branch-length filtering, intersection logic refinement, increased closed-loop frequency (via onboard GPU upgrades), and improved manipulator topology to extend workspace and planning reliability.

A plausible implication is that the context-aware, goal-driven selection paradigm underlying both variants of SWE-Pruner informs a wider set of “selective pruning” frameworks, applicable wherever structured reduction of complex contexts is essential for agentic or autonomous system throughput without performance compromise.

Definition Search Book Streamline Icon: https://streamlinehq.com
References (2)

Topic to Video (Beta)

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to SWE-Pruner.