Selecting Better Training Data for Agents
Listen to the summary
Uses a voice available on your device
Audio options
On this page 5 sections
Related concepts 3 concepts
Key Takeaways
- Training on a selected 10% subset of trajectories outperforms training on the full dataset.
- Models achieve relative performance gains of up to 12.2% on SWE-Bench Verified.
- Models achieve relative performance gains of up to 24.2% on SWE-Bench Pro.
- The method effectively filters out redundant or low-quality data that can otherwise hinder model learning.
Summary & Methodology Analysis
SWE-Prime addresses the issue where fine-tuning, the process of updating a model on specific data to improve task performance, suffers from noisy or redundant data in software engineering trajectory datasets. The researchers use clustering and segmentation to evaluate the utility of individual steps within an agent's problem-solving history. By identifying which segments contribute to a successful outcome, the system filters the training data to focus on high-quality sequences. The team encoded issue descriptions using the Qwen3-Embedding-8B model to facilitate this selection process. This focused approach ensures that the model learns from effective behaviors rather than being diluted by extraneous information, allowing for significant improvements in downstream benchmarks even when using only a fraction of the total available data.
Interactive System Flowchart
Illustrative Implementation
A short sketch of the paper's core idea, not the authors' own code.
# Illustrative sketch (not from the paper)
import torch
import hdbscan
from qwen3_embedding import embed_text # placeholder for Qwen3-Embedding-8B
# 1. Load trajectories (list of steps per issue)
trajectories = load_trajectories() # each traj: {'issue': str, 'steps': [str]}
# 2. Encode issue descriptions for clustering
issue_embeddings = [embed_text(t['issue']) for t in trajectories]
# 3. Cluster trajectories with HDBSCAN
clusterer = hdbscan.HDBSCAN(min_cluster_size=5)
labels = clusterer.fit_predict(issue_embeddings)
# 4. Select high‑quality trajectories (e.g., label != -1)
selected = [t for t, lbl in zip(trajectories, labels) if lbl != -1]
# 5. Semantic segment chunking (boundary‑aware sliding window)
def chunk_segments(steps, win=3, stride=1):
segs = []
for i in range(0, len(steps) - win + 1, stride):
segs.append(steps[i:i+win])
return segs
# 6. Score each segment (placeholder scoring function)
def score_segment(seg):
# contribution, learnability, risk – mocked as a scalar
return compute_quality_score(seg)
# 7. Prepare SFT data: retain all segments as context, but compute loss only on high‑score ones
train_data = []
for traj in selected:
segments = chunk_segments(traj['steps'])
scores = [score_segment(s) for s in segments]
high_quality = [s for s, sc in zip(segments, scores) if sc > QUALITY_THRESHOLD]
train_data.append({'context': segments, 'target': high_quality})
# 8. Simple SFT loop (PyTorch)
model = load_model('GLM-4.7-Flash')
optimizer = torch.optim.AdamW(model.parameters(), lr=1e-5)
for epoch in range(3):
for item in train_data:
optimizer.zero_grad()
loss = model.compute_loss(context=item['context'], target=item['target'])
loss.backward()
optimizer.step()
// Illustrative sketch (not from the paper)
const torch = require('torch-js'); // placeholder for PyTorch‑like API
const hdbscan = require('hdbscan-js'); // placeholder library
const { embedText } = require('qwen3-embedding'); // placeholder for Qwen3-Embedding-8B
// 1. Load trajectories (array of {issue, steps})
const trajectories = loadTrajectories();
// 2. Encode issue descriptions
const issueEmbeddings = trajectories.map(t => embedText(t.issue));
// 3. Cluster with HDBSCAN
const clusterer = new hdbscan.HDBSCAN({ minClusterSize: 5 });
const labels = clusterer.fitPredict(issueEmbeddings);
// 4. Keep trajectories with a valid cluster label
const selected = trajectories.filter((_, i) => labels[i] !== -1);
// 5. Semantic segment chunking (sliding window)
function chunkSegments(steps, win = 3, stride = 1) {
const segs = [];
for (let i = 0; i <= steps.length - win; i += stride) {
segs.push(steps.slice(i, i + win));
}
return segs;
}
// 6. Placeholder segment scoring
function scoreSegment(seg) {
// returns a scalar quality score
return computeQualityScore(seg);
}
// 7. Build training examples
const trainData = selected.map(traj => {
const segments = chunkSegments(traj.steps);
const scores = segments.map(scoreSegment);
const highQuality = segments.filter((s, idx) => scores[idx] > QUALITY_THRESHOLD);
return { context: segments, target: highQuality };
});
// 8. Simple SFT loop (using a mock torch model)
const model = loadModel('GLM-4.7-Flash');
const optimizer = new torch.optim.AdamW(model.parameters(), { lr: 1e-5 });
for (let epoch = 0; epoch < 3; epoch++) {
for (const item of trainData) {
optimizer.zeroGrad();
const loss = model.computeLoss({ context: item.context, target: item.target });
loss.backward();
optimizer.step();
}
}
Cross-Examination & FAQs
A deeper dive clarifying mechanics, constraints, and baseline evaluations.
Q1. What is the primary contribution of this research?
The research introduces SWE-Prime, a data selection method that improves the training of software engineering agents by focusing on high-quality subsets of training trajectories.
Q2. Does this method require training on the entire dataset?
No, the researchers found that training on just a 10% subset of trajectories yields better results than using the full dataset.
Q3. What are the core benefits observed by the researchers?
The method yields relative performance gains of up to 12.2% on SWE-Bench Verified and 24.2% on SWE-Bench Pro.
Q4. What models were used to test this approach?
The researchers evaluated GLM-4.7-Flash, Qwen3-30B-A3B-Instruct-2507, and Qwen3-Coder-30B-A3B-Instruct.
Q5. How are issue descriptions processed?
Issue descriptions are encoded using the Qwen3-Embedding-8B model.
Q6. What is a potential downside of retaining too many trajectories?
Including trajectories beyond the 10% threshold provides no further benefit and may reintroduce redundant or lower-quality supervision.
Q7. What are the limitations of the SWE-Prime method?
The method requires determining an appropriate trajectory retention ratio and segment score threshold, which vary based on the specific pool of training data.
Q8. Is the proportion of high-quality supervision known beforehand?
No, the researchers must determine the selection configuration of SWE-Prime before conducting evaluations because the quality proportion in a trajectory pool is not known a priori.
Q9. What is the consequence of retaining too few trajectories?
Retaining too few trajectories can limit data coverage, potentially harming the model's performance.