Coding agents based on frozen language models can improve their performance by refining the external context they rely on, without updating model weights. We study recursive self-improvement through behavioral specifications: natural-language code documentation that describes the behavior of program entities and guides agents in generating correct code. We formulate a self-improvement loop in which an agent generates code from its current specifications, evaluates it with execution-verified tests, and refines the specifications based on observed failures. The improved specifications then guide subsequent generation, progressively improving the agent's understanding of the codebase. However, recursive refinement is challenging because program entities are interdependent. Improving the specification of one entity can inadvertently degrade the correctness of others, a phenomenon we call output coupling. This creates a whack-a-mole effect in which local improvements cause regressions elsewhere, preventing consistent progress. We introduce SpecForge, a multi-frontier tree search framework that addresses this challenge with three mechanisms: (i) Pareto-guided state selection preserves complementary specification states and prevents premature commitment; (ii) dependency-constrained entity selection prioritizes callee-before-caller refinement; and (iii) error-diversified expansion explores multiple refinements using different subsets of test failures. On DevEval+, SpecForge achieves the best performance across five backbone models, including a 94.9% solve rate with Claude-4.5-Sonnet and a 5.7-percentage-point average improvement over the strongest baseline. The improved specifications also make the agent better at tasks outside the loop: they transfer to cross-language translation and to new-feature implementation, where they outperform the benchmark-provided requirement documents.
Figures & tables
Figure 1: Search tree view of behavioral specification optimization. Each node is a specification state. Different states solve different subsets of entities and therefore expose different eligible next refinements. Rather than committing to a single rewrite trajectory, our solution preserves multiple competitive frontiers and expands them selectively.
Figure 2: Overview of SpecForge . Each iteration resolves three decisions: where to search, what to refine, and how to refine. ❶ Pareto-guided state selection samples from an archive of non-dominated specification states with complementary strengths. ❷ Dependency-constrained entity selection only refines entities whose callees are already solved. ❸ Error-diversified expansion generates multiple children from different subsets of failing tests. Strong children are fed back into both the archive and the entity-selection policy.
Qwen3-235B-A22B
Gemini-2.5-Flash
GPT-4o
Gemini-3.1-Pro
Claude-4.5-Sonnet
Method
∣S∣
ϕˉ
∣S∣
ϕˉ
∣S∣
ϕˉ
∣S∣
ϕˉ
∣S∣
ϕˉ
Static Methods (No Optimization)
RepoAgent
22.3
34.9
19.2
30.6
27.8
39.9
33.7
45.5
35.3
47.3
DocAgent
16.1
31.1
14.5
27.2
22.2
37.2
26.8
41.8
28.9
44.7
Prompt Optimization (Monolithic)
MIPROv2
28.5
30.4
30.3
32.3
29.8
31.4
42.8
43.8
50.0
52.0
Table 1: Main results on DevEval+ .
Figure 3: Convergence analysis (GPT-4o, DevEval+ ). (a) Iterative refinement baselines oscillate due to refinement interference. (b) Monolithic methods exhibit catastrophic instability. SpecForge achieves steady upward progress in both comparisons. (c) Ablation study (GPT-4o, 10-module subset). Components ordered by contribution (large to small); dashed lines mark the full model ( ∣S∣=90.9% , ϕˉ=93.2% ). Reverse topological ordering is the largest single contributor ( −18.6% ).
Figure 4: (Left) Cross-language translation . Optimized specifications ( +26.0% over Source-only) transfer effectively across languages; combining specifications with source code achieves the best results (76.2%). (Right) New-feature implementation on SWE-Dev . SpecForge -generated specifications surpass the default PRD provided by the SWE-Dev benchmark, achieving the highest pass rate on both difficulty levels despite never accessing the PRD or target tests.
Appendix figures & tables3 assets
Supplementary material from the paper’s appendix.
Appendix
Figure 5: Module-level search dynamics on stocktrends/indicators (6 entities). Each row corresponds to a budget checkpoint; columns show the full refinement trace for Iterative Refinement (left), ACE (center-left), SpecForge (center-right), and per-entity pass rate radar charts (right). All text is verbatim from experiment logs, in which the specification is labeled “Doc”. Color coding: Doc Before (yellow), Errors (red), Reflection (purple), Doc After (green). Status tags indicate PLATEAU , REGRESSION , CYCLING , and RECOVERY . Radar charts overlay all three methods per checkpoint: Iterative (blue, solid), ACE (purple, dashed), SpecForge (green, bold).
Configuration
Feedback Signal
ϕˉ (%)
SpecForge (default)
LLM tests
93.2
Ground-truth tests
GT tests
94.8
LLM-as-a-judge
Judge score
73.6
τcov=0.7
Reduced tests
93.4
τcov=0.5
Reduced tests
92.6
τcov=0.3
Reduced tests
87.5
Appendix
Table 2: Sensitivity to feedback signal (GPT-4o, DevEval+).
Module
Source
Domain
arxiv_digest †
D
Academic/NLP
hybrid_images
D
Image Processing
textcnn
D
Deep Learning/NLP
chakin
D
NLP/Embeddings
geotext †
D
Geography/NLP
hone †
D
Data Processing
Appendix
Table 3: Complete module list of DevEval+ . Source : D = DevEval, G = GitHub. Modules marked with † are included in the cross-language subset DevEval+-Java .
Retrieval-based speculative decoding (SD) drafts tokens by copying continuations from existing text, which suits coding agents that repeatedly reproduce code, logs, and earlier attempts. Yet existing methods fall short in agent pipelines: much of the reusable text is missing from their corpora or stored in a form that differs from what the agent emits, and their draft lengths ignore that accept length varies across agents and drifts over turns. We present AgSpec, a framework that supplies the corpus and draft-length policies that existing retrieval engines lack in coding-agent pipelines. AgSpec retrieves from session, workspace, and global corpora, retaining the ongoing session trajectory and indexing opened files in the agent's emission format. It bounds each agent's draft length with an offline-profiled cap and adapts the length online from verification feedback. On two repository-level multi-agent coding benchmarks, AgSpec outperforms five retrieval-based drafters and EAGLE-3 in most evaluated settings, raising generation throughput over autoregressive decoding up to 4.37× at batch size 1 and 4.76× at batch size 16. AgSpec also remains effective on benchmarks without a repository or a multi-agent pipeline, showing that its gains generalize to coding agents broadly.
Coding agents can recursively modify their own implementations, forming a loop of self-improvement. While prior work shows this can boost performance on coding benchmarks, existing approaches are costly and compute-intensive. We introduce a simple, sample-efficient self-improvement framework that significantly improves coding performance under strict budget constraints. We identify evaluation of candidate self-modifications as the main runtime bottleneck since prior approaches estimate their effectiveness by re-running a subset of benchmark tasks with the modified agent, which is time-consuming. We introduce Recursive Self Improvement via Fast Tree-search (SIFT), which augments these downstream task evaluations with an LLM-as-a-judge signal that performs pairwise comparisons between candidate patches, where the win-loss record is aggregated with a regularized Bradley-Terry model, and the resulting strength scores drive rank-based parent sampling inside a lightweight disaggregated tree search. Expensive downstream task evaluations are reserved only for the most promising nodes. Using a fully disaggregated tree search pipeline, the judge scores provide intermediate signal to guide exploration on promising candidate patches without being bottlenecked by slow evaluation runs. SIFT outperforms existing tree-search based self-evolution frameworks on the full Polyglot benchmark with significantly lower resource requirements in terms of CPU hours, wall clock time, and API cost.
Improving an agent through successive revisions requires balancing exploration and evaluation under a limited budget. A narrow search can miss useful sequences of edits, while fully evaluating every intermediate version can exhaust the budget before those sequences yield a verified improvement. We introduce Speculative Recursive Self-Improvement (SpecRSI), which drafts executable successor agents before their predecessors are fully evaluated, while requiring complete verification before adoption. Verification-Aware Tree Search (VATS) allocates the budget between further edits and outstanding checks using the predicted verified return of a continuation. Group Verification Optimization (GVO) learns the improver from completed searches while keeping the real evaluator fixed. In the main scientific comparison, terminal gains exceed Janus by 33.3%--40.0%. Additional evaluations show that SpecRSI outperforms Janus in all 50 scientific backbone--task pairs and exceeds MetaRSI-v1 by 1.85%--2.38% in macro-average system score across twenty backbones. Coding-validation success reaches 69.4% versus HGM's 64.3% at a 20.8% lower target-cost index.
Xin Xu, Ke Cheng, Hao Wang +11
Tencent AMS, Beijing, China · State Key Laboratory of General Artificial Intelligence, School of Intelligence Science and Technology, Peking University, Beijing, China · CCSE lab, Beihang University. +3