| name | socratic-swe-self-evolving-coding-agents |
| description | Self-Evolving Coding Agents via Trace-Derived Agent Skills (Socratic-SWE). Closed-loop framework that reuses solving traces to distill agent skills, generate targeted repair tasks, and iteratively improve Solver performance. Achieves 50.40% on SWE-bench Verified. Activation: self-evolving agent, coding agent training, trace-derived skills, SWE bench, agent skill distillation. |
Context
LLM-driven software engineering agents face a critical bottleneck: limited availability of high-quality SWE tasks for training. Existing synthetic data methods create tasks through fixed mutation or bug-injection procedures, producing task distributions independent of the agent's actual weaknesses and learning progress.
Socratic-SWE introduces a closed-loop self-evolution framework that treats solving traces not just as reward signals, but as substrates for skill extraction. These skills guide targeted task generation, creating a curriculum that adapts to the agent's specific failure patterns across successive iterations.
Core Methodology
1. Trace-Derived Skill Distillation
Extract Structured Skills from Solving Traces
- Solving traces contain: (1) code changes, (2) test outcomes, (3) error messages, (4) reasoning steps
- Distillation process:
- Identify recurring failure patterns across traces
- Extract effective repair patterns that succeeded
- Cluster by failure type → skill per cluster
- Skill structure:
{failure_pattern, repair_strategy, verification_check}
Skill Schema:
{
"skill_id": "skill_fix_import_error",
"failure_pattern": "ImportError: module X not found",
"repair_strategy": "Add missing import: 'import X' at top of file",
"verification_check": "Run tests to confirm import resolves error",
"frequency": 15,
"success_rate": 0.80
}
Distillation Algorithm:
- Parse trace → extract error messages, code diffs, test results
- Pattern matching → group traces by error type
- Extract repair templates → generalize specific fixes to patterns
- Rank by frequency + success_rate → prioritize high-impact skills
2. Skill-Guided Task Generation
Generate Targeted Repair Tasks from Skills
- Input: Agent's distilled skills + real repository
- Output: Synthetic SWE tasks targeting specific weaknesses
- Task template:
{repo, skill, target_file, mutation_type, expected_fix}
Generation Process:
def generate_task(skill, repo):
target_file = find_file_with_imports(repo)
mutation = remove_import(target_file, module_name)
task = {
"repo": repo,
"issue": f"Test failing due to ImportError: {module_name}",
"expected_fix": skill["repair_strategy"]
}
if test_fails_after_mutation(task):
return task
else:
return None
Curriculum Adaptation:
- Round 1: Skills from initial Solver traces → generate Round 1 tasks
- Round 2: Solver improves → new traces → new skills → Round 2 tasks (different focus)
- Round N: Curriculum evolves as Solver weaknesses shift
3. Solver-Gradient Alignment Reward
Score Task Utility for Solver Improvement
- Not all generated tasks are equally useful
- Reward function:
R(task) = gradient_alignment(task, Solver)
- Gradient alignment measures: does solving this task improve Solver on similar tasks?
Reward Calculation:
R(task) = 1/N * Σ_i |∂Solver(task_i) / ∂θ| dot |∂Solver(task) / ∂θ|
where:
- task_i = tasks in Solver's training set
- θ = Solver model parameters
- dot product measures gradient alignment
Interpretation:
- High reward → solving this task moves Solver in direction beneficial for training set
- Low reward → orthogonal improvement, less useful for curriculum
- Filter: retain tasks with R(task) > threshold (e.g., 0.7)
4. Execution-Based Validation
Verify Generated Tasks Before Retention
- Task must be:
- Verifiable: Tests fail after mutation, pass after correct fix
- Solvable: Expected fix actually resolves the issue
- Nontrivial: Not trivially easy (e.g., single-character typo)
Validation Pipeline:
1. Apply mutation → create broken state
2. Run tests → verify failure (test status: FAIL)
3. Apply expected fix → create repaired state
4. Run tests → verify success (test status: PASS)
5. Check difficulty → reject trivial fixes (single-line, obvious typo)
6. Retain task if all checks pass
5. Iterative Self-Evolution Loop
Closed-Loop Training Process
Round 0:
- Initial Solver S_0 (baseline)
- Run on SWE-bench → generate traces T_0
- Distill skills K_0 from T_0
Round 1:
- Generate tasks D_1 using K_0
- Validate D_1 (execution-based)
- Score D_1 with gradient alignment
- Train Solver S_1 on D_1 + SWE-bench
Round 2:
- Run S_1 → new traces T_1
- Distill new skills K_1 (different weaknesses)
- Generate tasks D_2 using K_1
- Train Solver S_2 on D_2
Round N:
- Repeat until convergence or compute budget exhausted
Convergence Criterion:
- Solver improvement plateaus (SWE-bench score change < threshold)
- Or: skill diversity stabilizes (new skills are redundant)
Implementation Steps
Step 1: Trace Collection Infrastructure
- Deploy Solver on SWE-bench datasets
- Log: (a) code diffs, (b) test outputs, (c) error messages, (d) reasoning chain
- Store traces in structured format (JSON/Parquet) for distillation
Step 2: Skill Distillation Pipeline
- Parse traces → extract error types via regex/pattern matching
- Cluster by error category: ImportError, SyntaxError, TypeError, LogicError, etc.
- For each cluster → extract repair pattern (template from successful fixes)
- Rank skills by
(frequency * success_rate) → prioritize high-impact
Step 3: Task Generation Engine
- Load skill + real repository
- Identify target files matching skill context
- Apply mutation (inject failure pattern)
- Create issue description + expected fix
- Return candidate task
Step 4: Validation Framework
- Execute mutation → run tests → check failure
- Execute expected fix → run tests → check success
- Measure difficulty → reject trivial tasks
- Compute gradient alignment reward → filter by threshold
Step 5: Solver Training Loop
- Accumulate validated tasks across rounds
- Fine-tune Solver on: (SWE-bench + generated tasks)
- Use gradient alignment to prioritize task sampling
- Evaluate on SWE-bench → track improvement
Experimental Results (Paper)
- SWE-bench Verified: 50.40% after 3 iterations (baseline ~45%)
- SWE-bench Lite: Consistent improvement over self-evolving baselines
- SWE-bench Pro: Handles more complex tasks via skill-guided generation
- Terminal-Bench 2.0: Cross-domain transfer shows skill generalization
Compute Budget: Same for all methods (fair comparison)
- Socratic-SWE: 3 iterations → 50.40%
- Baseline self-evolution: ~45%
- Improvement: +5.4 percentage points
Pitfalls
- Skill Overfitting: Skills may target narrow failure patterns → generate narrow tasks; balance diversity
- Mutation Validity: Some mutations produce invalid code → execution-based validation critical
- Trivial Task Injection: Easy tasks inflate training data but don't improve Solver; filter by difficulty
- Compute Budget: Each iteration requires Solver evaluation + task generation + training; estimate cost
- Skill Redundancy: Round N may produce skills overlapping with Round N-1 → deduplicate
- Gradient Alignment Cost: Computing gradients for all training tasks is expensive; use approximation
Verification
- Trace Quality: Inspect distilled skills → verify repair patterns are meaningful
- Task Validity: Run validation pipeline → ensure tests pass/fail correctly
- Curriculum Diversity: Check task distribution → confirm skills evolve across rounds
- Solver Improvement: Track SWE-bench score → monotonic increase across iterations
References
- arXiv:2606.07412 (June 2026)
- SWE-bench: real-world software engineering benchmark
- Self-evolution in RL agents (curriculum learning)
- Trace-based debugging and repair automation