ARCS: Agentic Retrieval-Augmented Code Synthesis with Iterative Refinement

Manish Bhattarai, Miguel Cordova, Javier E. Santos, Dan O'Malley · DOI

Introduction

Large Language Models (LLMs) have demonstrated remarkable capabilities in code generation, yet they remain prone to logical errors and the "hallucination" of non-existent API calls. Most current paradigms utilize LLMs as one-shot generators, where the process terminates regardless of the output's correctness. To address these limitations, the ARCS (Agentic Retrieval-Augmented Code Synthesis) framework introduces a "synthesize-execute-repair" loop that wraps frozen models in an iterative refinement process guided by real-world execution feedback.

Methodology

The ARCS framework is built upon a budgeted synthesize–execute–repair loop designed to ensure monotonic improvement in code quality. The process is divided into three primary stages:

  1. RAG Registration and Agentic Labeling: A code corpus is processed by an initial model (LLM-1) to extract core functional blocks. These blocks are labeled and embedded into a vector store for retrieval-augmented generation (RAG).
  2. Chain-of-Thought (CoT) Retrieval: Upon receiving a user task, a second model (LLM-2) generates a series of subgoals or CoT steps. These steps serve as queries to the RAG system to retrieve the most relevant code snippets and documentation.
  3. Iterative Synthesis and Repair: A third model (LLM-3) synthesizes a candidate solution using the retrieved context. This solution is executed within a secure Docker sandbox. If the code fails unit tests, the resulting error logs and stack traces are fed back into the model to facilitate an iterative repair process.
The ARCS framework pipeline, showing the integration of RAG registration, agentic retrieval via CoT steps, and the iterative repair loop.

The system operates under a fixed iteration budget ($B$), ensuring termination while tracking the "best-so-far" candidate. This formalization guarantees that the quality of the output does not degrade over successive iterations. The authors also introduce Tiered Operational Modes (Small, Medium, and Large) to allow users to balance computational speed with synthesis accuracy.

Experimental Setup

The researchers evaluated ARCS across three diverse benchmarks:

  • HumanEval: 164 Python coding problems used to assess general synthesis capabilities.
  • TransCoder: A benchmark for code translation between Python, Java, and C++.
  • LANL Scientific Corpus: A domain-specific dataset from Los Alamos National Laboratory, testing the system's performance on specialized scientific code.

Key Results and Analysis

ARCS demonstrated significant performance gains over both standard LLMs and existing agentic systems. On the HumanEval benchmark, ARCS achieved a peak 87.2% pass@1 score when utilizing Llama-3.1-405B as the backbone. Even with smaller models like Llama-3.1-70B, the tiered approach showed clear improvements as the complexity of the agentic loop increased, outperforming baselines like GPT-3.5-Turbo.

Performance comparison of ARCS tiers against baseline models and other agentic frameworks on HumanEval.

Beyond general synthesis, ARCS excelled in specialized domains. On the LANL Scientific Corpus, it improved the CodeBLEU score by +0.115 compared to a standard RAG baseline. In code translation tasks, the system maintained accuracy levels above 90% for most language pairs. Ablation studies highlighted that the combination of retrieval, planning, and execution feedback is "super-additive," providing a synergistic boost that exceeds the sum of individual components.

Conclusion and Future Directions

ARCS provides a robust, reproducible framework for enhancing code generation without the need for expensive fine-tuning. By leveraging a linear control flow and iterative feedback, it achieves state-of-the-art results while remaining computationally predictable. Future work will focus on automating budget selection through difficulty estimators and extending the framework to repository-level tasks where changes span multiple files.

Summary updated

BibTeX
@misc{bhattarai2025arcs,
  author = {Manish Bhattarai and Miguel Cordova and Javier E. Santos and Dan O'Malley},
  title = {{ARCS: Agentic Retrieval-Augmented Code Synthesis with Iterative Refinement}},
  year = {2025},
  eprint = {2504.20434},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2504.20434},
}
Figure